pg_net icon indicating copy to clipboard operation
pg_net copied to clipboard

Increase default request rate

Open steve-chavez opened this issue 1 year ago • 5 comments

Problem

The current request rate of 200 req/s (pg_net.batch_size) is too low for several cases. It's limited this way to save on CPU usage, but this can be improved.

For example, right now the net._http_response tables store the response headers as jsonb. For this, processing is needed on each request/response to convert the headers to jsonb, which consumes CPU.

Solution

Store the response headers as binary and then provide a view that converts them to json on demand. This can be done without a breaking change. Then increase the default request rate.

Notes

  • Feedback on twitter about desired throughput https://x.com/martindonadieu/status/1869434542873878711 (200K req/s.. seems like a lot for a single instance, we would need a way to distribute load).

steve-chavez avatar Oct 17 '24 22:10 steve-chavez

+1, I think the value of pg_net.batch_size is far less than 200. By the way, how can I check the value of pg_net.batch_size? @steve-chavez

begank avatar Oct 18 '24 09:10 begank

@begank Try

show pg_net.batch_size;

steve-chavez avatar Oct 18 '24 18:10 steve-chavez

do we have a way to have in our migration file the set of batch_size ? when i add that to migrations: alter system set pg_net.batch_size to 2000; ERROR: ALTER SYSTEM cannot be executed within a pipeline (SQLSTATE 25001) At statement 61: alter system set pg_net.batch_size to 2000

riderx avatar Dec 21 '24 11:12 riderx

@riderx Looks like your migration tool is using libpq pipeline mode, which is incompatible with some SQL statements (COPY being another one).

For now, you could use another migration tool as a workaround.

Once https://github.com/supabase/pg_net/issues/163 is done we won't require ALTER SYSTEM anymore.

steve-chavez avatar Dec 28 '24 03:12 steve-chavez

I use the one in supabase CLI, so I don’t know exactly witch one it is but i believe your team does :) I would live to have that not require alter and be a method like set_batch_size like we have in others plugins

riderx avatar Dec 28 '24 14:12 riderx