Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Multiplexing HTTPS server, peer cert authentication problem.

by Moron (Curate)
on Mar 05, 2007 at 18:33 UTC ( [id://603260]=note: print w/replies, xml ) Need Help??


in reply to Multiplexing HTTPS server, peer cert authentication problem.

Going back to the original problem yet again, you have a daemon that accepts connections, but misses new requests while servicing the last one. Next idea is: Following the way, functionally, apache solves the same problem, you would have a master daemon that spawns eight eager daemonets all grabbing connections and being busy servicing them - not for long because they'll spawn another process to actually handle the request, e.g. Perl if a cgi program is allocated to the URL, and then go back to grabbing the next request. That way, translating back to your situation, if one daemonet is busy, there is always another one available to do the accept call. The looping required for each daemonet would be something like:
while ($request = $listen->accept()) { # handle request ... BUT ...read on }
Instead of spawning new processes to handle requests like apache does or forking or threading, the daemonets could write the request to a fifo. That way you can separate the asynchronous process of collecting and filing requests from the synchronous process of reading off the queue and servicing them - it is generally a good idea not to mix asynchronous and synchronous processing in the same process (this being what seems to be at the root of it all) - in fact that would be an oxyMoron ;)

-M

Free your mind

Replies are listed 'Best First'.
Re^2: Multiplexing HTTPS server, peer cert authentication problem.
by erroneousBollock (Curate) on Mar 06, 2007 at 01:44 UTC
    Ah, so you're talking about multiple listeners for the same socket - "bound" before the inital fork(), where only one process actually succeeds to accept() for a given incoming request ?

    Does that work with threads ? :)

    I only ask because I've looked into the magic that Threads.pm does to clone (copy) non-shared variables into new threads... specifically, that does bad things to the self-glob-ref thing that IO::Socket::SSL does internally.

    -David.
      If you are sticking with threads, you can pass objects to threads using the Thread::Queue module. In fact that is also the recommended (big Camel book) way to synchronise the handling of asynchronous requests under those circumstances, although if you use it to meet both requirements you'd need N+1 queues where N is the number of startup threads - one to synchronise requests to the request-handling synchronous daemon and one for each startup daemonet to receive object data from the initialising parent.

      And if the threads approach remains too troublesome, you could always spawn the daemonets with something like for (1..$nrDmnts) { my $pid = open my $ph, "|-" ... } instead and send them non-shared data across the pipe.

      -M

      Free your mind

        In my real server, I *am* actually using Thread::Queue::Any to farm out work to my worker threads from my multiplexing server.

        The code I posted is my (boilded down for SoPW) attempt at making my *mostly* non-blocking server *fully* non-blocking. (I see from Thelonius's suggestion that I may not have finished the job). The real server replaces the "file" code from the OP with a mechanism to send work to a Dispatcher thread which classifies the request, finds an appropriate handler class then farms the "work" out to a pool of worker threads.

        I can't actually import Threads.pm into the multiplexing server's package as some "magic" internal to Threads.pm causes crashes in IO::Socket::SSL (actually XS from Net::SSLeay).

        As for the excellently old-skool open "|blah" method of IPC, i would use it in a second (over say Thread::Queue::Any) if there was currently any problem with the IPC -- I do not believe this to be the case.

        -David.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://603260]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-03-28 17:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found