Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move buffer allocation to another thread #602

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
import org.swisspush.gateleen.queue.queuing.circuitbreaker.util.QueueCircuitState;
import org.swisspush.gateleen.queue.queuing.circuitbreaker.util.QueueResponseType;

import static io.vertx.core.Future.failedFuture;
import static io.vertx.core.Future.succeededFuture;
import static io.vertx.core.buffer.Buffer.buffer;
import static java.lang.System.currentTimeMillis;
import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenThriftyExceptionFactory;
import static org.swisspush.gateleen.queue.queuing.circuitbreaker.util.QueueResponseType.FAILURE;
import static org.swisspush.gateleen.queue.queuing.circuitbreaker.util.QueueResponseType.SUCCESS;
Expand Down Expand Up @@ -290,7 +294,18 @@ private void executeQueuedRequest(Message<JsonObject> message, Logger logger, Ht
};
request1.idleTimeout(120000); // avoids blocking other requests
if (queuedRequest.getPayload() != null) {
request1.send(Buffer.buffer(queuedRequest.getPayload()), httpAsyncHandler);
vertx.<Buffer>executeBlocking(() -> {
long beginEpchMs = currentTimeMillis();
Buffer payload = buffer(queuedRequest.getPayload());
long durationMs = currentTimeMillis() - beginEpchMs;
if (durationMs > 16) logger.debug("Creating buffer of size {} took {}ms", payload.length(), durationMs);
return payload;
}, false).compose((Buffer payload) -> {
request1.send(payload, httpAsyncHandler);
return succeededFuture();
}).onFailure((Throwable ex) -> {
httpAsyncHandler.handle(failedFuture(ex));
});
} else {
request1.send(httpAsyncHandler);
}
Expand Down
Loading