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

Re^2: Help designing a threaded service

by Tommy (Chaplain)
on Jan 24, 2014 at 01:18 UTC ( #1071860=note: print w/replies, xml ) Need Help??


in reply to Re: Help designing a threaded service
in thread Help designing a threaded service

*Grins widely* ...

Why you ask would I design it this way? Because I'm planning something evil: IE6 support. And here's the convoluted setup which I wanted to just keep segmented for simplicity's sake, but here we go:

I have a catalyst web app serving a number of people. The app polls the server using jQuery XMLHTTP (AJAX) every N seconds (usually 2) with a task ID. I have scrolling text panes to show the output of the tasks.

The problem which I must solve is how to get this streaming data from remote server C, while catalyst server B answers AJAX requests from client A. It's a polling system, where the browser sends a request to the catalyst server which then contacts the listening service for either initiation of long running SSH commands, or for content updates

WEBSOCKETS WOULD BE BETTER, but I'm supporting IE6 and 7 here. And I also can't have users in browsers hitting the more private daemon that's doing the remote SSH commands. In this situation, the catalyst app acts as a firewall for it and only sends "trusted" commands based on sanitized user input.

Now to clarify one thing I may have miscommunicated: each client connection does NOT go to the master thread. The sole responsibility of the master thread is to enforce timeouts on running tasks. "Listener" threads will be responsible for taking connections, looking up the running tasks in a shared hashref, opening the queue for task ID foo, spewing the update via ->dequeue() to the client, and hanging up. Then catalyst sends the updated data back to the web client in a well-formed AJAX response which gets populated into the scrolling faux terminal windows in the browser.

The idea is that the browser window is divided into panes which form a dashboard. Each pane scrolls different server health/activity statistics (IO/CPU/Network/Memory). Above all that will be a moving line graph using google charts or the like. It's a grand scheme, but the hard part is the back end plumbing that I'm trying to create. The front-end stuff is easy.

Tommy
A mistake can be valuable or costly, depending on how faithfully you pursue correction
  • Comment on Re^2: Help designing a threaded service

Replies are listed 'Best First'.
Re^3: Help designing a threaded service
by BrowserUk (Patriarch) on Jan 24, 2014 at 04:00 UTC
    "Listener" threads will be responsible for taking connections,

    "Listener threads". Plural? On different ports?


    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.

      So I sheepishly take it from your reply that I can't have a multi-threaded listener setup the way I see multiple forks of a fork-based network server taking connections on one port. I had some proof-of-concept code barely forming last night but hadn't got far enough to find out if it "worked"...Thanks for saving me the trouble.

      A I wrong in my understanding that in either case it seems like there is still one listening "doorman" who hands off the business of respond()-ing to his subservients?

      The more I think about this, the more I'm leaning toward going with Net::Server and using some other way to share data between its forks than the much more (imo) elegant shared variables via threads::shared. I've used it many times and it's soooo stable. I just really didn't want to do it that way.

      Tommy
      A mistake can be valuable or costly, depending on how faithfully you pursue correction
        I sheepishly take it from your reply that I can't have a multi-threaded listener setup the way I see multiple forks of a fork-based network server taking connections on one port.

        No. It is entirely feasible to do. Its just a completely ridiculous way to design a server.

        With forks (*nix), when you have multiple processes all waiting to accept on a shared socket, when a client connects, *every* listening process receives the connect.

        It is obviously a nonsense to have multiple server processes attempting to conduct concurrent communications with a single client, so now those multiple server processes need to arbitrate between themselves in order to decide which of them will pick up the phone.

        Envisage an office with a shared extension and a dozen bored people all shouting "I'll get it!" at the top of their voices ... or all of them pretending not to hear it hoping someone else will be bugged out by the constant ringing and answer it before they weaken and do so.

        In *nix server land the solution is for all of the listening processes to fight over acquiring a global mutex. One wins; and the other go back to whatever they were doing before they were so rudely interrupted.

        Of course, in your scenario, if the client calling back to collect his output happens to randomly connect to a different process to the one that he connected to when he made his hostname/command request -- an odds on favorite scenario -- then he's sh*t outta luck; cos that process has no way of knowing that one of the other processes is gathering output for this client.

        You wanna do thing the st hard way; have fun.......


        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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2022-11-28 17:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?