[Spread-users] Listener performance vs. receive() performance

Jonathan Stanton jonathan at cnds.jhu.edu
Thu Feb 14 01:01:20 EST 2008

The listener interface is a nice abstraction, but has always been worse then calling 
receive directly from a performance standpoint. Maybe there is a better way to implement 
the listener model so it is also fast (and if any java users/experts out there want to 
suggest improvements I'll happily accept them). The code is mainly in the "run" method 
defined in the SpreadConnection.java file. 

I think part of the performance problem is that we call "yield" every time through the
main handling loop for listeners so that other threads can join or remove listeners. This
may cause the thread to get unscheduled and be delayed before it gets another chance to

Our experience has been to integrate the receive handling into our main java program 
thread structure and have our own threads sitting in receive since we havn't needed to 
have multiple handlers of the same received message. 



On Mon, Feb 11, 2008 at 04:14:54PM -0500, John Keating wrote:
> Hi,
> I'm trying out Spread 4.0 Java interface.  As opposed to sitting on 
> connection.receive(), the BasicMessageListener interface is appealing 
> since you can have multiple listeners on one connection.
> If I use a single Java class to open the connection and read messages in 
> either mode, all is well.  If instantiate a second class to read 
> messagesin either mode, all is well.  The issue is when the second class 
> both extends Thread and acts as a listener.   Looking at the the test 
> classes User.java and recThread.java as examples, I created a class that 
> does both - extends Thread (like recThread.java) and implements the 
> BasicMessageListener interface.  I added the connection.receive() also 
> so this second class can receive messages either as a listener or by 
> blocking on connection.receive().  If I create the Thread object and 
> tell it to block on the connection.receive() , it's very fast.  If I 
> create the Thread object and tell it to listen, it's much, much slower - 
> maybe 10 times slower.
> Each Spread message's payload - the byte[] data - conains an ASN.1 
> encoded Java object.   When the message is received in either mode, the 
> byte array is decoded back into the Java object and some of the data is 
> displayed (message number).
> Does this performance difference ring a bell with anyone?
> _______________________________________________
> Spread-users mailing list
> Spread-users at lists.spread.org
> http://lists.spread.org/mailman/listinfo/spread-users

Jonathan R. Stanton         jonathan at cs.jhu.edu
Dept. of Computer Science   
Johns Hopkins University    

More information about the Spread-users mailing list