ruby-pg icon indicating copy to clipboard operation
ruby-pg copied to clipboard

We are observing a 10-30% regression in aggregate SQL execution time in v1.2.3 in some cases.

Open kitsunde opened this issue 5 years ago • 2 comments
trafficstars

I haven't devised a test for this yet because I'm not sure what to test exactly, but we monitor our SQL execution times. Specifically, with prometheus_exporter we collect durations of SQL execution on each endpoint by hooking into PG::Connection in Rails:

MethodProfiler.patch(PG::Connection, [
  :exec, :async_exec, :exec_prepared, :send_query_prepared, :query
], :sql)

When we upgraded from 1.2.2 to 1.2.3 we observe the following:

Screenshot 2020-07-21 22 30 12 Screenshot 2020-07-21 22 30 04

When we reverted the change the reverse happens:

Screenshot 2020-07-21 22 40 03 Screenshot 2020-07-21 22 39 36

These are the execution times of 30-50 queries in each graph. Looking through the changes in 1.2.3 I'm assuming the time isn't actually spent on SQL executing in PG but rather overhead in the library itself.

We've never faced the issue with segmentation faults that the 1.2.3 release is supposed to fix despite being on ruby 2.7.x for months with a fair amount of traffic.

kitsunde avatar Jul 21 '20 16:07 kitsunde

@kitsunde Thank you for the detailed report! And sorry for the long delay!

The new pg version 1.3.0 changes a lot regarding the handling of the socket IO. It would be very interesting how your results are performance-wise!

larskanis avatar Jan 24 '22 08:01 larskanis

pg-1.3.0 has a new install switch which should improve the query performance a little bit, but it is not enabled per default:

gem inst pg -- --disable-gvl-unlock

or through bundler:

bundle config build.pg --disable-gvl-unlock

See here in the History.rdoc.

larskanis avatar Jan 24 '22 09:01 larskanis