rtrlib icon indicating copy to clipboard operation
rtrlib copied to clipboard

Handle multiple RTR connections in same thread

Open fho opened this issue 11 years ago • 4 comments

Instead of creating a separate thread for every rtr connection it's more efficient to switch to an async event-based approach to handle multiple connections from the same thread. This could be done with the help of libevent

fho avatar May 25 '14 09:05 fho

I would vote for just adding select() calls.

mceyran avatar May 25 '14 10:05 mceyran

I just gave it another thought. Since there is already a system in place that divides the RTR manager into groups containing sockets, the groups would be perfect for spawning one thread each that uses select() on its own sockets.

mceyran avatar May 25 '14 10:05 mceyran

Yes, using select() could also be sufficient. I would vote for only one thread that handles all connections including multiple manager group, it doesn't provide a benefit to have a thread for each manager group. The threads have probably only a very low load also on older CPUs

fho avatar May 29 '14 10:05 fho

In this case, the manager would have to collect all sockets from all groups, which would break separation of concerns, locality and modularity. On each return from select(), it would again have to check all sockets in all groups using FD_ISSET() etc. If the groups have been designed to manage their sockets like a black box, the manager shouldn't interfere here.

Also, having each group spawn its own thread has the advantage that thread priorities can be assigned according to the group's preference value, helping higher-priority groups' socket data to be read earlier, especially when multiple NICs are used. Users can design their RTR manager groups accordingly in this case, without having to resort to maintaining multiple RTR managers.

mceyran avatar May 29 '14 13:05 mceyran