[Spread-users] Java API Performance

John Keating jkeating at ca.afilias.info
Mon Apr 21 15:51:21 EDT 2008


When you're the sender, you're also calling receiveMessage()...should you?

Mike Perik wrote:
> Has anyone done any basic performance tests with the Java API?
> I'm seeing what I would consider lengthy sending times.
>
> My test involves a process sending 5000 messages.  The message is the current time with the granularity to milliseconds.  The sending process sends a message and then receives the message.  When it receives the message is takes time it received it and subtracts the sending time.  I'm seeing a round trip time of 39-41 milliseconds.  I did the same test in C and the round trip time is more like 1 ms. 
>
> Maybe I'm doing something incorrectly, if so I'm not sure what it is and would be interested in any help you can give me.
>
> Below is the code I'm using.
>
> Thank you for your help,
> Mike
>
>
> import spread.*;
> import java.net.*;
>
> public class spreadlatency 
> {
>     SpreadConnection _sc;
>     boolean _sender = false;
>     MessageFactory _mf;
>     static public void main(String args[]) throws Exception
>     {
>         SpreadConnection sc = new SpreadConnection();
>         spreadlatency sl = new spreadlatency(sc, args.length == 0 ? true : false);
>         sc.connect(InetAddress.getLocalHost(), 4803, null, false, false);
>         sl.run();
>     }
>     
>     public spreadlatency(SpreadConnection sc, boolean sender) throws Exception
>     {
>         _sc = sc;
>         _sender = sender;
>     }
>
>     public void run()
>     {
>         SpreadGroup sg = new SpreadGroup();
>         try {
>             sg.join(_sc, "LATENCY");
>         }
>         catch (Exception ex)
>         {
>             ex.printStackTrace();
>         }
>         if (_sender == true)
>         {
>             SpreadMessage sm = new SpreadMessage();
>             short y = 1000;
>             sm.setType(y);
>             sm.addGroup("LATENCY");
>             int x = 0;
>             while (x++ < 5000)
>             {
>                 //                String st = "";
>                 long t = System.currentTimeMillis();
>                 //                st += t;
>                 //                sm.setData(st.getBytes());
>                 try {
>                     sm.setObject(new Long(t));
>                     _sc.multicast(sm);
>                     receiveMessage();
>                 }
>                 catch (Exception ex)
>                 {
>                     ex.printStackTrace();
>                 }
>                 
>             }
>         }
>         else
>         {
>             int x = 0;
>             while (x++ < 5000)
>             {
>                 receiveMessage();
>             }
>         }
>     }
>     
>     void receiveMessage()
>     {
>         try {
>             SpreadMessage sm = _sc.receive();
>             short type = sm.getType();
>             if (type == 1000)
>             {
>                 //                String s = new String(sm.getData());
>                 //                Long l = Long.valueOf(s);
>                 Long l = (Long)sm.getObject();
>                 if (_sender == true)
>                 {
>                     System.out.println("Sender Latency: " + (System.currentTimeMillis() - l.longValue()));
>                 }
>                 else
>                 {
>                     System.out.println("Recver Latency: " + (System.currentTimeMillis() - l.longValue()));
>                 }
>             }
>         }
>         catch (Exception ex)
>         {
>             ex.printStackTrace();
>         }
>     }
> }
>
>
>
>
>
>       ____________________________________________________________________________________
> Be a better friend, newshound, and 
> know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>
> _______________________________________________
> Spread-users mailing list
> Spread-users at lists.spread.org
> http://lists.spread.org/mailman/listinfo/spread-users
>   





More information about the Spread-users mailing list