Vert.x 3 - faster, better, stronger
Vert.x 3 released
New version of Vert.x has just been released. There are many new features and upgrades compared to Vert.x 2. You can read about most of changes in one of the threads from official Vert.x mailing list.
In Espeo we are using Vert.x in two projects. One of them (which I’m involved in) is at very early stage. That’s why we will try to upgrade Vert.x version as soon as possible. In order to be 100% sure I have created simple benchmark to verify if new Vert.x comes with better performance.
Benchmark preparation
In most popular scenario our application waits for HTTP post request with small (4,0 kB) JSON payload. Then we transform it to Java objects using Json class in order to decode/encode operations. At the end we send back some other JSON data.
JSON data looks as below (sample.json):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"guestListName": "My Birthday Guest List",
"eventName": "Birthday Party",
"venue": {
"name": "Great Place For Party",
"address": "Baker Street 221B, London"
},
"guests": [
{
"firstName": "Sherlock",
"lastName": "Holmes",
"profession": "Private Detective",
"age": "44"
},
{
"firstName": "John",
"lastName": "Watson",
"profession": "Doctor of Medicine",
"age": "50"
}...
]
}
Vert.x 2 Verticle looks as below:
1
2
3
4
5
6
7
8
9
10
11
12
13
public class HttpVerticle extends Verticle {
@Override
public void start() {
HttpServer httpServer = vertx.createHttpServer();
httpServer.requestHandler(req -> {
req.bodyHandler(buffer -> {
GuestList guestList = Json.decodeValue(buffer.toString(), GuestList.class);
req.response().end(Json.encode(guestList));
});
}).listen(8080);
}
}
Vert.x 3 Verticle looks very similar:
1
2
3
4
5
6
7
8
9
10
11
12
13
public class HttpVerticle extends AbstractVerticle {
@Override
public void start() {
vertx.createHttpServer()
.requestHandler(req -> {
req.bodyHandler(buffer -> {
GuestList guestList = Json.decodeValue(buffer.toString(), GuestList.class);
req.response().end(Json.encode(guestList));
});
}).listen(8081);
}
}
There are also three classes: GuestList, Venue, Guest that map JSON data structure:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class GuestList {
private String guestListName;
private String eventName;
private Venue venue;
private List<Guest> guests;
}
public class Venue {
private String name;
private String address;
}
public class Guest {
private String firstName;
private String lastName;
private String profession;
private int age;
}
As you can see, each Verticle waits for HTTP request, decodes request body (JSON) to Java POJOs, then encodes it once again to JSON and sends back.
As a benchmark I used ApacheBench, very easy tool for measuring HTTP server performance.
Test scenario will go as follow:
- 50 000 requests
- 100 concurrent requests
Benchmark results - Summary
After few rounds of warmup I’ve got results.
First Vert.x 2 result:
And Vert.x 3 result:
Benchmark results show that for my test scenario Vert.x 3 can handle 13.9% more requests per second than Vert.x 2. Performance increased from 9214.46 to 10493.76 requests per second.
It’s enough to convince me to migrate to Vert.x 3 next week.
Thanks for reading!