From 4f3a245407de4ea78eebec3ea731017f33d6eeaf Mon Sep 17 00:00:00 2001 From: Doug Hoyte Date: Wed, 1 Feb 2023 09:23:28 -0500 Subject: [PATCH] config for compression --- TODO | 2 -- golpe.yaml | 9 +++++++++ src/RelayWebsocket.cpp | 9 ++++++++- strfry.conf | 8 ++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 844145a..e67cc2b 100644 --- a/TODO +++ b/TODO @@ -7,8 +7,6 @@ features * limit on number of concurrent sync requests * full-db scan limited by since/until * `strfry sync` command always takes at least 1 second due to batching delay. figure out better way to flush - bool values in config - config for compression less verbose default logging make it easier for a thread to setup a quadrable env diff --git a/golpe.yaml b/golpe.yaml index c13e4b1..d315211 100644 --- a/golpe.yaml +++ b/golpe.yaml @@ -127,6 +127,15 @@ config: desc: "Maximum records that can be returned per filter" default: 500 + - name: relay__compression__enabled + desc: "Use permessage-deflate compression if supported by client. Reduces bandwidth, but slight increase in CPU" + default: true + noReload: true + - name: relay__compression__slidingWindow + desc: "Maintain a sliding window buffer for each connection. Improves compression, but uses more memory" + default: true + noReload: true + - name: relay__logging__dumpInAll desc: "Dump all incoming messages" default: false diff --git a/src/RelayWebsocket.cpp b/src/RelayWebsocket.cpp index a47c9f4..d286d91 100644 --- a/src/RelayWebsocket.cpp +++ b/src/RelayWebsocket.cpp @@ -69,7 +69,14 @@ void RelayServer::runWebsocket(ThreadPool::Thread &thr) { - hubGroup = hub.createGroup(uWS::PERMESSAGE_DEFLATE | uWS::SLIDING_DEFLATE_WINDOW, cfg().relay__maxWebsocketPayloadSize); + { + int extensionOptions = 0; + + if (cfg().relay__compression__enabled) extensionOptions |= uWS::PERMESSAGE_DEFLATE; + if (cfg().relay__compression__slidingWindow) extensionOptions |= uWS::SLIDING_DEFLATE_WINDOW; + + hubGroup = hub.createGroup(extensionOptions, cfg().relay__maxWebsocketPayloadSize); + } if (cfg().relay__autoPingSeconds) hubGroup->startAutoPing(cfg().relay__autoPingSeconds * 1'000); diff --git a/strfry.conf b/strfry.conf index 8b3620d..6b9f2a2 100644 --- a/strfry.conf +++ b/strfry.conf @@ -41,6 +41,14 @@ relay { # Maximum records that can be returned per filter maxFilterLimit = 500 + compression { + # Use permessage-deflate compression if supported by client. Reduces bandwidth, but slight increase in CPU + enabled = true + + # Maintain a sliding window buffer for each connection. Improves compression, but uses more memory + slidingWindow = true + } + logging { # Dump all incoming messages dumpInAll = false