-
Notifications
You must be signed in to change notification settings - Fork 12
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] Pool gzip.Writer
and bytes.Buffer
#19
Conversation
gzip.Writer
and bytes.Buffer
gzip.Writer
and bytes.Buffer
Hi @Anaethelion, would you mind reviewing this PR whenever you are available? |
Hi @pakio I've taken some time to review and evaluate this PR. I'm not going to merge this in its current state, however I'm interested to know if you have more examples of real world use cases beyond the benchmark ? How does it help you application being more stable ? What kind of usage do you have where this helps ? Search or Bulk indexing ? We still have the option of maintaining the current behavior and adding the pool as an optional behavior. |
hi @Anaethelion , thanks for your feedback!
Understood. Just to clarify, does this mean you've actually experienced OOM with sync.Pool or with this implementation, or have general concern about it?
sure, here are some examples of use cases of grpc-go: link And our team have also been using the feature on the platform for more than a year and is operating without any problem.
Our team uses go-elasticsearch for both data indexing pipeline and search application.
I'm happy to make this change as well as adding more practical test case using actual json file, but firstly I would like to understand your concern regarding OOM by using |
This is just general concern around edge cases while pushing the
Thank you!
Got you. It matches what I've benchmarked locally as well. The greater the payload, the greater the gain which makes sense. At the same time for search heavy use cases I've found this could slow down the client depending on the compression that has been set up.
That concern only led me to consider making this more pluggable at least at first and then in time or for a new major we can flip the switch and make that the default. But as much as we can I'd like not to break existing behavior. |
It sounds a fair concern. |
I've made a few changes on my implementation
I also found a bug in the benchmark that 1. reader was always at the end of the cursor except first loop 2. tp was always recreated in the bench which means the pool is not utilized properly. I updated them as well as the benchmark result in the description. ptal when you get a chance! @Anaethelion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thank you @pakio for the great addition!
Summary
Added
sync.Pool
to poolgzip.Writer
andbytes.Buffer
for better performance.Background
While I was investigating profile report of my application, noticed transport client is not pooling gzip writer and buffer.
As discussed in this Reddit thread and many other places, pooling them will benefit us by reusing allocated memory space rather than allocating and freeing them on every request.
Performance Comparison
These are the benchmark result on my machine (Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz)
Compress body
bench result