On Tue, May 22, 2018 at 7:12 AM Hawari Rahman <hawari.rahma...@gmail.com>
wrote:

> Is there something that I need to address in the previous code snippet?

It's necessary to analyze and understand the code to figure out if adding
concurrency makes sense. Just running many tasks in goroutines does not per
se guarantee any improvements. Actually it can be the opposite.

Later you wrote that all of the goroutines access a DB. It's possible that
some/all DB methods do lock the DB. So only one goroutine at a time can
actually do something useful. The code is then essentially serial and
adding many goroutines to execute it just adds scheduling and communication
overhead for no good reason.

Also, even where concurrency makes sense, launching too many goroutines can
make things again worse. Only benchmarks can tell for sure, but often the
right number of workers is roughly the same as the number of CPU cores
available.

-- 

-j

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to