本文共 2534 字,大约阅读时间需要 8 分钟。
hi-nginx-1.4.9已经发布。
更新:
从这一版开始,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', outputif (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 = outputhi_res.status = 200;
比较:
helloworld:
fedora 25,4g,2核i5,笔记本
ab -c 1000 -n 500000 压力测试,RPS:
ab -c 1000 -n 100000 压力测试,RPS:
用法:
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.0Server Hostname: 127.0.0.1Server Port: 8086Document Path: /Document Length: 11 bytesConcurrency Level: 1000Time taken for tests: 34.457 secondsComplete requests: 500000Failed requests: 0Total transferred: 139000000 bytesHTML transferred: 5500000 bytesRequests 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
官网:
文档:
仓库:
转载地址:http://tilja.baihongyu.com/