From 65a962d4591d52e43d95ae3902adb7c86b1b453b Mon Sep 17 00:00:00 2001 From: Santiago Pericas-Geertsen Date: Mon, 30 Jan 2023 09:44:24 -0500 Subject: [PATCH] Switch default back-pressure strategy to AUTO_FLUSH from LINEAR. (#5983) Signed-off-by: Santiago Pericasgeertsen --- .../reactive/webserver/ServerConfiguration.java | 4 ++-- .../reactive/webserver/SocketConfiguration.java | 11 ++++++----- .../webserver/WaterMarkedBackpressureIT.java | 15 ++++++++++++++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/reactive/webserver/webserver/src/main/java/io/helidon/reactive/webserver/ServerConfiguration.java b/reactive/webserver/webserver/src/main/java/io/helidon/reactive/webserver/ServerConfiguration.java index e5d031ffd4b..5bfb00e3a85 100644 --- a/reactive/webserver/webserver/src/main/java/io/helidon/reactive/webserver/ServerConfiguration.java +++ b/reactive/webserver/webserver/src/main/java/io/helidon/reactive/webserver/ServerConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2022 Oracle and/or its affiliates. + * Copyright (c) 2017, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -543,7 +543,7 @@ public Builder backpressureBufferSize(long size) { *
  • PREFETCH - After first data chunk arrives, probable number of chunks needed to fill the buffer up to watermark is calculated and requested.
  • *
  • NONE - No backpressure is applied, Long.MAX_VALUE(unbounded) is requested from upstream.
  • * - * @param backpressureStrategy One of NONE, PREFETCH or LINEAR, default is LINEAR + * @param backpressureStrategy One of NONE, PREFETCH, LINEAR or AUTO_FLUSH, default is AUTO_FLUSH * @return an updated builder */ @Override diff --git a/reactive/webserver/webserver/src/main/java/io/helidon/reactive/webserver/SocketConfiguration.java b/reactive/webserver/webserver/src/main/java/io/helidon/reactive/webserver/SocketConfiguration.java index ff552e5699f..c8b6b84380c 100644 --- a/reactive/webserver/webserver/src/main/java/io/helidon/reactive/webserver/SocketConfiguration.java +++ b/reactive/webserver/webserver/src/main/java/io/helidon/reactive/webserver/SocketConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2022 Oracle and/or its affiliates. + * Copyright (c) 2017, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -177,11 +177,12 @@ default long backpressureBufferSize() { /** * Strategy for applying backpressure to the reactive stream of response data. + * Switched default to {@link BackpressureStrategy#AUTO_FLUSH} since 3.1.1. * * @return strategy identifier for applying backpressure */ default BackpressureStrategy backpressureStrategy() { - return BackpressureStrategy.LINEAR; + return BackpressureStrategy.AUTO_FLUSH; } /** @@ -404,10 +405,10 @@ default B tls(Supplier tlsConfig) { *
  • PREFETCH - After first data chunk arrives, probable number of chunks needed to fill the buffer up to watermark is calculated and requested.
  • *
  • NONE - No backpressure is applied, Long.MAX_VALUE(unbounded) is requested from upstream.
  • * - * @param backpressureStrategy One of NONE, PREFETCH or LINEAR, default is LINEAR + * @param backpressureStrategy One of NONE, PREFETCH, LINEAR or AUTO_FLUSH, default is AUTO_FLUSH * @return this builder */ - @ConfiguredOption("LINEAR") + @ConfiguredOption("AUTO_FLUSH") B backpressureStrategy(BackpressureStrategy backpressureStrategy); /** @@ -500,7 +501,7 @@ final class Builder implements SocketConfigurationBuilder, io.helidon.c private int initialBufferSize = 128; private boolean enableCompression = false; private long maxPayloadSize = -1; - private BackpressureStrategy backpressureStrategy = BackpressureStrategy.LINEAR; + private BackpressureStrategy backpressureStrategy = BackpressureStrategy.AUTO_FLUSH; private int maxUpgradeContentLength = 64 * 1024; private long maxBufferSize = 5 * 1024 * 1024; diff --git a/reactive/webserver/webserver/src/test/java/io/helidon/reactive/webserver/WaterMarkedBackpressureIT.java b/reactive/webserver/webserver/src/test/java/io/helidon/reactive/webserver/WaterMarkedBackpressureIT.java index 8c7c0869748..bec5b050746 100644 --- a/reactive/webserver/webserver/src/test/java/io/helidon/reactive/webserver/WaterMarkedBackpressureIT.java +++ b/reactive/webserver/webserver/src/test/java/io/helidon/reactive/webserver/WaterMarkedBackpressureIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Oracle and/or its affiliates. + * Copyright (c) 2022, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,6 +58,19 @@ void tearDown() { executorService.shutdown(); } + /** + * Verifies default back-pressure strategy is {@link BackpressureStrategy#AUTO_FLUSH} + * on all sockets. + */ + @Test + void defaultStrategy() { + WebServer webServer = WebServer.builder().build(); + webServer.configuration() + .sockets() + .values() + .forEach(sc -> assertThat(sc.backpressureStrategy(), is(AUTO_FLUSH))); + } + @Test void linear() { AtomicLong receivedSize = new AtomicLong(0);