Skip to content

Commit

Permalink
Merge pull request #186 from well-typed/finley/override-ping-on-server
Browse files Browse the repository at this point in the history
Override ping rate limit on server
  • Loading branch information
edsko authored Jul 11, 2024
2 parents c341134 + 44d36dc commit 4c1f20d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
4 changes: 3 additions & 1 deletion kvstore/KVStore/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ client Cmdline{
cmdJSON
, cmdSecure
, cmdDisableTcpNoDelay
, cmdPingRateLimit
} statsVar = do
knownKeys <- RandomAccessSet.new
random <- RandomGen.new
Expand Down Expand Up @@ -126,7 +127,8 @@ client Cmdline{
params :: ConnParams
params = def {
connHTTP2Settings = def {
http2TcpNoDelay = not cmdDisableTcpNoDelay
http2TcpNoDelay = not cmdDisableTcpNoDelay
, http2OverridePingRateLimit = cmdPingRateLimit
}
}

Expand Down
8 changes: 8 additions & 0 deletions kvstore/KVStore/Cmdline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ data Cmdline = Cmdline {
, cmdJSON :: Bool
, cmdSecure :: Bool
, cmdDisableTcpNoDelay :: Bool
, cmdPingRateLimit :: Maybe Int
}

data Mode =
Expand Down Expand Up @@ -69,6 +70,13 @@ parseCmdline =
Opt.long "disable-tcp-nodelay"
, Opt.help "Disable the TCP_NODELAY option"
])
<*> (Opt.optional $
Opt.option Opt.auto $ mconcat [
Opt.long "ping-rate-limit"
, Opt.metavar "PINGs/sec"
, Opt.help "Allow at most this many pings per second from the peer"
]
)

parseMode :: Parser Mode
parseMode = asum [
Expand Down
4 changes: 3 additions & 1 deletion kvstore/KVStore/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ withKeyValueServer cmdline@Cmdline{
cmdJSON
, cmdSecure
, cmdDisableTcpNoDelay
, cmdPingRateLimit
} k = do
store <- Store.new

Expand Down Expand Up @@ -61,7 +62,8 @@ withKeyValueServer cmdline@Cmdline{
params :: ServerParams
params = def {
serverHTTP2Settings = def {
http2TcpNoDelay = not cmdDisableTcpNoDelay
http2TcpNoDelay = not cmdDisableTcpNoDelay
, http2OverridePingRateLimit = cmdPingRateLimit
}

-- The Java benchmark does not use compression (unclear if the Java
Expand Down
11 changes: 8 additions & 3 deletions util/Network/GRPC/Util/HTTP2.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE CPP #-}

#include "MachDeps.h"


module Network.GRPC.Util.HTTP2 (
-- * General auxiliary
Expand Down Expand Up @@ -138,16 +138,21 @@ mkServerConfig ::
mkServerConfig http2Settings numberOfWorkers =
Server.defaultServerConfig {
Server.numberOfWorkers =
fromMaybe
maybe
(Server.numberOfWorkers Server.defaultServerConfig)
(fromIntegral <$> numberOfWorkers)
fromIntegral
numberOfWorkers
, Server.connectionWindowSize = fromIntegral $
http2ConnectionWindowSize http2Settings
, Server.settings = Server.defaultSettings {
Server.initialWindowSize = fromIntegral $
http2StreamWindowSize http2Settings
, Server.maxConcurrentStreams = Just . fromIntegral $
http2MaxConcurrentStreams http2Settings
, Server.pingRateLimit =
fromMaybe
(Server.pingRateLimit Server.defaultSettings)
(http2OverridePingRateLimit http2Settings)
}
}

Expand Down

0 comments on commit 4c1f20d

Please sign in to comment.