为什么我看不到 Spring Boot 和 Vert.x 之间的性能差异

Why I can't see the performance difference between Spring Boot and Vert.x

Vert.X 的一个优点是它的性能,但我从我的测试中看不出有什么不同,有人知道为什么吗?测试只是打印 hello.

我还执行了请求 Google(Vert.x 中的异步请求)然后打印响应的测试。它还显示 2 个框架具有相同的性能。

Vert.x代码:

public class MainVerticle extends AbstractVerticle {
  static String HELLO = "hello";
  @Override
  public void start(Promise<Void> startPromise) throws Exception {
    vertx.createHttpServer().requestHandler(req -> {
      req.response()
        .putHeader("content-type", "text/plain")
        .end(HELLO );
    }).listen(8888, http -> {
      if (http.succeeded()) {
        startPromise.complete();
        System.out.println("HTTP server started on port 8888");
      } else {
        startPromise.fail(http.cause());
      }
    });
  }
}

Spring代码:

@SpringBootApplication
@RestController
public class DemoApplication {

    static String HELLO = "hello";
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
    @GetMapping("/")
    public String hei(){
        return HELLO;
    }
}

Apache Benchmark(从另一台机器调用):

ab -n 50000 -c 10 http://192.168.1.115:8888/

简而言之,您看不到性能优势,因为您测试的是错误的东西。

Vert.x 和一般的异步框架非常适合 IO 绑定操作。碰巧大多数读取世界的应用程序都是 IO 绑定的(等待数据库、磁盘、其他服务等)。

不过,您的应用程序没有执行任何重要的 IO。所以,这就是您看不到差异的原因之一。

另一个原因是您使用的并发级别。 Spring 应用程序受其线程池大小的限制,但我猜它大于 10 个线程,因此您并没有给应用程序带来真正的压力。

第三个原因是您很可能 运行 此测试与您的服务器 运行 在同一台机器上进行。这是有缺陷的,因为您的 Vert.x 应用程序将与 ab.

竞争资源