其他分享
首页 > 其他分享> > 个人pc单机上万并发连接实战

个人pc单机上万并发连接实战

作者:互联网

环境

服务

nodejs写的一个hello world的http服务
代码如下

const http = require('http');

const server = http.createServer((req, res) => {
    let now = ''+new Date().getTime()
    res.write(now)
    res.end();
    //console.info(now)
});
server.on('clientError', (err, socket) => {
  socket.end('HTTP/1.1 400 Bad Request');
});
server.listen(8000);
console.info('server started at port 8000!')

测试工具

apache jmeter
测试计划如下
Test Plan
Thead Group(16个线程)
Loop Controller(3000次循环)
Http Request(post http://localhost:8000)

测试结果

执行测试,生成报告的步骤省略
以下为测试报告
{
“Total” : {
“transaction” : “Total”,
“sampleCount” : 48000,
“errorCount” : 0,
“errorPct” : 0.0,
“meanResTime” : 0.6678333333333379,
“medianResTime” : 0.0,
“minResTime” : 0.0,
“maxResTime” : 47.0,
“pct1ResTime” : 1.0,
“pct2ResTime” : 1.0,
“pct3ResTime” : 2.0,
“throughput” : 16500.515641113787,
“receivedKBytesPerSec” : 2110.905809556549,
“sentKBytesPerSec” : 3351.6672396012377
},
“HTTP Request” : {
“transaction” : “HTTP Request”,
“sampleCount” : 48000,
“errorCount” : 0,
“errorPct” : 0.0,
“meanResTime” : 0.6678333333333379,
“medianResTime” : 0.0,
“minResTime” : 0.0,
“maxResTime” : 47.0,
“pct1ResTime” : 1.0,
“pct2ResTime” : 1.0,
“pct3ResTime” : 2.0,
“throughput” : 16500.515641113787,
“receivedKBytesPerSec” : 2110.905809556549,
“sentKBytesPerSec” : 3351.6672396012377
}
}
可以看出,throughput已经达到了16500.

备注:要支持高并发,需要优化操作系统的文件打开数配置,socket相关配置,防火墙相关配置.
这里我都已经配置好了.具体优化自行查阅相关资料.

感想

作为一个有追求的程序员,是不惧挑战的.
纵然学习了各种高并发的理论知识,但是纸上学来终觉浅.
于是想着要实战练习一下.
一般单机并发上万能解决大部分需求了.
当然实际需求并不会是一个hello world.
所以实际我们还需要考虑其他问题.
如果需要实战更高的并发,可以在某某云租几台机器尝试一下.

标签:http,并发,单机,0.0,Request,server,pc,1.0,上万
来源: https://blog.csdn.net/zhoujiaping123/article/details/115828405