Hi, I'm working on linux with 8-cores and am trying to decide the best way to implement multi-threading. I listen on one socket but have many many connections. The docs suggest one loop per thread. That makes sense, but there are a few options for how to distribute load between N loops/threads. I'm not sure which is best.
1. When I get a new incoming connection, I could keep track of which loop has the fewest connections and assign the connection appropriately. I think I'd have to use a mutex to lock all access to a loop's watchers. 2. I could use SO_REUSEPORT to have my accept logic operate on every loop. There'd be no mutexes, but I'd have little control over how connections are balanced between loops/threads. 3. I could establish a pipe (or socket) between the server loop and all other loops. When I get an incoming connection, I send a message (say the peer IP address & socket number) over the pipe to my other loop/thread. libev will awake and process the incoming connection as if it came directly to it. 4. Simulate a backlog for each loop - just a list of new connections to process. On accept, choose a loop, lock a mutex and add a value to the list of connections to process. On a loop's callback, lock same mutex and check for new connections to process. Could do this in a timer too instead of at every callback. Any suggestions or recommendations? Cheers, Eric
_______________________________________________ libev mailing list [email protected] http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev
