From 0982c759d2fefddc56652add0499cdb56221cdf7 Mon Sep 17 00:00:00 2001 From: Edsko de Vries Date: Thu, 4 Jul 2024 11:15:50 +0200 Subject: [PATCH] WIP: Enable `TCP_NODELAY` This should be optional; for now we're just testing if this works at all. --- .github/workflows/haskell-ci.yml | 18 ++++++++++++---- cabal.project | 10 +++++++++ cabal.project.ci | 10 +++++++++ grapesy.cabal | 31 ++++++--------------------- src/Network/GRPC/Client/Connection.hs | 17 +++++++++++---- src/Network/GRPC/Server/Run.hs | 5 ++++- 6 files changed, 58 insertions(+), 33 deletions(-) diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml index 3493d6ff..47cd715a 100644 --- a/.github/workflows/haskell-ci.yml +++ b/.github/workflows/haskell-ci.yml @@ -8,9 +8,9 @@ # # For more information, see https://github.com/haskell-CI/haskell-ci # -# version: 0.19.20240608 +# version: 0.19.20240702 # -# REGENDATA ("0.19.20240608",["github","cabal.project.ci"]) +# REGENDATA ("0.19.20240702",["github","cabal.project.ci"]) # name: Haskell-CI on: @@ -68,7 +68,7 @@ jobs: curl -sL https://downloads.haskell.org/ghcup/0.1.20.0/x86_64-linux-ghcup-0.1.20.0 > "$HOME/.ghcup/bin/ghcup" chmod a+x "$HOME/.ghcup/bin/ghcup" "$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false) - "$HOME/.ghcup/bin/ghcup" install cabal 3.10.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false) + "$HOME/.ghcup/bin/ghcup" install cabal 3.12.1.0 || (cat "$HOME"/.ghcup/logs/*.* && false) apt-get update apt-get install -y libsnappy-dev env: @@ -88,7 +88,7 @@ jobs: echo "HC=$HC" >> "$GITHUB_ENV" echo "HCPKG=$HCPKG" >> "$GITHUB_ENV" echo "HADDOCK=$HADDOCK" >> "$GITHUB_ENV" - echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.2.0 -vnormal+nowrap" >> "$GITHUB_ENV" + echo "CABAL=$HOME/.ghcup/bin/cabal-3.12.1.0 -vnormal+nowrap" >> "$GITHUB_ENV" HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))') echo "HCNUMVER=$HCNUMVER" >> "$GITHUB_ENV" echo "ARG_TESTS=--enable-tests" >> "$GITHUB_ENV" @@ -175,6 +175,16 @@ jobs: allow-newer: proto-lens:base allow-newer: proto-lens-runtime:base + source-repository-package + type: git + location: https://github.com/edsko/network-run + tag: 70211ef61ebbf178d6681ec37d3293d720ec9030 + + source-repository-package + type: git + location: https://github.com/edsko/http2-tls + tag: 53d8b7a0d2a044606de0906e5b66a1f2bce549bd + package grapesy tests: True benchmarks: True diff --git a/cabal.project b/cabal.project index 92172526..bf87595f 100644 --- a/cabal.project +++ b/cabal.project @@ -5,6 +5,16 @@ package grapesy benchmarks: True flags: +build-demo +build-stress-test +snappy +source-repository-package + type: git + location: https://github.com/edsko/network-run + tag: 70211ef61ebbf178d6681ec37d3293d720ec9030 + +source-repository-package + type: git + location: https://github.com/edsko/http2-tls + tag: 53d8b7a0d2a044606de0906e5b66a1f2bce549bd + -- -- ghc 9.10 -- diff --git a/cabal.project.ci b/cabal.project.ci index bee011df..82d05ec2 100644 --- a/cabal.project.ci +++ b/cabal.project.ci @@ -6,6 +6,16 @@ package grapesy flags: +build-demo +build-stress-test +snappy +strace ghc-options: -Werror +source-repository-package + type: git + location: https://github.com/edsko/network-run + tag: 70211ef61ebbf178d6681ec37d3293d720ec9030 + +source-repository-package + type: git + location: https://github.com/edsko/http2-tls + tag: 53d8b7a0d2a044606de0906e5b66a1f2bce549bd + -- -- ghc 9.10 -- diff --git a/grapesy.cabal b/grapesy.cabal index 80a1f4d2..809028bb 100644 --- a/grapesy.cabal +++ b/grapesy.cabal @@ -197,18 +197,21 @@ library , case-insensitive >= 1.2 && < 1.3 , conduit >= 1.3 && < 1.4 , containers >= 0.6 && < 0.8 + , crypton-x509 >= 1.7 && < 1.8 + , crypton-x509-store >= 1.6 && < 1.7 + , crypton-x509-system >= 1.6 && < 1.7 , data-default >= 0.7 && < 0.8 , deepseq >= 1.4 && < 1.6 , exceptions >= 0.10 && < 0.11 , hashable >= 1.3 && < 1.5 , http-types >= 0.12 && < 0.13 , http2 >= 5.2.4 && < 5.3 - , http2-tls >= 0.2.11 && < 0.3 + , http2-tls >= 0.3.1 && < 0.4 , lens >= 5.0 && < 5.4 , mtl >= 2.2 && < 2.4 , network >= 3.1 && < 3.3 , network-byte-order >= 0.1 && < 0.2 - , network-run >= 0.2.7 && < 0.3 + , network-run >= 0.3.2 && < 0.4 , proto-lens >= 0.7 && < 0.8 , proto-lens-runtime >= 0.7 && < 0.8 , random >= 1.2 && < 1.3 @@ -216,6 +219,7 @@ library , stm >= 2.5 && < 2.6 , text >= 1.2 && < 2.2 , time-manager >= 0.1 && < 0.2 + , tls >= 2.1 && < 2.2 , unbounded-delays >= 0.1.1 && < 0.2 , unordered-containers >= 0.2 && < 0.3 , utf8-string >= 1.0 && < 1.1 @@ -238,22 +242,6 @@ library build-depends: , snappy-c >= 0.1 && < 0.2 - -- tls 1.7 starts using Kazu's forked versions of x509-* packages - if flag(crypton) - -- Lower bounds are the first version of these packages after forking. - build-depends: - , tls >= 1.7 && < 2.1 - , crypton-x509 >= 1.7 && < 1.8 - , crypton-x509-store >= 1.6 && < 1.7 - , crypton-x509-system >= 1.6 && < 1.7 - else - -- Upper bounds are the final version of these packages before forking. - build-depends: - , tls >= 1.5 && < 1.7 - , x509 >= 1.7 && < 1.8 - , x509-store >= 1.6 && < 1.7 - , x509-system >= 1.6 && < 1.7 - test-suite test-record-dot import: , lang @@ -362,7 +350,7 @@ test-suite test-grapesy , tasty-hunit >= 0.10 && < 0.11 , tasty-quickcheck >= 0.10 && < 0.11 , text >= 1.2 && < 2.2 - , tls >= 1.5 && < 2.1 + , tls >= 2.1 && < 2.2 , tree-diff >= 0.3 && < 0.4 executable demo-client @@ -617,11 +605,6 @@ Flag build-stress-test default: False manual: True -Flag crypton - description: Use the crypton-x509-* package family instead of x509-* - default: True - manual: False - Flag snappy description: Enable snappy compression capabilities default: True diff --git a/src/Network/GRPC/Client/Connection.hs b/src/Network/GRPC/Client/Connection.hs index c8832375..07cbe183 100644 --- a/src/Network/GRPC/Client/Connection.hs +++ b/src/Network/GRPC/Client/Connection.hs @@ -560,9 +560,11 @@ connectSecure connParams attempt validation sslKeyLog addr = do case validation of ValidateServer _ -> True NoServerValidation -> False - , HTTP2.TLS.Client.settingsCAStore = caStore - , HTTP2.TLS.Client.settingsKeyLogger = keyLogger - , HTTP2.TLS.Client.settingsAddrInfoFlags = [] + + , HTTP2.TLS.Client.settingsCAStore = caStore + , HTTP2.TLS.Client.settingsKeyLogger = keyLogger + , HTTP2.TLS.Client.settingsAddrInfoFlags = [] + , HTTP2.TLS.Client.settingsOpenClientSocket = openClientSocket , HTTP2.TLS.Client.settingsConcurrentStreams = fromIntegral $ @@ -626,7 +628,14 @@ overridePingRateLimit connParams clientConfig = clientConfig { runTCPClient :: Address -> (Socket -> IO a) -> IO a runTCPClient Address{addressHost, addressPort} = - Run.runTCPClient addressHost (show addressPort) + Run.runTCPClientWithSocket openClientSocket addressHost (show addressPort) + +openClientSocket :: AddrInfo -> IO Socket +openClientSocket = + Run.openClientSocketWithOptions socketOptions + where + socketOptions :: [(SocketOption, Int)] + socketOptions = [(NoDelay, 1)] -- | Write-buffer size -- diff --git a/src/Network/GRPC/Server/Run.hs b/src/Network/GRPC/Server/Run.hs index ce7f7a6f..70df3cf2 100644 --- a/src/Network/GRPC/Server/Run.hs +++ b/src/Network/GRPC/Server/Run.hs @@ -410,9 +410,12 @@ disableTimeout = openServerSocket :: TMVar Socket -> AddrInfo -> IO Socket openServerSocket socketTMVar addr = do - sock <- Run.openServerSocket addr + sock <- Run.openServerSocketWithOptions socketOptions addr atomically $ putTMVar socketTMVar sock return sock + where + socketOptions :: [(SocketOption, Int)] + socketOptions = [(NoDelay, 1)] writeBufferSize :: BufferSize writeBufferSize = 4096