Goroutines and channels optimization

245 views
Skip to first unread message

Kanak Bhatia

unread,
May 8, 2025, 4:48:36 PMMay 8
to golang-nuts
Does anyone have idea how to optimize consumers, producers and channels using golang. I have to upload a million objects to a cloud object storage, but unable to get a optimzed values for above parametres. Producers used to create objects and send data through channels and receive  them at consumers and call api from there.

Jason E. Aten

unread,
May 9, 2025, 4:27:11 PMMay 9
to golang-nuts
There's not enough detail here to be more prescriptive than "use the profiler". You can of course insert calls to t := time.Now() at lots of places, compute time.Since(t) after an aggregate operation, and collect statistics on the time each operation takes -- a kind of poor-person's manual profiling -- if pprof isn't giving you what you need. In my experience needing to do so is rare. If you need to get down to L1 and cache coherency optimization, perf is your friend (https://en.wikipedia.org/wiki/Perf_%28Linux%29). Start by figuring out "where the time goes"-- is it disk, network, memory, or CPU bound?

Jason E. Aten

unread,
May 10, 2025, 10:21:54 PMMay 10
to golang-nuts
If you are asking how to benchmark variations of a design, rather an
improve an existing one, this is a nice survey of tools:
https://betterstack.com/community/guides/scaling-go/golang-benchmarking/

The classic pprof intro which gives a step by step example is:

ren...@ix.netcom.com

unread,
May 10, 2025, 10:33:33 PMMay 10
to golang-nuts
The two most likely limiters in performance will be your network pipe to the cloud and the QPS quota offered by the service. If you are not reaching those limits you should increase the parallelism until you do. If your cpu becomes saturated first you probably need larger buffer sizes in the I/o. 

Kanak Bhatia

unread,
May 11, 2025, 12:04:27 PMMay 11
to ren...@ix.netcom.com, golang-nuts

Does we have any kind of documented material or mathematical theory type stuff for these things or is it more like hit or try


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/6af4acac-c8c8-462c-aad4-08e1df73f694n%40googlegroups.com.

Robert Engels

unread,
May 11, 2025, 12:19:40 PMMay 11
to Kanak Bhatia, golang-nuts
Of that I’m not sure. It is based on deep knowledge of how these things are built from the hardware to the kernel to network protocols to the service layers. 

It broadly falls under performance tuning of which there is lots of literature. 

The key element of how channels and go routines play into this - is that when dealing with synchronous requests to a service (many services offer async endpoints) you need to be able to parallelize these. Then you need to be able to provide the data as fast as the network can accept it - most networks today are faster than disk storage - even some SSD. So then the disk storage array becomes the bottleneck and you need to parallelize that (RAID etc) and the kernel access. 

Often for massive uploads you might even partition the job across machines each with a portion of the data set. 

On May 11, 2025, at 11:04 AM, Kanak Bhatia <kanakb...@gmail.com> wrote:



Kanak Bhatia

unread,
May 11, 2025, 12:24:08 PMMay 11
to Robert Engels, golang-nuts

Thanks for the tip!

Could you suggest some resources for the same regarding these design considerations if you know of any ?

Robert Engels

unread,
May 11, 2025, 12:36:11 PMMay 11
to Kanak Bhatia, golang-nuts

Robert Engels

unread,
May 11, 2025, 12:38:38 PMMay 11
to Kanak Bhatia, golang-nuts
Lastly this seems to be a decent read on using gsutil- the concepts are the same for all services. https://jbrojbrojbro.medium.com/moving-mountains-large-file-upload-performance-d98e066b8401

Robert Engels

unread,
May 11, 2025, 1:15:11 PMMay 11
to Kanak Bhatia, golang-nuts

Kanak Bhatia

unread,
May 11, 2025, 1:25:10 PMMay 11
to Robert Engels, golang-nuts

Thanks, I'll check it out.

Reply all
Reply to author
Forward
0 new messages