Another idea that came up in talking to Bulat that I've been thinking about for a while: How do we make it truly services all the way down? Right now a service not only has services, but also green threads. The original thinking was around the idea of "can we make services green threads?" But I could never make this work conceptually in a way that made sense. After this, Bulat then suggested making the green thread pool that all services have be a service itself!
But wait, then you'd have to add a PoolService or something like that to every Service... well no, we know the common case is having one. So the idea was to create a more basic service called BasicService that implements just the service protocol (start/stop/etc). Then Service would always add a child service that would manage your green threads. That service would inherit from BasicService (as it would not need a pool).
Containers would also be based on BasicService instead of Service.
What's more, this also solves the problem I've been thinking about how to abstract the concurrency system. Wouldn't it be great if gservice (Ginkgo?) not only worked with gevent, but eventlet? More importantly, also work with regular threads? But then ALSO: processes (more on this in a bit).
AsyncManager would be a generic interface to concurrency/async primitives. It would own spawn, spawn_later, but also sleep, and factories for coordination primitives (events, queues, locks, etc). Service would forward calls to self.spawn, self.spawn_later to it. Otherwise you would use self.async.(whatever).
This in theory you could mix and match services with different concurrency systems! Although different event loops would be more of a challenge (maybe just running them in different threads), mixing threads, green threads, and processes would be kind of nice and relatively easy.
By default, a Service will use an AsyncManager that will try to use green threads using gevent, eventlet, or raw greenlets, then if none of those exist, it will use real threads. It can also use proceses. And you can always force a service to use any of them.
--
Jeff Lindsay
http://progrium.com