Skip to content

Commit

Permalink
Enable HASURA_GRAPHQL_PG_CONN_LIFETIME by default with a default of 6…
Browse files Browse the repository at this point in the history
…00 sec

See: hasura/pg-client-hs#26

We're still experiencing segfaults in certain configurations from the
libpq shrinking approach. This should be very safe, but is also
inadequate in several ways:

- negotiating a new connection is quite heavyweight compared to
  allocating a 1mb buffer
- thundering herd issues (TODO maybe add some jitter here)
- memory is not reclaimed promptly; there is no good default here.
  • Loading branch information
jberryman committed Nov 16, 2020
1 parent e2d07bb commit 13746b2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ This release contains the [PDV refactor (#4111)](https://github.com/hasura/graph
- server: accept only non-negative integers for batch size and refetch interval (close #5653) (#5759)
- server: fix bug which arised when renaming a table which had a manual relationship defined (close #4158)
- server: limit the length of event trigger names (close #5786)
- server: enable HASURA_GRAPHQL_PG_CONN_LIFETIME by default to reclaim memory
- server: Configurable websocket keep-alive interval. Add `--websocket-keepalive` command-line flag
and handle `HASURA_GRAPHQL_WEBSOCKET_KEEPALIVE` env variable (fix #3539)
**NOTE:** If you have event triggers with names greater than 42 chars, then you should update their names to avoid running into Postgres identifier limit bug (#5786)
Expand Down
2 changes: 1 addition & 1 deletion server/cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ package graphql-engine
source-repository-package
type: git
location: https://github.com/hasura/pg-client-hs.git
tag: 633a06ba9c1e6a561b0ad0d25951fcdf6dd054ca
tag: 08b02fbb4e7c7e1ac44325ef1bd107725f59255f

source-repository-package
type: git
Expand Down
8 changes: 6 additions & 2 deletions server/src-lib/Hasura/Server/Init.hs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ mkServeOptions rso = do
-- hard throughput cap at 1000RPS when db queries take 50ms on average:
conns <- fromMaybe 50 <$> withEnv c (fst pgConnsEnv)
iTime <- fromMaybe 180 <$> withEnv i (fst pgTimeoutEnv)
connLifetime <- withEnv cl (fst pgConnLifetimeEnv)
connLifetime <- withEnv cl (fst pgConnLifetimeEnv) <&> \case
Nothing -> Just 600 -- Not set by user; use the default timeout
Just 0 -> Nothing -- user wants to disable PG_CONN_LIFETIME
Just n -> Just n -- user specified n seconds lifetime
allowPrepare <- fromMaybe True <$> withEnv p (fst pgUsePrepareEnv)
return $ Q.ConnParams stripes conns iTime allowPrepare connLifetime

Expand Down Expand Up @@ -393,7 +396,8 @@ pgConnLifetimeEnv :: (String, String)
pgConnLifetimeEnv =
( "HASURA_GRAPHQL_PG_CONN_LIFETIME"
, "Time from connection creation after which the connection should be destroyed and a new one "
<> "created. (default: none)"
<> "created. A value of 0 indicates we should never destroy an active connection. If 0 is "
<> "passed, memory from large query results may not be reclaimed. (default: 600 sec)"
)

pgUsePrepareEnv :: (String, String)
Expand Down

0 comments on commit 13746b2

Please sign in to comment.