test max connections for linux server 测试linux服务器最大连接数。
install nodejs>8
ulimit -n 1000000
npx node1000k
test max connections
使用你的脚本执行完后,connection count 在392700导致了core dumped.
然后我对脚本进行了修改,因为想试一下如果只起单个服务的话能有多少个连接,所以将代码改为如下:
var net = require('net');
var count = 0
//server
let server = net.createServer(function(conn){
conn.on("close", function(code, reason){
console.log("close", code, reason);
})
conn.on("error", function(code, reason){
console.log("error close", code, reason);
})
}).listen({port : 8080, host: "0.0.0.0", backlog: 100000}).on("connection", _=>{count++});
//client
setInterval(_=>{new Array(300).fill(1).map((_,index)=>index+1926).map(p=>{
new net.Socket().connect(8080,'127.0.0.1')
.on('error',function(e){
console.log(count);
console.log(e);
process.exit()}
);
})&&console.log('connection count:',count)},100)
结果在connection count 达到64500的时候报了如下错误
{ Error: connect EADDRNOTAVAIL 127.0.0.1:8080 - Local (127.0.0.1:0)
at internalConnect (net.js:872:16)
at defaultTriggerAsyncIdScope (internal/async_hooks.js:294:19)
at defaultTriggerAsyncIdScope (net.js:962:9)
at process._tickCallback (internal/process/next_tick.js:61:11)
errno: 'EADDRNOTAVAIL',
code: 'EADDRNOTAVAIL',
syscall: 'connect',
address: '127.0.0.1',
port: 8080 }
原因应该是端口被耗尽,但是multiple server 不应该也会有这样的问题吗?
想请教下为什么multiple server和single server会有这样的差距?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.