News for hackers. Stuff that matters.
Re:RethinkDB internals: handling stack overflow on custom st... by cperciva on Friday December 31, 2010 @05:10AM (#2055048)
Regarding userland threads, I don't think these guys are developing (or probably testing at this point, though I'd be glad to hear if they were) on freebsd. That's the only place I know of with something actually called "userland threads"; there are several implementations on linux by different names that accomplish the same goal, but I don't recall seeing any with that name. Which threading scheme in particular were you referring to?

I said "userland threads" to distinguish it from kernel threads, which are (as they noticed) rather expensive.

What RethinkDB really want, and seem to be headed towards, is a proper M:N threading model: Launch one kernel thread per CPU (N), then spread M userland threads between those.

Re:RethinkDB internals: handling stack overflow on custom st... by littledanehren on Saturday January 01, 2011 @06:25PM (#2058798)
Yep, that's basically what we do. User-level threads are called 'coroutines' and they're scheduled cooperatively, so they don't incur the overhead of user-level preemption. Cooperative scheduling is fine for us because we can ensure that a single coroutine won't hog the CPU or issue blocking system calls.

It'd be nice if some pthread implementation gave us what we need, but I don't think they do. They probably are too heavy an abstraction, even if implemented in user space, providing too strong guarantees for context switching and scheduling. For example, we're never going to set individual signal handlers on different coroutines, but pthreads guarantee this capability. So even user-level pthreads which don't support preemption will require a system call on context switches, just as ucontext.h's swapcontext does for similar reasons. But as Slava points out, the performance penalty is something that we need to verify in the future with benchmarks.

What would be really nice is if the OS, or at least a standard application framework usable from C++, supported this. But it doesn't, so we build our own.

Re:RethinkDB internals: handling stack overflow on custom st... by leif on Friday December 31, 2010 @05:12AM (#2055051)
Oh, I thought you were talking about one particular implementation, my mistake.

Yep, I think so too. I don't know of anything that does that on linux, sadly.

Man, I gotta dust off that freebsd partition again.

Re:RethinkDB internals: handling stack overflow on custom st... by cperciva on Friday December 31, 2010 @05:19AM (#2055061)
Man, I gotta dust off that freebsd partition again.

Just spin up a FreeBSD instance in EC2. :-)

(And while you have it running, please run your favourite stress tests and try to find bugs. I think it's starting to get decently stable now, but it needs lots more testing.)