One advantage of Vert.X is it's performance, but I can't see any difference from my testing, any one know why? The test is simply printing hello.
I have also perform a testing for requesting Google(async request in Vert.x) then print response. It also shows 2 framework have same performance.
Vert.x Code:
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 code:
@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(calling from another machine):
ab -n 50000 -c 10 http://192.168.1.115:8888/
Simply put, you don't see performance benefits because you're testing the wrong things.
Vert.x, and asynchronous frameworks in general, are great for IO bound operations. And it so happens that most read world applications are IO bound (waiting for DB, disk, other services, etc).
Your application doesn't perform any significant IO, though. So, that's one reason you don't see a difference.
Another reason is the concurrency level you are using. Spring applications are bound by their thread pool size, but my guess is it's bigger than 10 threads, so you aren't really stressing your application.
The third reason is that you are most likely running this test on the same machine than your server is running. This is flawed, because your Vert.x application will compete for resources with ab.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With