hi-nginx-1.4.9已经发布。
更新:
支持javascript后端开发
修复脚本搜索的一个bug
从这一版开始,hi-nginx开始支持javascript,这意味着把javascript应用于后端开发,将不再只有nodejs这唯一的途径和方法。由于java本身对javascript的极好支持,使得在hi-nginx中,可以直接在javascript脚本中使用java——相当于把java嵌入了javascript。
为了开启javascript支持,你只需要开启java支持即可:--enable-http-hi-java=YES。
例子:
if (typeof (Mustache) == 'undefined') { load('https://cdn.bootcss.com/mustache.js/2.3.0/mustache.min.js') } var list = java.util.Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); var template = "{{#list}}* {{.}}\n{{/list}}" var key = 'test', output if (hi_req.cache.containsKey(key)) { output = hi_req.cache.get(key) } else { output = Mustache.render(template, {'list': JSON.parse(list.toString())}) hi_res.cache.put(key, output) } hi_res.headers.get('Content-Type').set(0, 'text/plain;charset=UTF-8') hi_res.content = output hi_res.status = 200;
比较:
helloworld:
fedora 25,4g,2核i5,笔记本
ab -c 1000 -n 500000 压力测试,RPS:
nodejs(6.12.0):无法完成测试
hi-nginx-javascript :均值13000+
ab -c 1000 -n 100000 压力测试,RPS:
nodejs(6.12.0):偶尔完成测试,最好成绩接近9000+,均值6000-9000
hi-nginx-javascript :均值14000+
用法:
hi_java_classpath "-Djava.class.path=.:/usr/local/nginx/java:/usr/local/nginx/java/hi-nginx-java.jar"; hi_java_options "-server -d64 -Xms512m -Xmx512m -Xmn170m -Dnashorn.args=--global-per-engine"; hi_java_servlet_cache_expires 300s; hi_java_servlet_cache_size 10; hi_java_version 8; location / { hi_need_cache off; hi_cache_expires 5s; hi_need_kvdb off; 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;"; }
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.457 seconds Complete requests: 500000 Failed requests: 0 Total transferred: 139000000 bytes HTML transferred: 5500000 bytes Requests per second: 14510.69 [#/sec] (mean) Time per request: 68.915 [ms] (mean) Time per request: 0.069 [ms] (mean, across all concurrent requests) Transfer rate: 3939.43 [Kbytes/sec] received
引用来自“一位极其不愿意透漏姓名的马先生”的评论
php的并发测试数据是多少ab -c 1000 -n 500000:13000+
ab -c 1000 -n 500000:14000+
ab -c 1000 -n 1000000:13000+
Server Software: nginx/1.14.0
Server Hostname: 127.0.0.1
Server Port: 8081
Document Path: /
Document Length: 11 bytes
Concurrency Level: 1000
Time taken for tests: 73.325 seconds
Complete requests: 1000000
Failed requests: 0
Total transferred: 278000000 bytes
HTML transferred: 11000000 bytes
Requests per second: 13637.82 [#/sec] (mean)
Time per request: 73.325 [ms] (mean)
Time per request: 0.073 [ms] (mean, across all concurrent requests)
Transfer rate: 3702.46 [Kbytes/sec] received
引用来自“左华栋”的评论
为啥用 node 6测试,而不是 node8 和 node10, 可以对比下 fastify 么引用来自“所以呢”的评论
nodejs 6比nodejs 8,10慢很多吗?fastify不甚了解,你可以测一下
引用来自“左华栋”的评论
10比8异步性能提升20%左右。node10 下fastify 直接逼近 beego (golang)。
引用来自“左华栋”的评论
为啥用 node 6测试,而不是 node8 和 node10, 可以对比下 fastify 么引用来自“所以呢”的评论
nodejs 6比nodejs 8,10慢很多吗?fastify不甚了解,你可以测一下
node10 下fastify 直接逼近 beego (golang)。
引用来自“圣艾夫斯传说”的评论
很强大!希望完善文档先。后端js的话,长远着想还是该typescript吧,如有官方的ts声明文件就更好啦:)AND MORE
引用来自“左华栋”的评论
为啥用 node 6测试,而不是 node8 和 node10, 可以对比下 fastify 么fastify不甚了解,你可以测一下
引用来自“_vince”的评论
有没有java版本的使用demo,看wiki有点懵https://github.com/webcpp/hi-nginx-demo/tree/master/javascript