diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-02-12 11:54:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-12 11:54:53 +0100 |
commit | 410ddc4d2a78924f5ba6500131cd0e3d0484ae64 (patch) | |
tree | 59672271095eae55e9fdc9c4849b0c1c7ebc46f2 /jrt | |
parent | 93e7f6bcba5d8cbc0d9700ec64dc6540eb935ef2 (diff) | |
parent | b0087080fd6766e6eb303317156b3fa8fd7d87e9 (diff) |
Merge pull request #16492 from vespa-engine/balder/use-small-buffers-in-applications-that-are-tight-on-memory
Use small buffers where size matters more than speed.
Diffstat (limited to 'jrt')
-rw-r--r-- | jrt/src/com/yahoo/jrt/Supervisor.java | 12 | ||||
-rw-r--r-- | jrt/src/com/yahoo/jrt/slobrok/api/Mirror.java | 1 | ||||
-rw-r--r-- | jrt/src/com/yahoo/jrt/slobrok/server/Slobrok.java | 2 |
3 files changed, 14 insertions, 1 deletions
diff --git a/jrt/src/com/yahoo/jrt/Supervisor.java b/jrt/src/com/yahoo/jrt/Supervisor.java index d4168e97743..bcd525c9596 100644 --- a/jrt/src/com/yahoo/jrt/Supervisor.java +++ b/jrt/src/com/yahoo/jrt/Supervisor.java @@ -15,6 +15,8 @@ import java.util.concurrent.atomic.AtomicReference; **/ public class Supervisor { + private static final int SMALL_INPUT_BUFFER_SIZE = 20 * 1024; // Large enough too hold the typical application buffersize of 17k. + private static final int SMALL_OUTPUT_BUFFER_SIZE = 8 *1024; // Suitable small buffer usage with many connections and little traffic. private final Transport transport; private SessionHandler sessionHandler = null; private final Object methodMapLock = new Object(); @@ -34,6 +36,16 @@ public class Supervisor { } /** + * Will optimize buffers size for small memory footprint + * Use this when you have many connections with very little traffic. + **/ + public Supervisor useSmallBuffers() { + setMaxInputBufferSize(SMALL_INPUT_BUFFER_SIZE); + setMaxOutputBufferSize(SMALL_OUTPUT_BUFFER_SIZE); + return this; + } + + /** * Set maximum input buffer size. This value will only affect * connections that use a common input buffer when decoding * incoming packets. Note that this value is not an absolute diff --git a/jrt/src/com/yahoo/jrt/slobrok/api/Mirror.java b/jrt/src/com/yahoo/jrt/slobrok/api/Mirror.java index 5a4a79995d8..1a00cd25a2c 100644 --- a/jrt/src/com/yahoo/jrt/slobrok/api/Mirror.java +++ b/jrt/src/com/yahoo/jrt/slobrok/api/Mirror.java @@ -57,6 +57,7 @@ public class Mirror implements IMirror { **/ public Mirror(Supervisor orb, SlobrokList slobroks, BackOffPolicy bop) { this.orb = orb; + orb.useSmallBuffers(); this.slobroks = slobroks; this.backOff = bop; transportThread = orb.transport().selectThread(); diff --git a/jrt/src/com/yahoo/jrt/slobrok/server/Slobrok.java b/jrt/src/com/yahoo/jrt/slobrok/server/Slobrok.java index f19779732ba..854cd973e4d 100644 --- a/jrt/src/com/yahoo/jrt/slobrok/server/Slobrok.java +++ b/jrt/src/com/yahoo/jrt/slobrok/server/Slobrok.java @@ -39,7 +39,7 @@ public class Slobrok { public Slobrok(int port) throws ListenFailedException { // NB: rpc must be single-threaded - orb = new Supervisor(new Transport("slobrok-" + port, 1)); + orb = new Supervisor(new Transport("slobrok-" + port, 1)).useSmallBuffers(); registerMethods(); try { listener = orb.listen(new Spec(port)); |