|Don't ask to ask, just ask|
Re^2: Help designing a threaded serviceby Tommy (Chaplain)
|on Jan 24, 2014 at 01:18 UTC ( #1071860=note: print w/replies, xml )||Need Help??|
*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.
A mistake can be valuable or costly, depending on how faithfully you pursue correction
In Section Seekers of Perl Wisdom