I've written a singled threaded uv_default_loop() tcp server and I am curious if there are any examples out there how to expand this to use all available cores of the server? Multiple loops? How this may be achieved?
Any advice is much appreciated.
Hi, you might want to look into using a pipe to pass the listen socket to multiple threads. You might get mileage out these two projects as examples _(disclaimer: I wrote these)_:
https://github.com/willemt/uv_multiplex
https://github.com/willemt/pearldb
I think this is what Haywire does to get multiple threads working: https://github.com/kellabyte/Haywire/blob/master/src/haywire/connection_dispatcher.c
https://github.com/kellabyte/Haywire/blob/master/src/haywire/connection_consumer.c
Closing because it's answered.
@2ix Can you use the mailing list next time? Thanks.
For completeness, if you are fine with your code working on Linux only and have a recent enough kernel (>= 3.9 IIRC) you can create the socket early with uv_tcp_init_ex, set SO_REUSEPORT, create multiple threads and let the kernel do the balancing.
Most helpful comment
For completeness, if you are fine with your code working on Linux only and have a recent enough kernel (>= 3.9 IIRC) you can create the socket early with
uv_tcp_init_ex, setSO_REUSEPORT, create multiple threads and let the kernel do the balancing.