This example project contains a very basic http server which demonstrates the basics that are need to build a Vert.x server which can handle 10k concurrent connections.
The example program starts Vert.x and deploys multiple http verticles.
Noteworthy aspects:
-
The
netty-transport-native-epoll
library adds epoll support. -
HttpServer
options improve connection handling
options
.setPort(SERVER_PORT)
.setHost(SERVER_HOST)
.setCompressionSupported(true)
.setHandle100ContinueAutomatically(true)
.setTcpFastOpen(true)
.setTcpNoDelay(true)
.setTcpQuickAck(true);
VertxOptions
to prefer native transports
VertxOptions vertxOptions = new VertxOptions();
vertxOptions.setPreferNativeTransport(true);
- Deploy multiple verticles
DeploymentOptions options = new DeploymentOptions();
int nVerticles = Runtime.getRuntime().availableProcessors() * 2;
options.setInstances(nVerticles);
mvn clean package
java -jar target/vertx-c10k-example-0.0.1-SNAPSHOT.jar
-
GET http://localhost:8080/0k - Returns empty response
-
GET http://localhost:8080/static/4k - Returns fixed 4k response
-
GET http://localhost:8080/static/8k - Returns fixed 8k response
-
GET http://localhost:8080/static/64k - Return fixed 64k response
-
GET http://localhost:8080/cached/4k - Returns 4k response from caffeine cache
-
GET http://localhost:8080/cached/8k - Returns 8k response from caffeine cache
-
GET http://localhost:8080/cached/64k - Return 64k response from caffeine cache
-
GET http://localhost:8080/jcs/4k - Return 4k response from JCS disk based cache
-
GET http://localhost:8080/sendFile/test - Returns response which uses NIO sendfile() call.
-
POST http://localhost:8080/upload - Upload a file, empty response will be returned
- GET http://localhost:8081/metrics - Return micrometer metrics for prometheus
# Increase amount of open files. This will allow the creation of more network sockets.
sysctl -w fs.file-max=110000
sysctl -w fs.nr_open=110000
ulimit -n 110000
# Increase tcp buffers
sysctl -w net.ipv4.tcp_mem="100000000 100000000 100000000"
# Increase socket connection limit
sysctl -w net.core.somaxconn=10000
# Increase backlog size for tcp connections in SYN state
sysctl -w net.ipv4.tcp_max_syn_backlog=10000
via wrk
./wrk -c10000 -d32s -t8 http://localhost:8080/static/4k
via apache benchmark
ab -n 200000 -c 10000 http://localhost:8080/static/4k
- On Intel i7 7700k @ Linux 4.19.0-5-amd64
./wrk -c10000 -d32s -t16 http://localhost:8080/static/4k
Running 32s test @ http://localhost:8080/static/4k
16 threads and 10000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 85.68ms 29.71ms 1.03s 75.52%
Req/Sec 7.04k 1.27k 19.43k 85.71%
3588359 requests in 32.10s, 13.83GB read
Requests/sec: 111789.39
Transfer/sec: 441.05MB
Please note that the results should not be used as a performance reference. The server response is static. The tests are run locally. There are many other factors which will affect real world performance.