Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: choosing threads

by gone2015 (Deacon)
on Feb 19, 2009 at 18:55 UTC ( [id://745160] : note . print w/replies, xml ) Need Help??

in reply to choosing threads

Threads will give you two things: (a) the ability to use multiple processors -- but in this case I guess you're pretty much I/O bound; (b) a way of running complicated processing separately in each thread -- with the state of the processing held implicitly in where you are in the code.

For simply reading files and throwing them into sockets, it may be more straightforward to use non-blocking I/O and a select loop. I'd maintain a (large-ish) buffer for each socket, and each time I could write something I'd do a non-blocking file read to top up the buffer -- the assumption being that file I/O will easily outrun socket I/O (assuming they aren't intra-machine sockets).

Mind you, I believe select only works on sockets under Windows -- but I'm damned if I can find a reference for that. So there you'd have to use a time-out or something if one of the socket buffers were ever to empty.

Also, is 100 input files and 100 output sockets a lot of file handles ?

I suppose you could compromise and fork 4 or 8 processes...