您现在的位置是:首页 > 文章详情

hi-nginx-javascript vs node.js

日期:2018-05-12点击:333

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比较下。

fedora 25,4g,2core,i5,笔记本

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。

 

 

 

hi-nginx github: https://github.com/webcpp/hi-nginx

 

原文链接:https://yq.aliyun.com/articles/684935
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章