首页 > 编程语言 >Node.js vs. Spring Boot:Hello World 性能对决,谁更快一点?

Node.js vs. Spring Boot:Hello World 性能对决,谁更快一点?

时间:2023-09-27 11:00:58浏览次数:49  
标签:Node Spring resp Boot springframework js import

前言:

Spring Boot 在 Java 生态中备受欢迎,它是一款基于 Java 构建的轻量级服务端框架,主要用于 Web 服务。Spring Boot 的应用使得创建各类基于 Spring 的企业级应用变得异常简单。Node.js作为一种基于Chrome V8引擎的JavaScript运行时环境,在服务端上运行JavaScript代码。它以其独特的特性为我们提供了极其便捷的开发方式,今天我们就对比一下Spring Boot与Node.js之间的性能差异。

运行环境:

硬件:MacBook Pro M1 16g

测试工具:Bombardier

测试并发数:50、100、200

版本:

Node.js v19.6.0

Spring Boot v3.0.2

Java17

Node.js 测试代码:

import http from "node:http";

 http.createServer((req, resp) => {
  try {
   if (req.method !== "GET") {
    return resp.writeHead(405).end();
   }
   if (req.url !== "/") {
    return resp.writeHead(404).end();
   }
   resp.writeHead(200, {
    "content-type": "text/plain",
   });
   resp.end("Hello world");
  } catch (e) {
   resp.writeHead(500).end();
  }
 }).listen(3000);

Spring Boot测试代码:

package com.example.demo;

 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.Spring BootApplication;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.http.ResponseEntity;
 import org.springframework.http.HttpStatus;
 import org.springframework.web.bind.annotation.RestController;

 @Spring BootApplication
 @RestController
 public class DemoApplication {

   public static void main(String[] args) {
     SpringApplication.run(DemoApplication.class, args);
   }

   @GetMapping("/")
   public String handleRequest() {
     return "Hello World!";
   }
 }

测试时,每个并发执行500万请求,对比如下性能指标:

  • 耗时
  • 每秒处理请求数
  • 延迟:平均值、中值、q25、q75、q90、最大值(以毫秒为单位)
  • 资源占用情况:CPU和内存平均使用率

测试结果:

经过对比测试,绘制了如下图表(延迟以毫秒为单位):

测试结果分析:

资源占用方面,Spring/Java 是一个资源密集型应用,在一个简单的“Hello World”案例中,200并发情况下,Spring 使用了约190%的 CPU 和 470M 的内存。相比之下,Node.js 使用了 95% 的 CPU 和 82M 的内存。

延迟方面,在q75之前,Spring 的延迟低于 Node.js。Spring在最大延迟达到了几秒钟,而Node.js的最大延迟仅 123ms。Spring 的延迟中位数(0.6ms)优于 Node.js(2.5ms)。

总结来看,Node.js 在使用显著较少的系统资源的情况下”吞吐量“(RPS/每秒请求数)更高。

原文链接:https://medium.com/deno-the-complete-reference/node-js-vs-springboot-hello-world-performance-comparison-59b4d461526c

扩展链接:

扩展链接:

ChatGPT赋能低代码开发:打造智能应用的双重引擎

窗口函数大揭秘!轻松计算数据累计占比,玩转数据分析的绝佳利器

3D模型+BI分析,打造全新的交互式3D可视化大屏开发方案

标签:Node,Spring,resp,Boot,springframework,js,import
From: https://blog.51cto.com/powertoolsteam/7621733

相关文章

  • SpringBoot | 拦截机制
    欢迎参观我的博客,一个Vue与SpringBoot结合的产物:https://poetize.cn博客:https://gitee.com/littledokey/poetize-vue2.git聊天室:https://gitee.com/littledokey/poetize-im-vue3.git后端:https://gitee.com/littledokey/poetize.git七牛云登录/注册地址(文件服务器,CDN):https:/......
  • SpringBoot | Bean生命周期
    欢迎参观我的博客,一个Vue与SpringBoot结合的产物:https://poetize.cn博客:https://gitee.com/littledokey/poetize-vue2.git聊天室:https://gitee.com/littledokey/poetize-im-vue3.git后端:https://gitee.com/littledokey/poetize.git七牛云登录/注册地址(文件服务器,CDN):https:/......
  • 一文告诉你Istio和 spring cloud该怎么选
    相信了解SpringCloud的朋友在刚刚开始接触Istio的时候一定会有一个疑问:Istio和springcloud也太像了,他们都可以提供服务发现、负截均衡、限流、链路跟踪、鉴权等微服务治理手段,那么二者的主要区别是什么呢?本文就会带大家理解二者的区别,如果您目前对微服务和ServiceMesh还不了......
  • 「Java开发指南」在MyEclipse中的Spring开发(三)
    在上文中(点击这里回顾>>),我们介绍了如何管理多个Beans和项目、Spring配置编辑器等,本文将继续介绍AOP、WebFlow支持等,要持续关注哦~MyEclipsev2023.1.2离线版下载MyEclipse技术交流群:742336981欢迎一起进群讨论6.AOP支持BeansCrossReferences视图显示了所有被建议的beans......
  • Idea+SpringBoot控制台调试打印sql语句
    在application.yml中添加:logging:level:com.xiaobai.stock.mapper:DEBUG//注意:':'后有空格,不能省略mapper:运行时控制台 ......
  • macOS Sonoma 14 (23A344) 正式版 Boot ISO 原版可引导镜像下载
    macOSSonoma14(23A344)正式版BootISO原版可引导镜像下载2023年9月26日(北京时间27日凌晨)macOSSonoma正式版现已发布。本站下载的macOS软件包,既可以拖拽到Applications(应用程序)下直接安装,也可以制作启动U盘安装,或者在虚拟机中启动安装。另外也支持在Windows......
  • SpringBoot | 加密算法使用示例
    欢迎参观我的博客,一个Vue与SpringBoot结合的产物:https://poetize.cn博客:https://gitee.com/littledokey/poetize-vue2.git聊天室:https://gitee.com/littledokey/poetize-im-vue3.git后端:https://gitee.com/littledokey/poetize.git七牛云登录/注册地址(文件服务器,CDN):https:/......
  • SpringBoot | Dubbo之Filter使用示例
    欢迎参观我的博客,一个Vue与SpringBoot结合的产物:https://poetize.cn博客:https://gitee.com/littledokey/poetize-vue2.git聊天室:https://gitee.com/littledokey/poetize-im-vue3.git后端:https://gitee.com/littledokey/poetize.git七牛云登录/注册地址(文件服务器,CDN):https:/......
  • SpringBoot | Redis序列化与分布式锁
    欢迎参观我的博客,一个Vue与SpringBoot结合的产物:https://poetize.cn博客:https://gitee.com/littledokey/poetize-vue2.git聊天室:https://gitee.com/littledokey/poetize-im-vue3.git后端:https://gitee.com/littledokey/poetize.git七牛云登录/注册地址(文件服务器,CDN):https:/......
  • SpringBoot | Jackson序列化
    欢迎参观我的博客,一个Vue与SpringBoot结合的产物:https://poetize.cn博客:https://gitee.com/littledokey/poetize-vue2.git聊天室:https://gitee.com/littledokey/poetize-im-vue3.git后端:https://gitee.com/littledokey/poetize.git七牛云登录/注册地址(文件服务器,CDN):https:/......