carbon icon indicating copy to clipboard operation
carbon copied to clipboard

carbon-cache processes not binding to unique cpu cores

Open mwtzzz-zz opened this issue 9 years ago • 8 comments

My understanding is that if I launch multiple carbon-cache processes, each one is supposed to bind to a different CPU core. But this is not the behavior I am seeing. I've got an 8-core machine and I'm launching six carbon-cache processes from daemontools with --nodaemon --instance=start

If I examine the cpu affinity of each processes, I see there is no specific affinity: [root@ec2- radar122 ~]$ taskset -a -p 15026 pid 15026's current affinity mask: ff pid 15044's current affinity mask: ff

If I run top to see which core this particular process and its threads are running on, I see that which core it's on varies through time, meaning that the process is getting scheduled on different cores. After launching top press [f j Enter]: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ P COMMAND
15044 xad 20 0 366m 194m 6360 S 57.6 0.3 34538:51 7 python
15026 xad 20 0 366m 194m 6360 R 19.6 0.3 8865:57 2 python

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ P COMMAND
15044 xad 20 0 366m 194m 6360 S 38.8 0.3 34539:30 4 python
15026 xad 20 0 366m 194m 6360 R 18.6 0.3 8866:08 5 python

In the above screenshot, first you see it running on cores 7 and 2. Then a couple seconds later it is on cores 4 and 5.

I do not see a performance problem as a result of this in my own setup, but it would suggest that the documentation is misleading. Unless I'm missing something, it seems that if I want a particular carbon-cache process to be bound to a specific cpu core, I must set it manually using "taskset". Is this accurate, or is graphite supposed to do it automatically?

mwtzzz-zz avatar May 12 '17 16:05 mwtzzz-zz

It is not supposed to bind to a specific core. Where in documentation did you read that?

piotr1212 avatar May 12 '17 16:05 piotr1212

Indeed. Carbon not doing anything specific with the process, it's completely relying on OS. Not sure why binding to a specific core is also needed at all...

deniszh avatar May 12 '17 17:05 deniszh

I don't think he was saying that it was in the graphite doc, more like that python is expected to do this by default, though as the web mentions, you are not guaranteed that it will take a free thread by default.

He is however asking something that I have been wondering for a fair few years, that is: Is there any benefit to set cpu affinity for each python daemon you start? My use case here is effectively 24 threads, and I currently run 12 caches and 6 relays on a given box, leaving enough room for mod_wsgi to breathe when serving queries.

frlinux avatar May 12 '17 17:05 frlinux

IIRC there are(/were) some Sun Sparc systems which have "CPU boards" with each board having it's own memory. CPU's can access all memory in its system but access to memory on its own board is faster. On these kind of systems it would make sense to stick a process on a CPU so that memory access is faster. I also can imagine that binding on a core would make hyperthreading (if enabled) more efficient. I don't think this would actually be noticeable, just let the OS decide on which core it should run.

piotr1212 avatar May 12 '17 17:05 piotr1212

On page 32 of "Monitoring with Graphite" (Jason Dixon), it says "each carbon-cache binds to its own CPU core, so it's easy to track down an overworked cache process."

mwtzzz-zz avatar May 15 '17 15:05 mwtzzz-zz

The full sentence follows: "Each “cache” binds to its own CPU core, so it’s easy to track down an overworked cache process with simple UNIX tools like top or ps." which is, in general, true, but not always formally true. @obfuscurity ?

deniszh avatar May 15 '17 15:05 deniszh

Yeah it wasn't my intent to imply that a core would stay with the same core, only that each would run on their own (thus making it easy to differentiate between them by workload).

obfuscurity avatar May 15 '17 15:05 obfuscurity

Ok got it, thanks for the clarification.

mwtzzz-zz avatar May 15 '17 15:05 mwtzzz-zz