hi-nginx-1.4.9已经支持javascript,这意味着把javascript应用于后端开发,将不再只有nodejs这唯一的途径和方法。由于java本身对javascript的极好支持,使得在hi-nginx中,可以直接在javascript脚本中使用java——相当于把java嵌入了javascript。因此,你随时可以用java写个库或者类,然后在javascript中随便玩。这比用c/c++写node.js扩展舒服多了。
那么,hi-nginx-javascript VS node.js,如何呢?来个node.js (6.12.0)helloworld比较下。
node.js:
var http = require('http');
http.createServer(function (request, response) {
// 发送 HTTP 头部
// HTTP 状态值: 200 : OK
// 内容类型: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// 发送响应数据 "Hello World"
response.end('Hello World');
}).listen(8888);
// 终端打印如下信息
console.log('Server running at http://127.0.0.1:8888/');
hi-nginx-javascript:
location / {
hi_need_cache off;
hi_cache_expires 5s;
hi_need_kvdb on;
hi_kvdb_size 10;
hi_kvdb_expires 5s;
hi_need_cookies on;
hi_need_headers on;
hi_need_session on;
hi_session_expires 300s;
hi_javascript_lang javascript;
hi_javascript_extension js;
#hi_javascript_script javascript/index.js;
hi_javascript_content "hi_res.content='hello,world';hi_res.status=200;";
}
使用ab作为压力测试工具:ab -c 1000 -n 500000。从最终稳定结果RPS来看,n=500000对nodejs来说是越不过去,
Completed 50000 requests
Completed 100000 requests
Completed 150000 requests
apr_socket_recv: Connection reset by peer (104)
Total of 162214 requests completed
而hi-nginx-javascript均值在14000多左右:
Server Software: nginx/1.14.0
Server Hostname: 127.0.0.1
Server Port: 8086
Document Path: /
Document Length: 11 bytes
Concurrency Level: 1000
Time taken for tests: 34.366 seconds
Complete requests: 500000
Failed requests: 0
Total transferred: 139000000 bytes
HTML transferred: 5500000 bytes
Requests per second: 14549.43 [#/sec] (mean)
Time per request: 68.731 [ms] (mean)
Time per request: 0.069 [ms] (mean, across all concurrent requests)
Transfer rate: 3949.94 [Kbytes/sec] received
把n降低至100000,nodejs偶尔能完成测试,RPS的最好成绩是8900多,其值在6000至9000间徘徊:
Server Software:
Server Hostname: 127.0.0.1
Server Port: 8888
Document Path: /
Document Length: 11 bytes
Concurrency Level: 1000
Time taken for tests: 11.114 seconds
Complete requests: 100000
Failed requests: 0
Total transferred: 11200000 bytes
HTML transferred: 1100000 bytes
Requests per second: 8997.62 [#/sec] (mean)
Time per request: 111.141 [ms] (mean)
Time per request: 0.111 [ms] (mean, across all concurrent requests)
Transfer rate: 984.11 [Kbytes/sec] received
而hi-nginx-javascript则依然表现出众,与n=500000是差不多:
Server Software: nginx/1.14.0
Server Hostname: 127.0.0.1
Server Port: 8086
Document Path: /
Document Length: 11 bytes
Concurrency Level: 1000
Time taken for tests: 7.038 seconds
Complete requests: 100000
Failed requests: 0
Total transferred: 27800000 bytes
HTML transferred: 1100000 bytes
Requests per second: 14208.52 [#/sec] (mean)
Time per request: 70.380 [ms] (mean)
Time per request: 0.070 [ms] (mean, across all concurrent requests)
Transfer rate: 3857.39 [Kbytes/sec] received
结论:
hi-nginx-javascript 完胜 nodejs。
希望与广大网友互动??
点此进行留言吧!