I might even keep your "sleep" so that my server processes expire every so often as a memory-leak counter-measure.)

You'll probably want to set to something less than 31 years then :)

I expect somewhere between 1 and 100 simultaneous clients. Each connection should last no more than 1sec with 10k+ queries.

Then I'd go for a thread pool server something like this (again, a cut down version of pre-existing test code, not a production ready code):

#! perl -slw use strict; use threads; use Thread::Queue; use IO::Socket; use constant { SERVERIP => '127.0.0.1', SERVERPORT => 3000, MAXBUF => 4096, }; our $R //= 8; sub s2S{ my( $p, $h ) = sockaddr_in( $_[0] ); $h = inet_ntoa( $h ); "$h:$p"; } my %DB :shared; chomp, $DB{ $_ } = $. while <>; close *ARGV; my $Q = new Thread::Queue; my $Qcleanup = new Thread::Queue; sub responder { my $tid = threads->tid; while( my $fileno = $Q->dequeue() ) { print "[$tid] Servicing fileno: $fileno"; open my $client, '+<&=', $fileno or die $!; bless $client, 'IO::Socket::INET'; while( 1 ) { $client->recv( my $in, MAXBUF ); unless( length $in ) { print "Disconnected from ", s2S $client->peername; shutdown $client, 2; close $client; $Qcleanup->enqueue( $fileno ); last; }; print "Received $in from ", s2S $client->peername; my( $cmd, @args ) = split ' ', $in; if( $cmd eq 'FETCH' ) { $client->send( $DB{ $args[ 0 ] } ); } else { $client->send( 'Bad command' ); } } } } threads->create( \&responder )->detach for 1 .. $R; my $lsn = IO::Socket::INET->new( LocalHost => SERVERIP, LocalPort => SERVERPORT, Reuse => 1, Listen + => SOMAXCONN ) or die $!; my @clients; print "Listening..."; while( my $client = $lsn->accept ) { my $fileno = fileno( $client ); $clients[ $fileno ] = $client; print "[0] queing ", $fileno; $Q->enqueue( $fileno ); close $clients[ $Qcleanup->dequeue ] while $Qcleanup->pending; }

In a test running 8 responders, it served 1000 responses to each of 100 concurrent clients and achieved an average response time at the clients of 0.002 seconds.

That's clients and server running in the same box so no network latency. But on the other hand, that's 8 server threads and 100 client threads all running in the same box which will obviously adversely affect server responsiveness.

Here's a graph of its response times using 8 threads to respond to 16, 32, 64, 100, & 128 concurrent clients.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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.

The start of some sanity?


In reply to Re^3: Bid data but need fast response time by BrowserUk
in thread Bid data but need fast response time by Anonymous Monk

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.