socket.write 性能可能需要分析下
lhkzh opened this issue · 1 comments
lhkzh commented
在windows上,write100k条,3000ms+;centos上400ms+; 用php写个测了下 centos上90ms,windows上900ms
fibjs代码
fibjs test_sk.js server
fibjs test_sk.js client
const net=require("net"); net.use_uv_socket=process.argv.slice(2).includes("uv");
if(process.argv.slice(2).includes("server")){
new net.TcpServer(8113, function(conn) {
var data;
while (data = conn.read()){
}
conn.close();
}).start();
}else{
var sock=net.connect("tcp://127.0.0.1:8113");
console.time("write");
let buf = Buffer.from(`PUB fooaa 45\r\nabjiahgpuhapughpauhgphaupghpauhgpuahpguhapugh\r\n`);
for(var i=0;i<100000;i++){
sock.write(buf); // sock.flush();
}
console.timeEnd("write");
}```
php
```<?php
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, "127.0.0.1", 8113);
$t = microtime(true)*1000;
for($i=0;$i<100000;$i++){
socket_write($socket, "PUB fooaa 45\r\nabjiahgpuhapughpauhgphaupghpauhgpuahpguhapugh\r\n");
}
$now = microtime(true)*1000;
echo($now-$t).PHP_EOL;```
forchid commented
Why close the issue? @lhkzh . In my windows system, a java program only needs 384ms.
import java.net.*;
public class test_sk {
public static void main(String[] args) throws Exception {
var sock = new Socket("127.0.0.1", 8113);
var ts = System.currentTimeMillis();
var buf = new String("PUB fooaa 45\r\nabjiahgpuhapughpauhgphaupghpauhgpuahpguhapugh\r\n")
.getBytes("utf-8");
var out = sock.getOutputStream();
for(var i = 0; i < 100000; i++) {
out.write(buf); // out.flush();
}
out.close();
sock.close();
var te = System.currentTimeMillis();
System.out.printf("time %sms%n", (te - ts) / 1000.0);
}
}