rapier1 has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a nonforking blockign server that is making use of IO::Select's can_read function. Specifcially:
foreach $client ($select->can_read(0)) { dostuff }
When I run top the memory usage on this script approaches 98% which seems a little excessive to me. I'm starting to think this is having some negative effects on the functionality of the server. Does it? Should I be concerned? Are there alternatives? All the examples of a nonforking server I've seen use can_read.

Also, who do I have to kill to keep this text from being centered? It makes it difficult as hell to read the code.

Replies are listed 'Best First'.
Re: IO::Select Memory Hog?
by kjherron (Pilgrim) on Aug 23, 2001 at 23:56 UTC
    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.

      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.
Re: IO::Select Memory Hog?
by rapier1 (Novice) on Aug 23, 2001 at 23:20 UTC
    s/memory/cpu/g

    I am a dork sometimes...

Re: IO::Select Memory Hog?
by jlongino (Parson) on Aug 24, 2001 at 08:14 UTC
    As for the centering, I understand that it is because you are using IE 6.0. You might want to go back a version or switch to NS. I read about it somewhere on this site but can't find it via search.

    Update: Check the node Re: Everything is centered.

    If the code and the comments disagree, then both are probably wrong. -- Norm Schryer