I certainly won't claim to know, but I'm working on
it, and learning a few things through trial and error. But I thought
I'd join in on this to add a more specific question...
The server I've built for our MMORPG so far can
easily handle (at this point) over 200 server-controlled "monster" entities,
each in it's own thread, each checking for nearby players, and roaming about the
terrain if nobody is around to attack. Their thread runs every 250ms
(although I'd like to get that down to every 100ms). All
client/server comms is done via TCP right now.
We've had up to 20 people connected at once with no
real performance issues (in fact the CPU utilization on a dual 500Mhz PIII never
passed 3%). Each player connection also gets its own thread. This
thread handles incoming and outgoing messages, processing of the incoming
messages (chat, movement, joining/authentication, disconnecting, attacking,
emotes, etc).
Messages that then need to be sent to others are
handled by iterating through all the nearby clients, and calling that client
threads' SendMessage method. That's a potential blocking problem I see,
when a client thread is too busy handling messages handed to it from other
processes, to handle it's own messages. But, of course, the socket we need
to talk to is in that thread, so we have to call that method, right? (Or course
UDP might be the answer here, for low priority messages).
The server-controlled entities
(monsters,NPC,etc) add messages, like moving, attacking, etc, to be
sent to all nearby players by putting messages into a queue (a Vector at this
point).
Another thread handles sending these queued
messages to players within range of a message origination, in a FIFO
order. That particular thread I'm having some problems with. I need
it to run all the time, or "wake up" whenver the message queue isn't
empty. If the queue _is_ empty, I want it to sleep quietly. I've
played around with thread priority, and that seems to make no difference.
I can't seem to get it to either:
1) Keep up with the message queue, so messages get
stacked up and I start to drop them, according to their priority,
or
2) Not have CPU utilization to jump to 100% (in
which case it keeps up fine).
And note that this happens with no clients
connected, so we're not blocking on socket communications...
It seems to me that message "queues" are a good way
for threads to hand off a task, like processing movement messages, to
another thread without holding it up., but in the first case, even when the
message handler is falling behind, CPU use never passes 1% for Java.
Getting the thread queue that's processing those messages to have enough CPU time, when it's
needed, to handle them as they come in, but not run at 100% CPU use is killing
me...
Scott
----- Original Message -----
|
- [JAVA3D] Multi User Server Sharon Lin
- Re: [JAVA3D] Multi User Server Scott
- Re: [JAVA3D] Multi User Server Brad Christiansen
- Re: [JAVA3D] Multi User Server Hubinette Per
- Re: [JAVA3D] Multi User Server Smith, Daniel