While setting the size of a channel,
should consider how go scheduling mechanism works.
A small size of channel(including an un-buffered channel) causing the producer to block the running goroutine thus forces a re-scheduling (on same physical thread most of the time).
While a larger size of channel can reduce the latency of producing data into the channel but having the consumer delay the processing.
Here's the time slice down into different stages(ref by Vincent Blanchon's article):
Measure the performance before hard-setting the channel size,
i.e make the size configurable.
Reference:
https://medium.com/a-journey-with-go/go-what-does-a-goroutine-switch-actually-involve-394c202dddb7
should consider how go scheduling mechanism works.
A small size of channel(including an un-buffered channel) causing the producer to block the running goroutine thus forces a re-scheduling (on same physical thread most of the time).
While a larger size of channel can reduce the latency of producing data into the channel but having the consumer delay the processing.
Here's the time slice down into different stages(ref by Vincent Blanchon's article):
Measure the performance before hard-setting the channel size,
i.e make the size configurable.
Reference:
https://medium.com/a-journey-with-go/go-what-does-a-goroutine-switch-actually-involve-394c202dddb7
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.