Title: RE: [JAVA3D] Multi User Server

That helped an awful lot, along with sychronizing most of the run() method as suggested in Ole's message.

I'm now able to run 1000+ entities (monsters, each is a thread) at a 200ms frame duration (5 movement or state updates per second), with no messages getting discarded. 

Without wrapping the add and notify in a synchronized() block, I was getting array out of bounds exceptions when removing values... and was my biggest problem.

It's only using about 3% CPU (single processor 1GHz P3).

I also discovered that with 1000 entities (threads), the max queue size before discarding low priority messages needed to be pretty high.  1000 message generating threads, waking up five times a second, will run the queue up into the thousands very quickly, but the run() method keeps up just fine.  Makes me wonder if Vector() is the right way to go, since I've read Vectors are better with smaller dynamic arrays.

Again, this is with zero clients connected, so nothing is really being done except adding to the queue, and popping the values back off, but this is a huge step from handling 200 or so at the most.

Thanks for the help guys!

Scott

       
public void addMessage(String tempMessage, int priority){
        messageID++;
        //QUEUEMAX is set to 5,000
        //priority 1 is of highest importance, 5 lowest
        //when our queue limit is hit, discard non-essential messages like animation/emote actions,
        //small movements, etc.

        if (outgoingMessages.size()<QUEUEMAX || priority<3){
                synchronized(outgoingMessages){
                        outgoingMessages.add(tempMessage);
                        outgoingMessages.notify();
                        }
        }else{
                discards++;
        }
}


//and in the run method...
while (running){
                        //if the message queue is empty, wait.
                        if (outgoingMessages.size()==0){
                                synchronized(outgoingMessages){
                                        try{
                                                outgoingMessages.wait();
                                        }
                                        catch(InterruptedException ie){} 
                                }
                        }

                        //get oldest message

                        synchronized(outgoingMessages){
                                message=(String) outgoingMessages.get(0);
                                outgoingMessages.remove(message);
                                for (int i=0;i<server.clients.size();i++){
                                        tempThread=(VPServerThread) server.clients.get(i);
                                        //do range checking here too.
                                        if (tempThread!=null && tempThread.ready==true){
                                                //this will be a blocking call most likely
                                                tempThread.sendData(message);
                                        }
                                }
                        }
       
                       
                }

-----Original Message-----
From: Hubinette Per [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 06, 2002 5:19 AM
To: [EMAIL PROTECTED]
Subject: Re: [JAVA3D] Multi User Server


This is the  way to go I think but you need to wait and notify on the queue as well as have synchronized blocks.
Be sure that your queue is thread safe (Vector or some synchronized Set,Map). Don't use thread priority this is not well specified for the JVM. You don't have any control over how the thread priority will work.

/** Thread that sends all message to the clients */
public void run() {

  if(queue.size() == 0) {
    synchronized(queue){
        try{
          queue.wait();
        }
        catch(InterruptedException ie){} 
    }
   }
   message = queue.dequeue();
   proccessMessage(message);
}

public void sendToClients(Message message) {
  queue.enqueue(message);
  synchronized(queue){
        queue.notifyAll();
  }
}

-Per

-----Original Message-----
From: Brad Christiansen [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 06, 2002 3:56 AM
To: [EMAIL PROTECTED]
Subject: Re: [JAVA3D] Multi User Server


Hi,

I am not sure I understand your issue completely, but for the following
issue:

>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:

Have you tried something along these lines ?

/** Thread that sends all message to the clients */
public void run() {

  if(queue.size() == 0) {
    wait();
  }
  message = queue.dequeue();
  proccessMessage(message);
}

/** method used to add items to the queue */
public void sendToClients(Message message) {
  queue.enqueue(message);
  notifyAll();
}


Cheers,

Brad


----------------------------------------------------------------------------
This Email may contain confidential and/or privileged information and is
intended solely for the addressee(s) named. If you have received this
information in error, or are advised that you have been posted this Email by
accident, please notify the sender by return Email, do not redistribute it,
delete the Email and keep no copies.
----------------------------------------------------------------------------

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

==========================================================================To unsubscribe, send email to [EMAIL PROTECTED] and include in the body

of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to