Skip to content

Instantly share code, notes, and snippets.

@jinwik
Created February 13, 2021 00:03
Show Gist options
  • Save jinwik/569938388962a457a93ee87d9b9c6732 to your computer and use it in GitHub Desktop.
Save jinwik/569938388962a457a93ee87d9b9c6732 to your computer and use it in GitHub Desktop.
wrk -c 150 -d 5m 'http://127.0.0.1:9999'
#Test2.java output
08:00:48.622 [vert.x-eventloop-thread-0] ERROR io.vertx.example.Tester2 - unexpected timeout: 84
08:00:48.641 [vert.x-eventloop-thread-0] ERROR io.vertx.example.Tester2 - unexpected timeout: 92
08:00:48.777 [vert.x-eventloop-thread-0] ERROR io.vertx.example.Tester2 - unexpected timeout: 40
08:00:48.856 [vert.x-eventloop-thread-0] ERROR io.vertx.example.Tester2 - unexpected timeout: 87
08:00:49.792 [vert.x-eventloop-thread-0] ERROR io.vertx.example.Tester2 - unexpected timeout: 16
08:00:50.365 [vert.x-eventloop-thread-0] ERROR io.vertx.example.Tester2 - unexpected timeout: 23
08:00:51.046 [vert.x-eventloop-thread-0] ERROR io.vertx.example.Tester2 - unexpected timeout: 21
08:00:51.876 [vert.x-eventloop-thread-0] ERROR io.vertx.example.Tester2 - unexpected timeout: 28
....
package io.vertx.example;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.TimeUnit;
public class Server {
public static void main(String[] args) throws IOException, InterruptedException {
ServerSocket serverSocket = new ServerSocket(8899, 1);
new Socket().connect(serverSocket.getLocalSocketAddress());
TimeUnit.DAYS.sleep(1);
}
}
package io.vertx.example;
import io.netty.channel.ConnectTimeoutException;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.ext.web.client.WebClient;
import io.vertx.ext.web.client.WebClientOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
public class Tester2 extends AbstractVerticle {
private final static Logger logger = LoggerFactory.getLogger(Tester2.class);
@Override
public void start() throws Exception {
WebClient webClient = WebClient.create(vertx, new WebClientOptions().setConnectTimeout(100).setMaxPoolSize(200));
vertx.createHttpServer()
.requestHandler(req -> {
long start = System.nanoTime();
webClient.get(8899, "172.16.185.141", "/")
.send(ar -> {
if (ar.failed()) {
long millis = Duration.ofNanos(System.nanoTime() - start).toMillis();
if (millis < 100) {
if (ar.cause() instanceof ConnectTimeoutException) {
logger.error("unexpected timeout: {}", millis);
}
}
req.response().end(ar.cause().getMessage());
} else {
req.response().end("ok");
}
});
})
.listen(9999);
}
public static void main(String[] args) {
Vertx.vertx(new VertxOptions()
.setBlockedThreadCheckIntervalUnit(TimeUnit.DAYS)
.setBlockedThreadCheckInterval(1)).deployVerticle(new Tester2());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment