首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kryonet RMI性能

Kryonet RMI性能
EN

Stack Overflow用户
提问于 2013-11-12 03:26:46
回答 1查看 842关注 0票数 0

我试图为Kryonet RMI运行一个性能测试,测试结果并不令人信服。然而,我认为我可能没有以正确的方式做事情。我能得到一些关于下面代码的反馈吗?

服务器

代码语言:javascript
复制
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);

            }

        });

    }

}

客户端

代码语言:javascript
复制
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();

    }

}

结果

代码语言:javascript
复制
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

我会想象更多的性能。这是一个有效的测试吗?

EN

回答 1

Stack Overflow用户

发布于 2014-02-07 04:13:33

这不是一个有效的性能测试,因为即使在本地主机请求中,也有很强的延迟,并且测试程序在发送下一个请求之前等待服务器响应(因为rmi方法调用本质上是阻塞的)。

因为你做了900次,即使没有任何java处理,你也必须等待: number_of_request *travel_time(延迟)*2(一次请求,一次响应)。

因此,在您的示例中: 900 *0.03秒(ping localhost查看您的本地延迟) ~= 27秒

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19914247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档