<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    On 03/13/2012 05:50 AM, Peng Xiao -X (penxiao - Digital China at
    Cisco) wrote:
    <blockquote
cite="mid:776373CB9C5EA544A476052F49F1DAE202877BB4@XMB-HKG-41B.cisco.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      <meta name="Generator" content="Microsoft Word 14 (filtered
        medium)">
      <style><!--
/* Font Definitions */
@font-face
        {font-family:&#23435;&#20307;;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:&#40657;&#20307;;
        panose-1:2 1 6 9 6 1 1 1 1 1;}
@font-face
        {font-family:&#40657;&#20307;;
        panose-1:2 1 6 9 6 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@&#23435;&#20307;";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"\@&#40657;&#20307;";
        panose-1:2 1 6 9 6 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        text-align:justify;
        text-justify:inter-ideograph;
        font-size:10.5pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
/* Page Definitions */
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal"><span lang="EN-US">Hi experts,<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">I wrote a TCP client
            program used twisted to receive lots of data from the server
            and decode them for analysis.<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">But the efficiency is
            ugly.<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">I used<b><span
                style="color:red"> &#8220;profile&#8221; and &#8220;pstats&#8221; </span></b>to
            analysis and found <b><span style="color:red">selectreactor.py</span></b>
            is time consuming.<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">what is <b><span
                style="color:red">selectreactor.py</span></b> used for?<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">How can I improve that?
            <o:p></o:p></span></p>
        <br>
      </div>
    </blockquote>
    selectreactor is the core event loop; it waits for events to happen
    and calls other code.<br>
    <br>
    In general, if you have many connections (hundreds or thousands)
    switching to the IOCP reactor on Windows, epoll on Linux, or poll on
    other Unix platforms may help (next release will also have kqueue
    support for FreeBSD). Running your application with PyPy may also
    help.<br>
    <br>
    It may also be, though, that your program is taking a long time
    because it's waiting for data to arrive, for example, and that won't
    show up in a profile because it has nothing to do with CPU time.<br>
  </body>
</html>