0
votes

I'm a bit confused here about cores and threads on CPUs

Often in configuration files eg. nginx, golang you have to define the number of cores to get the best performance

If you look at this CPU http://ark.intel.com/products/52213/Intel-Core-i7-2600-Processor-8M-Cache-up-to-3_80-GHz

How many "cores" does it have?

In the specs it has 4 cores and 8 threads.. Does that mean 4*8 = 32 "cores" ??

1
What does this question have to with Go (the programming language)? - icza
"In the specs it has 4 cores" ... It has 4 cores... - SirDarius
regarding Go, I guess OP is wondering what runtime.NumCPU() is going to return on this CPU, hence the max value which can be passed to GOMAXPROCS. - tomasz
Please note that Go programs are not single-threaded; I mean, not even in the sense of OS threads: the Go runtime scheduler uses multiple OS threads to multiplex multiple goroutines onto them -- while trying to keep the number of used OS threads to a minimum. Its networking poller is indeed resembles libevent, nginx etc but a goroutine blocked in a non-network-related syscall occupies an OS thread, so once this happens, and there's another runnable goroutine, the scheduler will spawn another thread if possible. Consider reading this for more insight. - kostix

1 Answers

1
votes

No, the CPU you linked to has four cores. It can, however, run two threads at the same time per core with a technology called Hyper-Threading (HT), thus has 8 "threads". The OS will be presented with 8 processors, unless you disable HT in the BIOS or elsewhere.

Note that hyper threading works in a special way: It uses unused execution units (in the sense of a superscalar processor) of a core for the second thread. AFAIK there are really good algorithms that re-order instructions for this to be most effective, but bear in mind that the hyper threads may not bring the best performance for all applications. For example: if you already use all floating point execution units in the four "real" threads all the time, the hyper threads will not be able to use them most of the time.