Nathan Fenenga Yospe (yospe@Hawaii.Edu) wrote:
: Thread Player Socket:
: Start
: Wait for Connect
: Pick up
: Spawn new thread for next connect
: loop
: when input, load to buffer
: when output, flush (provision for delayed flush here)
: end
: (This thread sends message and terminates when the main process dies)
Have you looked at using an asynchronous model for handling your
connection threads? Allocating one thread per connection can get
expensive when the total number of connections gets large (say 500
simultaneous players).
I have a thread pool here that as a unit manages the IO from a much
larger set of connections. Essentially all the threads block until
there is IO to serve. Threads are assigned to IO on a first-available
basis, and then de-assigned as soon as the IO is compleated. This
allows (in very crude tests) a rough ratio of 1:20 threads per active
socket while still maintaining good response rates (you could also put
in a balancing algorithm which grows/shrinks the thread pool in
response to loading).
--
J C Lawrence Internet: coder@ibm.net
---------------(*) Internet: clawrenc@cup.hp.com
...Honorary Member Clan McFUD -- Teamer's Avenging Monolith...