graphql-engine-1.0.0: GraphQL API over Postgres
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hasura.GC

Synopsis

Documentation

ourIdleGC Source #

Arguments

:: Logger Hasura 
-> DiffTime

Run a major GC when we've been "idle" for idleInterval

-> DiffTime

...as long as it has been > minGCInterval time since the last major GC

-> DiffTime

Additionally, if it has been > maxNoGCInterval time, force a GC regardless.

-> IO void 

The RTS's idle GC doesn't work for us:

  • when `-I` is too low it may fire continuously causing scary high CPU when idle among other issues (see #2565)
  • when we set it higher it won't run at all leading to memory being retained when idle (especially noticeable when users are benchmarking and see memory stay high after finishing). In the theoretical worst case there is such low haskell heap pressure that we never run finalizers to free the foreign data from e.g. libpq.
  • as of GHC 8.10.2 we have access to `-Iw`, but those two knobs still don’t give us a guarantee that a major GC will always run at some minumum frequency (e.g. for finalizers)

...so we hack together our own using GHC.Stats, which should have insignificant runtime overhead.

NOTE: as always the cost of a major GC (forced here, or initiated by the RTS) with the default copying collector is proportional to live (non-garbage) heap data. Tune parameters here to balance: more frequent GC pauses vs. prompt cleanup of foreign data (which does not exert GC pressure).

NOTE: larger nursery size (+RTS -A) may help us run more finalizers during cheaper minor GCs, before they are promoted, making it feasible (maybe) to run this with longer interval parameters.