in reply to Can I/O operations on the same IO::Socket be executed in different threads?
Excellent thread you refer-to ... everyone should read it carefully all the way through. (I just tossed-out a bunch of up-votes.)
There is one classic design for working with multiple sockets: a select-loop, which polls a list of sockets to find out which one(s) have data, managed by one thread, which acts as the incoming and outgoing gatekeeper for the entire system. This design works extremely well, and there are plenty of CPAN modules out there which already implement all of it.
Network I/O is a comparatively slow operation, so there is plenty of time, even with many sockets to tend. But there’s also one other important consideration: the need to track the state of the external systems with which you are communicating. If a single thread is pulling off a sequential stream of messages from multiple sockets, there will never be any timing issues. That one thread, with simple FSM = Finite-State Machine logic, can keep track of them all, and can do whatever protocol exchanges are needed. Meanwhile, the worker threads, who are listening and writing to thread-safe queues populated by the gatekeeper, need have no such concerns.
Replies are listed 'Best First'. | |
---|---|
Re^2: Can I/O operations on the same IO::Socket be executed in different threads?
by eyepopslikeamosquito (Archbishop) on May 12, 2015 at 12:44 UTC | |
by locked_user sundialsvc4 (Abbot) on May 12, 2015 at 20:38 UTC | |
Re^2: Can I/O operations on the same IO::Socket be executed in different threads?
by BrowserUk (Patriarch) on May 12, 2015 at 12:15 UTC |