Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

How much cpu does your server use when it's polling those 1000 connections?

I ask, because think that you may be misinterpreting the results of your profiling.

What the profiling shows is that your program is spending 56% of elapsed wall-clock time in the can_read() call, but so what? You are not using a timeout value, which means that if there is nothing to do, no input to read, then that call waits until there is. What else would you have it do?

Unless you are thrashing your cpu, that is probably exactly where you want it to wait whilst there is nothing to do so that it is instantly read to roll as soon as there is.

If you are thrashing the cpu that is a different matter, but that is not reflected or demonstrated in the profiler output.

In that case, it may be that the implementation of IO::Select or the underlying calls on your system is such that whilst there is nothing avialable to read, it sits in a tight loop--like cartoon kids on a road trip:Are we there yet? Are we there yet? Are we there yet?--, and that is the cause of the thrashing.

In that case, it might be better to add a timeout to the can_read() call and explicitly sleep a little if there is nothing to do.

sub ckSockets { ... CHECK: my @breadys = $io_select_obj->can_read( 0.01 ); unless( @breadys ) { usleep( 0.1 ); ## See Time::HiRes ## Or select undef, undef, undef, 0.1; ## but that might be a "busy loop" also. goto CHECK; } ... }

But, unless you are experiencing high cpu loads when there is little or no traffic, then can_read() is exactly the right place for you program to spend most of it's time whilst it waits for something to do. Good on you for profiling, but be sure you are interpreting the results correctly.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Socket IO with large (>1000) numbers of open sockets by BrowserUk
in thread Socket IO with large (>1000) numbers of open sockets by Ray Smith

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-25 13:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found