Use Pool to store and reuse GZIPWriters #1329
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
GZIPWriter are very expensive to create and leads
to allocating a lot of memory. They are perfect for reusing
(they have .reset method for this)
I profiled a web service inside my company and I noticed that creation of GZipWriter is responsible for 20% of memory allocation (in bytes).
Inspired by
https://www.akshaydeo.com/blog/2017/12/23/How-did-I-improve-latency-by-700-percent-using-syncPool/
https://dzone.com/articles/memory-pooling-in-go-where-why-and-how
Could you help me to run unit tests?
I noticed there is a shell script ./run-es.sh which worked after I did
sudo sysctl -w vm.max_map_count=262144
(my workstation is linux)But
go test .
still fails for a lot of tests withI am quite puzzled
I also learned that I probably misuse
defer
(cause it is in the loop)Current proposal with additional parameter looks a bit ugly too.
I will appreciate your feedback. This is my first pull request in go project (I am new to go)