Vert.x 3 – faster, better, stronger

A 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 the changes in one of the threads from the official Vert.x mailing list.

Vert.x 3 released

At 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 to Vert.x as soon as possible. In order to be 100% sure, I have created simple benchmark to verify if the new Vert.x gives a better performance than the previous version.

Benchmark preparation

In the 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
23
24
25
{
    "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() {
    vertx.createHttpServer()
      .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 a HTTP request, decodes request body (JSON) to Java POJOs, then encodes it once again to JSON and sends it 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
1
2
3
4
#Vert.x 2:
ab -l -t 10 -c 100 -T application/json -p sample.json http://localhost:8080/test
#Vert.x 3:
ab -l -t 10 -c 100 -T application/json -p sample.json http://localhost:8081/te

Benchmark results – Summary

After few rounds of warmup I’ve got results.

First Vert.x 2 result:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Time taken for tests:   5.426 seconds
Complete requests:      50000
Failed requests:        0
Total transferred:      146300000 bytes
Total body sent:        221800000
HTML transferred:       144250000 bytes
Requests per second:    9214.46 [#/sec] (mean)
Time per request:       10.853 [ms] (mean)
Time per request:       0.109 [ms] (mean, across all concurrent requests)
 
Percentage of the requests served within a certain time (ms)
  50%     10
  66%     11
  75%     11
  80%     11
  90%     12
  95%     13
  98%     14
  99%     16
 100%     24 (longest request)

Benchmark results show that for my test scenario Vert.x 3 can handle 13.9% more requests per second than Vert.x 2.

Performance has 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!

Find more of my articles on my Blog: http://qrman.github.io/

author: Krzysztof Urman