Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do a blocking flush every 100 calls to put_copy_data #474

Merged
merged 1 commit into from
Aug 9, 2022

Conversation

larskanis
Copy link
Collaborator

We had a blocking flush in pg-1.3.x at every call to put_copy_data. This made sure, that all data is sent until the next put_copy_data. In #462 (and pg-1.4.0 to .2) the behaviour was changed to rely on the non-blocking flushs libpq is doing internally. This makes a decent performance improvement especially on Windows. Unfortunately #473 proved that memory bloat can happen, when sending the data is slower than calls to put_copy_data happen.

As a trade-off this proposes to do a blocking flush only every 100 calls.

If libpq is running in blocking mode (PG::Connection.async_api = false) put_copy_data does a blocking flush every time new memory is allocated. Unfortunately we don't have this kind of information, since we don't have access to libpq's PGconn struct and the return codes don't give us an indication when this happens. So doing a flush at every fixed number of calls is a very simple heuristic.

Fixes #473

We had a blocking flush in pg-1.3.x at every call to put_copy_data.
This made sure, that all data is sent until the next put_copy_data.
In ged#462 (and pg-1.4.0 to .2) the behaviour was changed to rely on the non-blocking flushs libpq is doing internally.
This makes a decent performance improvement especially on Windows.
Unfortunately ged#473 proved that memory bloat can happen, when sending the data is slower than calls to put_copy_data happen.

As a trade-off this proposes to do a blocking flush only every 100 calls.

If libpq is running in blocking mode (PG::Connection.async_api = false) put_copy_data does a blocking flush every time new memory is allocated.
Unfortunately we don't have this kind of information, since we don't have access to libpq's PGconn struct and the return codes don't give us an indication when this happens.
So doing a flush at every fixed number of calls is a very simple heuristic.

Fixes ged#473
@larskanis larskanis merged commit 9929ac9 into ged:master Aug 9, 2022
@larskanis larskanis deleted the put_copy_data-flushing branch September 30, 2022 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

copy_data memory bloat in v1.4
1 participant