-
Notifications
You must be signed in to change notification settings - Fork 279
Add jit_stack_size option #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
81039e3
Add ngx.re.opt with a "jit_stack_size" option
alubbe 388a59c
Add error messages
alubbe 1af05e8
Disallow the changing of jit_stack_size once regex cache is populated
alubbe eceb788
Update error message to be the same as non-ffi
alubbe b5bd59c
Add NYI tests
alubbe 6bf7add
Update travis.yml
alubbe 1c6c7ad
Tests: Move ngx.re.opt into init_by_lua
alubbe 27d3064
Use *_by_lua_block in new tests
alubbe 8338ad6
Extract magic numbers
alubbe 3aa105b
Focus on success path
alubbe efd0adb
Move ngx.re.opt to ngx_re.opt
alubbe 96f85ab
Fix tests
alubbe 8ed4d22
Add http_config to the ngx.re tests
alubbe 850e3e4
Merge HttpConfig and init_by_lua manually for test 2
alubbe 5057830
Expand $pwd in test 2
alubbe 11c1da5
Pass http_config as a string
alubbe 6a49919
Another attempt to pass http_config as a string
alubbe 22ff594
Maybe this helps?
alubbe 7c833ab
Collectivism to the rescue!
alubbe 2e62edb
Check for existing compiled regexs in lua instead of C
alubbe 7d5e63e
Save error and next as local variables
alubbe d099691
Uncapitalize error messages
alubbe 96564d5
Remove unnecessary branches
alubbe 4ae9051
Re-insert empty last line
alubbe 2ee5c72
Cache variable lookup
alubbe 2762ef0
Use a private flag to determine whether the regex cache is empty
alubbe 8da1c98
Update test to expect uncapitalized error message
alubbe 236d832
update re.md
alubbe e919051
fix variable name
alubbe f68cbd0
Add spacing
alubbe a2a7303
Added handling of missing pcre jit support
alubbe cca774d
Minor improvements to the readme
alubbe 047a97f
Document the minimum jit_stack_size
alubbe 687a9ff
Read error messages from C
alubbe 6e47027
Add missing pointer declaration
alubbe da1a14f
Add missing bracket
alubbe 8053a23
Add missing imports
alubbe 1e05ce7
Restore return value that got lost in rebasing
alubbe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,6 +140,7 @@ local _M = { | |
|
||
local buf_grow_ratio = 2 | ||
|
||
|
||
function _M.set_buf_grow_ratio(ratio) | ||
buf_grow_ratio = ratio | ||
end | ||
|
@@ -154,6 +155,20 @@ local function get_max_regex_cache_size() | |
end | ||
|
||
|
||
local regex_cache_is_empty = true | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: two blank lines needed here. |
||
|
||
function _M.is_regex_cache_empty() | ||
return regex_cache_is_empty | ||
end | ||
|
||
|
||
local function lrucache_set_wrapper(...) | ||
regex_cache_is_empty = false | ||
lrucache_set(...) | ||
end | ||
|
||
|
||
local function parse_regex_opts(opts) | ||
local t = cached_re_opts[opts] | ||
if t then | ||
|
@@ -341,7 +356,7 @@ local function re_match_compile(regex, opts) | |
|
||
if compile_once then | ||
-- print("inserting compiled regex into cache") | ||
lrucache_set(regex_match_cache, key, compiled) | ||
lrucache_set_wrapper(regex_match_cache, key, compiled) | ||
end | ||
end | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -260,3 +260,4 @@ matched: 234 | |
NYI | ||
--- error_log eval | ||
qr/\[TRACE \d+ content_by_lua\(nginx\.conf:\d+\):4 loop\]/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
# vim:set ft= ts=4 sw=4 et fdm=marker: | ||
use lib 'lib'; | ||
use Test::Nginx::Socket::Lua; | ||
use Cwd qw(cwd); | ||
|
||
#worker_connections(1014); | ||
#master_process_enabled(1); | ||
#log_level('warn'); | ||
|
||
repeat_each(2); | ||
|
||
plan tests => repeat_each() * blocks() * 3; | ||
|
||
our $pwd = cwd(); | ||
|
||
our $HttpConfig = <<_EOC_; | ||
lua_package_path "$pwd/lib/?.lua;../lua-resty-lrucache/lib/?.lua;;"; | ||
init_by_lua_block { | ||
-- local verbose = true | ||
local verbose = false | ||
local outfile = "$Test::Nginx::Util::ErrLogFile" | ||
-- local outfile = "/tmp/v.log" | ||
if verbose then | ||
local dump = require "jit.dump" | ||
dump.on(nil, outfile) | ||
else | ||
local v = require "jit.v" | ||
v.on(outfile) | ||
end | ||
|
||
require "resty.core" | ||
-- jit.opt.start("hotloop=1") | ||
-- jit.opt.start("loopunroll=1000000") | ||
-- jit.off() | ||
} | ||
_EOC_ | ||
|
||
no_diff(); | ||
no_long_string(); | ||
check_accum_error_log(); | ||
run_tests(); | ||
|
||
__DATA__ | ||
|
||
=== TEST 1: default jit_stack_size too small | ||
--- http_config eval: $::HttpConfig | ||
--- config | ||
location /re { | ||
content_by_lua_block { | ||
-- regex is taken from https://github.com/JuliaLang/julia/issues/8278 | ||
local very_long_string = [[71.163.72.113 - - [30/Jul/2014:16:40:55 -0700] "GET emptymind.org/thevacantwall/wp-content/uploads/2013/02/DSC_006421.jpg HTTP/1.1" 200 492513 "http://images.search.yahoo.com/images/view;_ylt=AwrB8py9gdlTGEwADcSjzbkF;_ylu=X3oDMTI2cGZrZTA5BHNlYwNmcC1leHAEc2xrA2V4cARvaWQDNTA3NTRiMzYzY2E5OTEwNjBiMjc2YWJhMjkxMTEzY2MEZ3BvcwM0BGl0A2Jpbmc-?back=http%3A%2F%2Fus.yhs4.search.yahoo.com%2Fyhs%2Fsearch%3Fei%3DUTF-8%26p%3Dapartheid%2Bwall%2Bin%2Bpalestine%26type%3Dgrvydef%26param1%3D1%26param2%3Dsid%253Db01676f9c26355f014f8a9db87545d61%2526b%253DChrome%2526ip%253D71.163.72.113%2526p%253Dgroovorio%2526x%253DAC811262A746D3CD%2526dt%253DS940%2526f%253D7%2526a%253Dgrv_tuto1_14_30%26hsimp%3Dyhs-fullyhosted_003%26hspart%3Dironsource&w=588&h=387&imgurl=occupiedpalestine.files.wordpress.com%2F2012%2F08%2F5-peeking-through-the-wall.jpg%3Fw%3D588%26h%3D387&rurl=http%3A%2F%2Fwww.stopdebezetting.com%2Fwereldpers%2Fcompare-the-berlin-wall-vs-israel-s-apartheid-wall-in-palestine.html&size=49.0KB&name=...+%3Cb%3EApartheid+wall+in+Palestine%3C%2Fb%3E...+%7C+Or+you+go+peeking+through+the+%3Cb%3Ewall%3C%2Fb%3E&p=apartheid+wall+in+palestine&oid=50754b363ca991060b276aba291113cc&fr2=&fr=&tt=...+%3Cb%3EApartheid+wall+in+Palestine%3C%2Fb%3E...+%7C+Or+you+go+peeking+through+the+%3Cb%3Ewall%3C%2Fb%3E&b=0&ni=21&no=4&ts=&tab=organic&sigr=13evdtqdq&sigb=19k7nsjvb&sigi=12o2la1db&sigt=12lia2m0j&sign=12lia2m0j&.crumb=.yUtKgFI6DE&hsimp=yhs-fullyhosted_003&hspart=ironsource" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36]] | ||
local very_complicated_regex = [[([\d\.]+) ([\w.-]+) ([\w.-]+) (\[.+\]) "([^"\r\n]*|[^"\r\n\[]*\[.+\][^"]+|[^"\r\n]+.[^"]+)" (\d{3}) (\d+|-) ("(?:[^"]|\")+)"? ("(?:[^"]|\")+)"?]] | ||
local from, to, err = ngx.re.find(very_long_string, very_complicated_regex, "jo") | ||
if from or to then | ||
ngx.say("from: ", from) | ||
ngx.say("to: ", to) | ||
else | ||
if err then | ||
ngx.say("error: ", err) | ||
return | ||
end | ||
ngx.say("not matched!") | ||
end | ||
} | ||
} | ||
--- request | ||
GET /re | ||
--- response_body | ||
error: pcre_exec() failed: -27 | ||
--- no_error_log | ||
[error] | ||
|
||
|
||
|
||
=== TEST 2: increase jit_stack_size | ||
--- http_config eval | ||
<<_EOC_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe most tests in this module (and elsewhere) use the
|
||
lua_package_path "$::pwd/lib/?.lua;../lua-resty-lrucache/lib/?.lua;;"; | ||
init_by_lua_block { | ||
-- local verbose = true | ||
local verbose = false | ||
local outfile = "$Test::Nginx::Util::ErrLogFile" | ||
-- local outfile = "/tmp/v.log" | ||
if verbose then | ||
local dump = require "jit.dump" | ||
dump.on(nil, outfile) | ||
else | ||
local v = require "jit.v" | ||
v.on(outfile) | ||
end | ||
|
||
require "resty.core" | ||
-- jit.opt.start("hotloop=1") | ||
-- jit.opt.start("loopunroll=1000000") | ||
-- jit.off() | ||
|
||
local ngx_re = require "ngx.re" | ||
ngx_re.opt("jit_stack_size", 128 * 1024) | ||
} | ||
_EOC_ | ||
--- config | ||
location /re { | ||
content_by_lua_block { | ||
-- regex is taken from https://github.com/JuliaLang/julia/issues/8278 | ||
local very_long_string = [[71.163.72.113 - - [30/Jul/2014:16:40:55 -0700] "GET emptymind.org/thevacantwall/wp-content/uploads/2013/02/DSC_006421.jpg HTTP/1.1" 200 492513 "http://images.search.yahoo.com/images/view;_ylt=AwrB8py9gdlTGEwADcSjzbkF;_ylu=X3oDMTI2cGZrZTA5BHNlYwNmcC1leHAEc2xrA2V4cARvaWQDNTA3NTRiMzYzY2E5OTEwNjBiMjc2YWJhMjkxMTEzY2MEZ3BvcwM0BGl0A2Jpbmc-?back=http%3A%2F%2Fus.yhs4.search.yahoo.com%2Fyhs%2Fsearch%3Fei%3DUTF-8%26p%3Dapartheid%2Bwall%2Bin%2Bpalestine%26type%3Dgrvydef%26param1%3D1%26param2%3Dsid%253Db01676f9c26355f014f8a9db87545d61%2526b%253DChrome%2526ip%253D71.163.72.113%2526p%253Dgroovorio%2526x%253DAC811262A746D3CD%2526dt%253DS940%2526f%253D7%2526a%253Dgrv_tuto1_14_30%26hsimp%3Dyhs-fullyhosted_003%26hspart%3Dironsource&w=588&h=387&imgurl=occupiedpalestine.files.wordpress.com%2F2012%2F08%2F5-peeking-through-the-wall.jpg%3Fw%3D588%26h%3D387&rurl=http%3A%2F%2Fwww.stopdebezetting.com%2Fwereldpers%2Fcompare-the-berlin-wall-vs-israel-s-apartheid-wall-in-palestine.html&size=49.0KB&name=...+%3Cb%3EApartheid+wall+in+Palestine%3C%2Fb%3E...+%7C+Or+you+go+peeking+through+the+%3Cb%3Ewall%3C%2Fb%3E&p=apartheid+wall+in+palestine&oid=50754b363ca991060b276aba291113cc&fr2=&fr=&tt=...+%3Cb%3EApartheid+wall+in+Palestine%3C%2Fb%3E...+%7C+Or+you+go+peeking+through+the+%3Cb%3Ewall%3C%2Fb%3E&b=0&ni=21&no=4&ts=&tab=organic&sigr=13evdtqdq&sigb=19k7nsjvb&sigi=12o2la1db&sigt=12lia2m0j&sign=12lia2m0j&.crumb=.yUtKgFI6DE&hsimp=yhs-fullyhosted_003&hspart=ironsource" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36]] | ||
local very_complicated_regex = [[([\d\.]+) ([\w.-]+) ([\w.-]+) (\[.+\]) "([^"\r\n]*|[^"\r\n\[]*\[.+\][^"]+|[^"\r\n]+.[^"]+)" (\d{3}) (\d+|-) ("(?:[^"]|\")+)"? ("(?:[^"]|\")+)"?]] | ||
local from, to, err = ngx.re.find(very_long_string, very_complicated_regex, "jo") | ||
if from or to then | ||
ngx.say("from: ", from) | ||
ngx.say("to: ", to) | ||
else | ||
if err then | ||
ngx.say("error: ", err) | ||
return | ||
end | ||
ngx.say("not matched!") | ||
end | ||
} | ||
} | ||
--- request | ||
GET /re | ||
--- response_body | ||
from: 1 | ||
to: 1563 | ||
--- no_error_log | ||
[error] | ||
|
||
|
||
|
||
=== TEST 3: jit_stack_size change disallowed once regex cache is populated | ||
--- http_config eval: $::HttpConfig | ||
--- config | ||
location /re { | ||
content_by_lua_block { | ||
local ngx_re = require "ngx.re" | ||
|
||
local status, err = pcall(ngx_re.opt, "jit_stack_size", 128 * 1024) | ||
if err then ngx.log(ngx.ERR, err) end | ||
local s = "hello, 1234" | ||
local from, to = ngx.re.find(s, "(hello world)|([0-9])", "jo") | ||
ngx.say("from: ", from) | ||
ngx.say("to: ", to) | ||
} | ||
} | ||
--- request | ||
GET /re | ||
--- response_body | ||
from: 8 | ||
to: 8 | ||
|
||
--- grep_error_log eval | ||
qr/changing jit stack size is not allowed when some regexs have already been compiled and cached/ | ||
|
||
--- grep_error_log_out eval | ||
["", "changing jit stack size is not allowed when some regexs have already been compiled and cached\n"] | ||
|
||
|
||
|
||
=== TEST 4: passing unknown options to ngx_re.opt throws an error | ||
--- http_config eval: $::HttpConfig | ||
--- config | ||
location /re { | ||
content_by_lua_block { | ||
local ngx_re = require "ngx.re" | ||
|
||
local status, err = pcall(ngx_re.opt, "foo", 123) | ||
ngx.say(err) | ||
} | ||
} | ||
--- request | ||
GET /re | ||
--- response_body | ||
unrecognized option name | ||
--- no_error_log | ||
[error] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite like this variable name. How about
regex_cache_updated
?