parca-agent
parca-agent copied to clipboard
pkg/agent: trigger batch before grpc message size overflow
Hello, I don't have much experience on writing concurrent code, might make some mistake. Thanks for guidance in advance. :D
@heylongdacoder Let me know if you need any help with this.
@kakkoyun thanks for the review and guidance! yes I need some help. I am not sure how would it works if we removed the batchDone channel. If we removed batchDone, I think there is a chance where WriteRaw function will continue to append data to the overflowed writeRawRequest(https://github.com/parca-dev/parca-agent/pull/836/files#diff-7276397f96515c11ca49f4f72de2237d63936ab985888a5a4fe07ccf8c371d42R166) before the batch function could send it.
Currently I got another idea to avoid the creation of these triggerBatch and batchDone channels. Instead of a writeRawRequest, what about we create a slices of writeRawRequest and a writeRawRequestIndex? WriteRaw function will write to writeRawRequest[writeRawRequestIndex] and when the current one is going to be overflowed, then we write to writeRawRequest[writeRawRequestIndex+1]. Then the batch function either loop through the slices of writeRawRequest to fire gRPC request sequentially or create goroutine for each element to fire gRPC request. Do you think this would work and is this a better approach?