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

Performance improvement after output refactoring #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dpirotte
Copy link
Contributor

@dpirotte dpirotte commented Nov 7, 2018

In an attempt to bring our fork closer to master, we discovered that d4c0e81 introduced a meaningful performance change. d4c0e81 replaced several appendStringInfoString uses with appendStringInfo, which dramatically cleaned up the output code at the cost of a performance hit.

This proposal reduces decoding time by ~20% as measured by this benchmarking script. It swaps appendStringInfo for a new appendStringInfoStrings helper, which loops through a variable argument list and calls the more performant appendStringInfoString under the hood, skipping if the argument starts with a null byte, i.e. whitespace args when pretty-print isn't set. (I think this is safe in these use cases, and it is responsible for a full quarter of the performance return.)

I'm very open to suggestions or other approaches that keep the (very nice) output refactoring and reclaim most of the performance.

Removing pretty-print branching replaced several appendStringInfoString
uses with appendStringInfo, which dramatically cleaned up the output
code at the cost of decoding about 22% slower. We can recover most of
this performance and keep the tidiness by adding a helper function to
run appendStringInfoString for a variable number of strings. We lose
some niceties of the sprintf-style template, but the performance seems
worth it for high-throughput databases.

"22% slower" was measured by populating a pgbench database with scale
factor 5, running 50K transactions, DELETE-ing all the data, then timing
how long it takes to receive all the changes with `pg_recvlogical`. On a
c5.4xlarge EC2 instance backed by a gp2 EBS volume, this takes about 9.2
seconds on this branch compared to about 11.2s on master as of
aa4077a.
@dpirotte
Copy link
Contributor Author

dpirotte commented Nov 7, 2018

I ran some additional benchmarks overnight with the same script to verify the performance delta, and it remains consistent.

pgbench txns rows output before after diff
100,000 1,200,057 15.219s 12.058s -20.8%
200,000 1,900,073 23.849s 18.227s -23.6%
300,000 2,600,083 31.222s 24.182s -22.6%
400,000 3,300,101 39.237s 31.146s -20.7%
500,000 4,000,111 47.055s 36.420s -22.7%

@jmealo
Copy link

jmealo commented Apr 6, 2019

@eulerto: this looks interesting. Thoughts?

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.

None yet

2 participants