相关疑难解决方法(0)

Java socket性能瓶颈:在哪里?

我最近开始开发一个密集使用网络的应用程序.第一次使用RMI尝试,由于几个原因,我们切换到纯套接字.但是,当通过网络或甚至在localhost上测试套接字时,我们降低到25个请求/秒的速率.使用RMI时,它高出两个数量级.

通过更多测试,我们获得了以下(对于localhost):

  • 始终发送相同的对象:31628个请求/秒
  • 始终发送新对象:25个请求/秒
  • 只有对象创建率:每秒3-4百万(这不是瓶颈)

这是客户端代码:(服务器端只回复"ACK")

public static void main(String[] args) throws IOException, ClassNotFoundException
{
    Socket kkSocket = null;
    ObjectOutputStream out = null;
    ObjectInputStream in = null;


    kkSocket = new Socket("barium", 4444);
    out = new ObjectOutputStream(kkSocket.getOutputStream());
    in = new ObjectInputStream(kkSocket.getInputStream());


    long throughput;
    long millis;

    TcpRequest hello = null;


    throughput = 0;
    millis = System.currentTimeMillis();
    while (System.currentTimeMillis() < millis + 1000)
    {
        hello = new TcpRequest();
        hello.service = "hello";
        hello.payload = Math.random();
        throughput++;
    }

    System.out.println("-------------------------------------------------------");
    System.out.println("|        Objects created: " + (throughput) …
Run Code Online (Sandbox Code Playgroud)

java sockets

8
推荐指数
1
解决办法
8934
查看次数

标签 统计

java ×1

sockets ×1