I'm working on an alternative asynchronous library - reactor.nim. reactor.nim is an asynchronous networking engine for Nim. It's based on libuv and provides future-based API.
reactor.nim doesn't use asynchronous mechanisms from asyncdispatch stdlib module and instead provides its own. They are arguably richer and more performant. The API is inspired by Dart and Midori OS. In particular, it's IO is centered around buffered stream, which allow most reads and writes to complete without any allocations (or "context-switches").
You can grab it from https://github.com/zielmicha/reactor.nim or using Nimble. Relatively sparse documentation is hosted on https://networkos.net/nim/reactor.nim/doc/. Currently it works only on Linux and Mac OSX, but thanks to libuv porting it to Windows will be trivial.
Wow, that looks great!
I see there is a reactor/threading module. How does the event loop interact with threads?
I am currently working on Rosencrantz, a DSL to write HTTP servers, which is currently based on the standard async packages, and as such is single threaded. Performance is not bad, but if Reactor allows to delegate the responding of requests on worker threads, I would be very much interested in porting Rosencrantz on top of it
Currently, reactor/threading can only execute tasks that don't use event loop at all. When the task is finished, the result is deep-copied to main thread.
Anyway, probably the best way to parallelize web servers is to spawn multiple processes and send socket file descriptors to them. There is some cross-platform support for that in reactor/ipc, but it needs polishing and more features.
Do you think one of these approaches might work in some way with Reactor?
andrea,
You could try to setup server sockets from multiple threads with SO_REUSEPORT|SO_REUSEADDR flags, instead of having single server socket in the main thread. That way, different threds may accept connections on the same address/port pair, while OS tries to evenly distribute load between them.