0

I was trying to run a performance test for Kryonet RMI, the test results are not convincing. However I think I may not be doing things in the right way. Can I get some feedback on the code below.

SERVER

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;
import com.esotericsoftware.kryonet.Server;
import com.esotericsoftware.kryonet.rmi.ObjectSpace;

public class Razor {      

    static int port = 2551;
    static String send = null;

    // Data Creator, creates data of size s.getBytes().length * 10
    static String createMsg(String s){

        StringBuilder sb = new StringBuilder();

        for (int i = 0 ; i < 10; i++){
            sb.append(s);
        }

        System.out.println(sb.toString().getBytes().length);

        return sb.toString();

    }    

    // Test Interface
    public static interface TestInterface {

        public String getName (String name);

    }    

    //Class implementing the test interface.
    static private class TestImpl implements TestInterface {  

        public String getName (String name) {

            return send;

        }

    }    

    public static void main (String[] args) throws Exception {

        // Creating data of size 160 bytes
        send = createMsg("FooAndBarAndLazy");

        Server server = new Server();

        Kryo kryo = server.getKryo();

        ObjectSpace.registerClasses(kryo);

        kryo.register(TestInterface.class);

        server.start();

        server.bind(port);

        System.out.println("Server started on " + port);        

        TestImpl test = new TestImpl();

        final ObjectSpace objectSpace = new ObjectSpace();

        objectSpace.register(123, test);

        server.addListener(new Listener() {

            public void connected (final Connection connection) {

                objectSpace.addConnection(connection);

            }

        });

    }

}

CLIENT

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryonet.Client;
import com.esotericsoftware.kryonet.rmi.ObjectSpace;

public class TBone {

    static int port = 2551;

    // Bytes to MB converter
    public static float b2mb(long bytes){

        float bb = bytes;

        float ll = 1024 * 1024;

        return bb/ll;

    }

    // Nono Seconds to seconds converter
    public static float ns2s(long nsecs){

        float f = nsecs;
        float t = 1000000000;

        return f/t;

    }



    public static void main (String[] args) throws Exception {

        Client client = new Client();

        Kryo kryo = client.getKryo();

        ObjectSpace.registerClasses(kryo);

        kryo.register(Razor.TestInterface.class);


        client.start();

        client.connect(50000, "localhost", port);


        Razor.TestInterface test = ObjectSpace.getRemoteObject(client, 123, Razor.TestInterface.class);

        String profile = null;

        int bytes = 0;

        long stime = System.nanoTime();

        for (int  i = 0; i < 1000; i++){

            profile = test.getName("");

            bytes = bytes + profile.getBytes().length;

            if (i %100 == 0) System.out.println("Done : " + i);

        }

        long etime = System.nanoTime();

        System.out.println("Total bytes(MB) : " + b2mb(bytes)+" , " + "Total time : " + ns2s((etime-stime))+" seconds");

        client.stop();

    }

}

RESULT

Done : 0
Done : 100
Done : 200
Done : 300
Done : 400
Done : 500
Done : 600
Done : 700
Done : 800
Done : 900

Total bytes(MB) : 0.15258789 , Total time : 26.139627 seconds

I would imagine way more performance. Is this a valid test?

Scolytus
  • 16,338
  • 6
  • 46
  • 69
  • Kryonet RMI is a reflection layer built over RMI, so it's going to be slower than raw RMI, particularly on an unrealistic test like this that tests nothing else. I cannot see the point of it myself. – user207421 Nov 11 '13 at 21:18

1 Answers1

0

This isn't a valid test of performance because even in a localhost request you have a strong latency and your test program wait for the server response before sending next request (as a rmi method call is by nature blocking).

Since you do it 900 time, even without any java processing you have to wait : number_of_request * travel_time(latency) * 2(one travel for the request and one for the response).

So in your case : 900 * 0.03seconds (ping localhost to see your local latency) ~= 27 seconds

GaelFG
  • 81
  • 4