hi-nginx-1.4.9正式发布,支持javascript后端开发

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

 

 

官网:https://www.hi-nginx.com/

文档:https://doc.hi-nginx.com/

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

 


posted @ 2018-05-14 09:06 hi-nginx 阅读(...) 评论(...) 编辑 收藏