From 2a89aaae159c019af885128a5cbaf0055ee32673 Mon Sep 17 00:00:00 2001 From: Frederic Bregier Date: Tue, 12 Dec 2023 19:16:12 +0100 Subject: [PATCH] Speedup retrieving inputstream Workd both on sending and retrieving (server, client) an InputStream Fetch more than 1 at startup (3 to still have a limit of memory consumption) Speedup: - POST: from 900 MB/s to 1200 MB/s (almost close to Netty native Post at 1400 MB/s) - GET: from 900 MB/s to 2000 MB/s (still half og Netty netive GET at 4400 MB/s) --- .../io/quarkus/vertx/http/runtime/VertxInputStream.java | 9 ++++----- .../reactive/client/handlers/VertxClientInputStream.java | 9 ++++----- .../resteasy/reactive/server/vertx/VertxInputStream.java | 9 ++++----- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxInputStream.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxInputStream.java index 83b8ebe93d1612..295cff15e92a79 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxInputStream.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxInputStream.java @@ -226,7 +226,8 @@ public void handle(Throwable event) { } }); - request.fetch(1); + // More than 1 speedup retrieve while limited in memory + request.fetch(3); } else { eof = true; } @@ -266,10 +267,8 @@ protected ByteBuf readBlocking() throws IOException { input1 = null; if (inputOverflow != null) { input1 = inputOverflow.poll(); - if (input1 == null) { - request.fetch(1); - } - } else if (!eof) { + } + if (!eof) { request.fetch(1); } return ret == null ? null : ret.getByteBuf(); diff --git a/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/handlers/VertxClientInputStream.java b/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/handlers/VertxClientInputStream.java index a471ed3199fd67..5186c777d99006 100644 --- a/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/handlers/VertxClientInputStream.java +++ b/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/handlers/VertxClientInputStream.java @@ -181,7 +181,8 @@ public void handle(Throwable event) { } }); - response.fetch(1); + // More than 1 speedup retrieve while limited in memory + response.fetch(3); } catch (IllegalStateException e) { //already ended eof = true; @@ -221,10 +222,8 @@ protected ByteBuf readBlocking() throws IOException { input1 = null; if (inputOverflow != null) { input1 = inputOverflow.poll(); - if (input1 == null) { - request.fetch(1); - } - } else if (!eof) { + } + if (!eof) { request.fetch(1); } return ret == null ? null : ret.getByteBuf(); diff --git a/independent-projects/resteasy-reactive/server/vertx/src/main/java/org/jboss/resteasy/reactive/server/vertx/VertxInputStream.java b/independent-projects/resteasy-reactive/server/vertx/src/main/java/org/jboss/resteasy/reactive/server/vertx/VertxInputStream.java index 3002f19b36025a..adfefce874aeb0 100644 --- a/independent-projects/resteasy-reactive/server/vertx/src/main/java/org/jboss/resteasy/reactive/server/vertx/VertxInputStream.java +++ b/independent-projects/resteasy-reactive/server/vertx/src/main/java/org/jboss/resteasy/reactive/server/vertx/VertxInputStream.java @@ -227,7 +227,8 @@ public void handle(Throwable event) { } }); - request.fetch(1); + // More than 1 speedup retrieve while limited in memory + request.fetch(3); } else { eof = true; } @@ -267,10 +268,8 @@ protected ByteBuf readBlocking() throws IOException { input1 = null; if (inputOverflow != null) { input1 = inputOverflow.poll(); - if (input1 == null) { - request.fetch(1); - } - } else if (!eof) { + } + if (!eof) { request.fetch(1); } return ret == null ? null : ret.getByteBuf();