kr/beanstalkd — Issue #96: CPU pinned calling kevent on OSX
Author: tonyarkles
Created: 2012-02-07 02:42:30+00:00
State: open

I'm trying to get Beanstalkd 1.5 running on OSX 10.6, and it seems to frequently (but not all the time) peg the CPU at close to 100%. Running dtruss against it (`sudo dtruss -s -p 55933`), I get a massive amount of these:

```
kevent(0x4, 0x0, 0x0)	= 1 0

libSystem.B.dylib`kevent+0xa
beanstalkd`srv+0x130
beanstalkd`main+0x267
beanstalkd`start+0x34
beanstalkd`0x4
```

Looking briefly at the source, it looks like the compiler might be inlining stuff into that srv() function; it doesn't call kevent() directly, but it does call sockwant() and sockmain() from sock-bsd.c, which both call kevent. I'm not sure which one it's calling here in the stack trace though.

I've reduced it to a mostly repeatable simple test case:

1. start beanstalkd
2. observe that CPU usage is quite low
3. connect beanstalkc (python) to the server: `import beanstalkc; c = beanstalkc.Connection(host='localhost', port=11300)`
4. observe that the CPU usage is still quite low
5. reserve: `c.reserve(10)`
6. before the 10 second timeout expires, CPU usage is low, and then it skyrockets after the timeout
7. `sudo dtruss -s -p ` will show the same trace output I posted above