Re: Using too many threads?



Alex Taylor wrote:
On Sat, 4 Jul 2009 16:11:15 UTC, Steven Levine <steve53@xxxxxxxxxxxxxxxxxxx> wrote:
I would have to guess you are using non-blocking sockets. If you have a
socket per thread there's no reason not to block. The only downside to
blocking sockets is that it takes a bit more work to ensure an app will
always shut down quickly and cleanly, when requested.

Correct. I originally planned to use blocking sockets, but quickly discovered that wasn't going to work.

And now you discovered that non-blocking sockets will not work too. It is nearly impossible to limit the CPU usage without an impact on the throughput.

The Ui thread has to be able to send messages to the thread that talks on
the socket, so commands can be sent to the client at the other end on demand.

I also need to take certain actions at specific intervals (for instance,
send a refresh command to the remote client every 5 seconds), and if the
loop only iterates every time data comes in, that timing gets thrown out
the window.

You can use select with a timeout to implement the refresh command. Furthermore sending commands to the same socket from another thread is safe as long as it is done mutual exclusive to send operations of the other threads. Of course you must also ensure the protocol integrity.
If a delay of 5 Seconds is okay you may also check for asynchronous UI commands by the time. A command queue would be helpful.


Marcel
.



Relevant Pages

  • Re: FTP client. Error "bad address"
    ... Then client ask for a connection to this IP in port ... Open a socket with socketfunction ... that you use the same address in the PORT command as was used to connect ... Some FTP servers will reject PORT commands that contain ...
    (comp.unix.programmer)
  • Re: How to remote-control a Java app?
    ... program in a client machine. ... whether it accepts commands via a socket or via COM. ... depends on the definition of server. ...
    (comp.lang.java.programmer)
  • Re: Sharing C commands across threads
    ... I want to pass the device commands to ... My model is the classic multi-threaded socket server. ... devices instead of socket connections, ...
    (comp.lang.tcl)
  • Re: creating single-instance executables using python/py2exe
    ... You could open a listening socket to listen for "open file" commands. ... The problem with the world is stupidity. ...
    (comp.lang.python)
  • Re: Question about non-blocking NIO and Selection Keys
    ... around blocking sockets, and without a complete re-write it's hard to ... because we need to support the case where the client can ... asynchronously send a message to the server telling it to stop sending ... socket, and is now scattered across 10s of thousands of lines of code ...
    (comp.lang.java.programmer)

Loading