what's new in openresty for 2016 · what's new in openresty for 2016...
TRANSCRIPT
![Page 2: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/2.jpg)
ngx_stream_lua_module
(vs ngx_http_lua_module)
![Page 3: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/3.jpg)
stream # define a TCP server listening on # the port 1234: server listen 1234; content_by_lua_block ngx.say("Hello, Lua!")
![Page 4: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/4.jpg)
stream server listen 4343 ssl; ssl_certificate /path/to/cert.pem; ssl_certificate_key /path/to/cert.key; content_by_lua_block local sock = ngx.req.socket(true) read a line from client local data = sock:receive() if data == "thunder!" then ngx.say("flash!") output data end
![Page 5: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/5.jpg)
![Page 6: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/6.jpg)
ssl_certificate_by_lua*
ngx.sslngx.ocsp
![Page 7: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/7.jpg)
ssl_certificate_by_lua_block local ssl = require "ngx.ssl" clear default certificates and private keys ssl.clear_certs() set certificate chain in DER format for the current SSL session ssl.set_der_cert(my_cert_chain) set private key in DER format for the current SSL session ssl.set_der_priv_key(my_private_key)
![Page 8: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/8.jpg)
![Page 9: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/9.jpg)
ssl_session_fetch_by_lua*ssl_session_store_by_lua*
![Page 10: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/10.jpg)
balancer_by_lua*
ngx.balancer
![Page 11: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/11.jpg)
upstream my_backend server 0.0.0.1; # just a place holder balancer_by_lua_block local balancer = require "ngx.balancer" local host = "10.26.4.2" local port = 8080 balancer.set_current_peer(host, port) Note: you can control retries here as well. keepalive 10; # configure connection pool
![Page 12: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/12.jpg)
server location / proxy_pass http://my_backend;
![Page 13: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/13.jpg)
ngx.semaphore
![Page 14: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/14.jpg)
local semaphore = require "ngx.semaphore" local sema = semaphore.new()
![Page 15: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/15.jpg)
producer sema:post(2) post 2 resources
![Page 16: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/16.jpg)
consumer, maybe in another request handler wait for a resource, 3 sec timeout local ok, err = sema:wait(3)
![Page 17: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/17.jpg)
Lists or queues in lua_shared_dict
![Page 18: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/18.jpg)
local animals = ngx.shared.animals apend an item to the end of the list under key "dogs" local cnt, err = animals:rpush("dogs", "Tom") append another item cnt, err = animals:rpush("dogs", "Bob") pop out an item from the beginning of the list under key "dogs" cnt, err = animals:lpop("dogs")
![Page 19: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/19.jpg)
C2000K
![Page 20: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/20.jpg)
Lemplate
TT2 templates ⇒ Lua code
![Page 21: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/21.jpg)
<! file a.tt2 > <html><body> <ul> [% FOREACH v IN list %] <li>[% v | html %]</li> [% END %] </ul> </body></html>
![Page 22: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/22.jpg)
$ lemplate compile a.tt2 > my_templates.lua
![Page 23: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/23.jpg)
location = /animals content_by_lua_block local templates = require "my_templates" local animals = "cats", "dogs", "birds" local html = templates.process( "a.tt2", only as a key list = animals ) ngx.print(html)
![Page 24: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/24.jpg)
$ curl http://localhost/animals <! file a.tt2 > <html><body> <ul> <li>dogs</li> <li>cats</li> <li>birds</li> </ul> </body></html>
![Page 25: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/25.jpg)
Jemplate TT2 templates ⇒ Browser JavaScript code
![Page 26: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/26.jpg)
Official Windows binary builds
Linux binary packages coming...
![Page 27: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/27.jpg)
![Page 28: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/28.jpg)
Official Package Management
![Page 29: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/29.jpg)
resty.luarocks.org
![Page 30: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/30.jpg)
$ opm install agentzh/luarestyscream
![Page 31: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/31.jpg)
OpenResty Edge Platform
![Page 32: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/32.jpg)
server agentzh.org; uriprefix("/foo", "/bar/baz") => seturiarg(channel: 3), done; uri(rx / ([09af]+) ), uriarg("name") as $name => redirect(uri: "/en/$name/$1", code: 301);
![Page 33: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/33.jpg)
The Edge optimizing compilertargeting Lua
![Page 34: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/34.jpg)
PCRE JIT Sregex DFA Intel HyperScan Google RE2
![Page 35: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/35.jpg)
OpenResty WAF Platform
![Page 36: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/36.jpg)
ModSecurity rule translatortargeting OpenResty Edge
![Page 37: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/37.jpg)
The ORSQL language
![Page 38: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/38.jpg)
Relational-relational mapping (RRM)
![Page 39: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/39.jpg)
date $day; symbol $database, $table, $column; location $db_node; @res := select $column, count(id) from $database.$table where day = $day group by $column at $db_node;
![Page 40: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/40.jpg)
The Y language
![Page 41: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/41.jpg)
Y source code
⇒ SystemTap scripts
⇒ GDB Python scripts
⇒ LLDB Python scripts
⇒ Linux eBPF bytecode?
![Page 42: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/42.jpg)
Any questions?
![Page 43: What's new in OpenResty for 2016 · What's new in OpenResty for 2016 ☺agentzh@gmail.com☺ Yichun Zhang (agentzh) 2016.3](https://reader034.vdocument.in/reader034/viewer/2022050101/5f40029eb529fe483159cfb2/html5/thumbnails/43.jpg)
Wha