在Debian上进行Node.js性能测试,你可以遵循以下步骤:
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
这里我们使用的是Node.js 14.x版本,你可以根据需要选择其他版本。
app.js
的文件,并添加以下代码:const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
});
const port = 3000;
server.listen(port, () => {
console.log(`Server running at http://localhost:${port}/`);
});
这个简单的应用程序会在每次收到请求时返回"Hello World"。
node app.js
现在,你的应用程序应该在端口3000上运行。
sudo apt-get install apache2-utils
ab -n 1000 -c 100 http://localhost:3000/
这里,-n
参数表示请求的总数,-c
参数表示并发请求的数量。
注意:Apache Bench适用于简单的性能测试,但对于更复杂的场景,你可能需要使用其他工具,如Artillery或wrk。这些工具提供了更多的功能和更详细的统计信息。