Poor performance vertx-web-client 4.5.7

73 views
Skip to first unread message

Skyler L

unread,
Apr 15, 2024, 6:50:00 PMApr 15
to vert.x
Hi folks,

I am observing poor performance with vertx-web-client 4.5.7. I am only seeing 0-3 requests served per second. I'm sure I am doing something wrong.

Here is my abbreviated code:
```
vertx = Vertx.vertx();
router = Router.router(vertx);
webClient = WebClient.create(vertx);

router.route().handler(CorsHandler.create("*")
        .allowedMethod(HttpMethod.GET)
        .allowedMethod(HttpMethod.POST)
        .allowedMethod(HttpMethod.PUT)
        .allowedMethod(HttpMethod.OPTIONS)
        .allowedMethod(HttpMethod.DELETE)
        .allowedHeader("Content-Type")
);
router.route("/api/*").handler(ResponseTimeHandler.create());
router.route("/api/*").handler(LoggerHandler.create());
router.route("/api/*").handler(TimeoutHandler.create(TimeUnit.SECONDS.toMillis(TIMEOUT_SECONDS)));

router.get("/api/v1/my_endpoint").handler(rc -> {

    var request = webClient.getAbs("another-endpoint");

    request
            .send()
            .flatMap(ar -> {

                if (ar.statusCode() != 200) {
                    return Future.failedFuture(ar.bodyAsString());
                } else {

                    final List<Map<String, Object>> values = GSON.fromJson(ar.bodyAsString(), new TypeToken<List<Map<String, Object>>>() {}.getType());

                    return webClient.postAbs("another-other-endpoint")
                        .sendBuffer(Buffer.buffer(GSON.toJson(values)));
                }
            })
            .onComplete(ar -> {

                if (ar.succeeded()) {

                    rc.response().setStatusCode(200).putHeader(CONTENT_TYPE_HEADER, CONTENT_TYPE_APPLICATION_JSON).end("OK");

                } else {
                    rc.response().setStatusCode(500).putHeader(CONTENT_TYPE_HEADER, CONTENT_TYPE_APPLICATION_JSON).end(ar.cause().getMessage());
                }
            });
})

final HttpServer httpServer = vertx.createHttpServer(new HttpServerOptions().setMaxHeaderSize(62768))
                .requestHandler(router);

logger.info("WEB,STARTING_SERVER,PORT,{}", webserverPort);
httpServer.listen(webserverPort, result -> {
    if (result.failed()) {
        final String error = String.format("UNABLE_TO_BIND_ON_PORT,%s,%s", webserverPort,
                result.cause());
        logger.error(error);
        // potentially send  critical error event
        // and handle all critical errors in one place
        System.exit(-1);
    }
    logger.info("WEB,SERVER_STARTED,PORT,{}", webserverPort);
});

```

As you can see my code is pretty straight-forward -- very little configuration and basic usage of send() and flatMap().
Can someone please advise? Thanks in advance.

Skyler L

unread,
Apr 15, 2024, 6:52:27 PMApr 15
to vert.x
I forgot to mention that, I have benchmarked the upstream dependences (another-endpoint and another-other-endpoint) and they perform orders of magnitude faster 

Skyler L

unread,
Apr 20, 2024, 11:14:37 AMApr 20
to vert.x
var vertx = Vertx.vertx();
        var router = Router.router(vertx);
        router.post("/api/my_api_call/").handler(rc -> {
            Maybe.just(rc.getBodyAsString())
                    .observeOn(Schedulers.computation())
                    .<List<DomainObj>>flatMap(this::parse)
                    .flatMap(objs -> {
                        return Maybe.zip(
                                objs
                                        .stream()
                                        .map(inputCopy ->
                                                validateInput(inputCopy) // no http req
                                                        .flatMap(__ -> getServerCopyOfObj(inputCopy)) // http req
                                                        .flatMap(serverCopy ->
                                                                validateInputAgainstServerCopy(inputCopy, serverCopy) // http req
                                                                        .flatMap(__ -> calculateDiffs(inputCopy, serverCopy)) // no http req
                                                        )
                                                        .flatMap(this::batchUpdate) // http req
                                                        .flatMap(__ -> getChildren(inputCopy.name(), null)) // http req
                                                        .onErrorResumeNext(error -> recover(inputCopy, error)) // no http req
                                                        .toMaybe()
                                        )
                                        .collect(toList()),
                                results -> results
                        );
                    })
                    .defaultIfEmpty(emptyList())
                    .subscribe(
                            results -> rc.response().setStatusCode(200).end(GSON.toJson(results));,
                            error -> rc.response().setStatusCode(400).end(GSON.toJson(Map.of("ERROR", error.getMessage())));
                    );
        });

        final HttpServer httpServer = vertx.createHttpServer(new HttpServerOptions())
                .requestHandler(router);

        httpServer.listen(8080).subscribe(
                server -> logger.info("WEB,SERVER_STARTED"),
                error -> {
                    final String err = String.format("UNABLE_TO_START,%s", error);
                    logger.error(err);
                    System.exit(-1);
                }
        );
Reply all
Reply to author
Forward
0 new messages