Hello everybody

I would like to code a TCP server that has to accept socket connections from more than 2'000 clients. The clients would perform some sort of FTP-like communication, i.e. Request-Reply-Request-Reply-...

The connections would be let established for the whole FTP-like communication, which can last for several hours.

The problem: Currently I am forking the server foreach new accepted client (standard way to allow the parent to listen again immediately). But using this approach, I will duplicate the perl script (server) and thus the memory usage would increase. Say the server script needs 5MB, and let there be 10 concurrent clients. Then the memory usage would be already 50MB (+5MB for the parent). Is there a better approach to minimize the memory usage?

Are there any tutorials and/or good books out there that cover this problem? The communication I am trying to implement is a little bit more tricky than simple FTP. After the connection is established, both, the server and the client, can send requests.

My implementation: In a loop, I use the method can_read(1) from the module Select on the socket to check if there is new data (a request or maybe a reply) to be processed. If there is, I will read the data and invoke a script that handles the data (depending on whether it is a request or a reply). If not, I will search in a specified directory for text-files (created by other scripts) that can be sent through the socket. The content of the text-files is either a reply or a request. Then I will sleep for 1 second. and restart the loop.

Any suggestions how I could improve this complicated communication?

Thanks for your answer(s)
Adrian


In reply to TCP Socket, Forking, Memory exhaustion by asuter

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.