English 中文(简体)
minimum work size of a goroutine [closed]
原标题:
Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 5 years ago.

Does anyone know approximately what the minimum work size is needed in order for a goroutine to be beneficial (assuming that there are free cores for the work to be offloaded to)?

问题回答

I ve been plodding through project euler with Go. While I don t have a definite answer for you I found the goroutine-based primality sieve in the Go docs to be an order of magnitude slower than simply checking each number for primality. Setting GOMAXPROCS to a higher value didn t help, either.

goroutine is an abstraction that you use if it helps you model your application better. You re doing concurrency oriented programming, so think about the parts of your application that have concurrency within them.

Think about an OO system and imagine asking the same question about whether you should instantiate an object.

Do the thing that makes sense first.

Using goroutines isn t just about hardware efficiency. Sometimes they make the software easier to write and make it easier to keep bugs out. The language allows the programmer to express concurrency naturally and simply. That s worth a lot to me.

My own experience with problems that are natural candidates for concurrency is that go easily allows me to max out all the available cores on CPU bound problems using a trivial "scatter/gather" approach. Your mileage may vary.

Hotei

goroutines are lightweight and don t take up much resources. You should use them where ever it is appropriate to the problem. Currently go doesn t seem to be exceptionally good at using multiple cores (it seems there is a bit too much overhead in allocating additional host threads.)

I think the real question is when to use multiple cores rather than when to use goroutines. The answer to that is probably the same as for other languages and additional host processes. (Unfortunately you can t easily specify when a goroutine should occupy a new host process or which process it should occupy.)





相关问题
OutOfMemoryException on MemoryStream writing

I have a little sample application I was working on trying to get some of the new .Net 4.0 Parallel Extensions going (they are very nice). I m running into a (probably really stupid) problem with an ...

Master-Slave Pattern for Distributed Environment

Currently we have a batch driven process at work which runs every 15 mins and everytime it runs it repeats this cycle several times: Calls a sproc and get some data back from the DB Process the data ...

How to use database server for distributed job scheduling?

I have around 100 computers and few workers on each of them. The already connect to a central database to query for job parameters. Now I have to do job scheduling for them. One job for one worker ...

minimum work size of a goroutine [closed]

Does anyone know approximately what the minimum work size is needed in order for a goroutine to be beneficial (assuming that there are free cores for the work to be offloaded to)?

Optimal number of threads per core

Let s say I have a 4-core CPU, and I want to run some process in the minimum amount of time. The process is ideally parallelizable, so I can run chunks of it on an infinite number of threads and each ...

What s the quickest way to parallelize code?

I have an image processing routine that I believe could be made very parallel very quickly. Each pixel needs to have roughly 2k operations done on it in a way that doesn t depend on the operations ...

how to efficiently apply a medium-weight function in parallel

I m looking to map a modestly-expensive function onto a large lazy seq in parallel. pmap is great but i m loosing to much to context switching. I think I need to increase the size of the chunk of work ...

热门标签