我最近开始开发一个密集使用网络的应用程序.第一次使用RMI尝试,由于几个原因,我们切换到纯套接字.但是,当通过网络或甚至在localhost上测试套接字时,我们降低到25个请求/秒的速率.使用RMI时,它高出两个数量级.
通过更多测试,我们获得了以下(对于localhost):
这是客户端代码:(服务器端只回复"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)