[Haskell-cafe] Optimizing a high-traffic network architecture

Bulat Ziganshin bulatz at HotPOP.com
Wed Dec 14 13:06:38 EST 2005


Hello Joel,

Wednesday, December 14, 2005, 7:55:36 PM, you wrote:

JR> In my current architecture I launch a two threads per socket where
JR> the socket reader places results in a TMVar and the socket writer  
JR> takes input from a TChan.

as i already said, you can write to socket directly in your worker
thread

JR> I also have the worker thread the does the  
JR> bulk of packet processing and a timer thread. The time thread sleeps  
JR> for a few minutes and exits after posting a timeout event if it  
JR> hasn't been killed before.

you can use just one timeouts thread for all your bots. if this
timeout is constant across program run, then this thread will be very
simple - just: 

1) read from Chan (yes, it is the case where using of Chan wll be appropriate! ;)
2) wait until 9 or so minutes from the time when this message was sent
3) send kill signal to the thread mentioned in message

so, you will had only 2 threads. you can then try to play with
conbinating socket reading and TMVar reading in one thread (btw, try
to replace TMVar with MVar - may be, it will be better?). or, you can
try to create one sockets reading thread, which will service all sockets.
may be, this can be somewhat done with help of select() system call?
it is a more "right way", but i don't know how this can be
accomplished

-- 
Best regards,
 Bulat                            mailto:bulatz at HotPOP.com





More information about the Haskell-Cafe mailing list