-
Notifications
You must be signed in to change notification settings - Fork 442
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
consumer: optimize memory allocation in DecodeMessage and ReadResponse #174
Comments
The message must be drained from the conn before go-nsq can read the next message. Eliminating
I think a nice approach would be to provide an interface for custom message decoding. This eliminates the need to |
remember that you could put the bigger buffers back into the pool for reuse. so if you have high sizing variety it just means you'll be using more memory (until the next GC run) and there will definitely be benefit in terms of allocations and amount of GC runs. i like your idea of having a special api for it though, and leave allocations up to the user of the library! |
Thanks for looking into this @Dieterbe and apologies for the delayed response.
I'm guessing there are lots of opportunities like this throughout the library. With respect to this specific issue, why don't we just experiment with some of the proposed solutions and see how far we get? I would love some help contributing patches for these! |
@Dieterbe those results look promising and the diff looks simple and safe to me, want to open up a PR so we can get that in? (we can leave this issue open to track overall optimization progress) |
see nsqio#174 (comment) for more discussion and before and after
see nsqio#174 (comment) for more discussion and before and after
* DecodeMessage: skip bytes Buffer, reducing alloc overhead see #174 (comment) for more discussion and before and after * allow empty bodies + document message format as discussed in #175 and on IRC
here's a profile from a production service (if you're interested, the code lives at https://github.com/raintank/raintank-metric/tree/master/metric_tank)
we can probably address the first and 3rd item pretty easily by using a sync.Pool
the first one comes from
msg.Body, err = ioutil.ReadAll(buf)
in go-nsq.DecodeMessageThe text was updated successfully, but these errors were encountered: