聽說Node.js最近很火,網上簡單查閱了一下,大約就是一個在非瀏覽器環境下執行js的engine(基於V8引擎的擴充),並且內建web server功能。用js來取代其他傳統的伺服器端指令碼,大有“一切皆js”的架勢。最近在學習一些linux的東西,所以嘗試在centos上裝了個Node嘗嘗鮮。
從原始碼安裝和測試
從http://nodejs.org上找到下載源碼的地址:http://nodejs.org/dist/v0.8.14/node-v0.8.14.tar.gz 用wget命令下載:
wget http://nodejs.org/dist/v0.8.14/node-v0.8.14.tar.gz
tar –zxf node-v0.8.14.tar.gz
- cd到node-v0.8.14,依次執行configure\make\make install,編譯需要依賴的庫:yum install gcc-c++ openssl-devel
./configuremakemake install
- 寫個測試代碼,儲存成test-web-server.js
var http = require('http');http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Node.js\n');}).listen(8081, "192.168.1.102");console.log('Server running at http://192.168.1.102:8081/');
node test-web-server.js &
iptables -I INPUT 2 -p tcp --dport 8081 -j ACCEPTservice iptables save
- 用http_load做個簡單的壓力測試,可以看到同樣是10000次請求,當並發數是50時,吞吐率為2869,當並發數是500時,吞吐率為1935,下降趨勢比較明顯哦~