in reply to IO::Select Memory Hog?

s/memory/cpu/ noted...

The loop you show looks fine, but you understand that can_read(0) doesn't block? It returns immediately, whether any handles are ready or not. If the surrounding code is essentially:

while(1) { foreach $client ($select->can_read(0)) { dostuff } }
then you're going to keep calling can_read() just as fast as you can, rather than truly blocking until a file handle becomes ready.

If you want can_read() to block as long as necessary, then you shouldn't pass a timeout argument. IF you need can_read() to return every so often, then you should pass some timeout other than 0. Only use 0 for the timeout if you don't want the call to block.

Replies are listed 'Best First'.
Re: Re: IO::Select Memory Hog?
by rapier1 (Novice) on Aug 24, 2001 at 21:31 UTC
    Yeah, unfortunately I need it not to block. Once it gets a client connection it has to spit out data as fast as possible. I can't fork and I can't use threads so I guess I'm entirely screwed.