in reply to Help designing a threaded service
What you've described sounds eminently doable. Though I'm going to question a couple of things and I'd probably make a few adjustments.
Constantly re-making connections is a costly affair. That why http (web) servers went over to persistent connections.
Why not let the client continue to listen and just send it data as it arrives from the remote system?
Or perhaps better would be for the client to open a local UDP port and once it has communicated the hostname/command pair/and port number to the service it just sits back and monitors the UDP port to retrieve the output.
I guess this is because you envisage the client re-connecting to the servers primary thread to retrieve the output and so you need accumulate the data in a shared structure so the primary thread can get access to it.
It think this is a bad design. You are making it so that your primary thread has to be involved in all data retrieval by every client; thus setting yourself up with a bottleneck. It also complicates the processing, by requiring shared data structures and uses more memory because shared data is duplicated.
I think -- without being fully aware of your requirements -- that a better design would be to have the primary (listening) thread start dedicated thread(s) (one or two depending upon the answer to the above) for each client/command and accumulate the buffered output entirely local to that (those) threads.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Help designing a threaded service
by Tommy (Chaplain) on Jan 24, 2014 at 01:18 UTC | |
by BrowserUk (Patriarch) on Jan 24, 2014 at 04:00 UTC | |
by Tommy (Chaplain) on Jan 25, 2014 at 04:34 UTC | |
by BrowserUk (Patriarch) on Jan 25, 2014 at 05:32 UTC | |
by zwon (Abbot) on Jan 26, 2014 at 15:42 UTC | |
| |
by Tommy (Chaplain) on Jan 26, 2014 at 20:08 UTC | |
|