Drop unsafe from PQconsumeInput FFI import #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @phadej!
I've been doing performance testing of PostgREST (which indirectly uses this library) with GHC 8.10.1 (and 8.8.3 too). We have a latency spikes issue with it, easily attributable to idle GC pauses. That is, tens-to-hundreds-of-milliseconds long stop-the-haskell-world episodes when the GC is not using the CPU; is idle; blocked.
You can check out my methods & intermediate results in this thread: https://gitlab.haskell.org/ghc/ghc/-/issues/18415
While I currently cannot completely explain all the idle pauses — it's 100% clear that one of contributing issues is this line here in
postgresql-libpq
. As the commit message says:PQconsumeInput()
in libpq.so can go into blocking IO. While the GHC User Guide isn't terribly clear on how FFI interacts with GC, you can see this doc patch and this graph. All together, this leads to the conclusion that the import ofPQconsumeInput
should not be markedunsafe
.Sure thing, I did test this change (and not only it). It's a bit hard to summarize concisely — but if you let me hand-pick a few graphs, I'd say that this one is "typical" for the code in
master
:The vertical axis is latency of PostgREST handling HTTP requests; red lines are 10s timeouts. 1000 requests-per-second load; everything run on a modest SSD laptop, without CPU saturation. Here's a similar graph for a build with this patch applied:
(Well actually, all
postgresql-libpq
imports are unmarked unsafe in the latter graph; but onlyPQconsumeInput
matters.)Might not seem significant (and I can pick way more dramatic graphs) — but when I drill down into
threadscope
profiles, this patch does eliminate places like this.Please review, merge & release.