Skip to content

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
wants to merge 38 commits into from
Closed

Conversation

alubbe
Copy link
Contributor

@alubbe alubbe commented May 31, 2016

@@ -162,6 +165,11 @@ local function get_max_regex_cache_size()
return max_regex_cache_size
end

function _M.opt(option, value)
if option == "jit_stack_size" then
C.ngx_http_lua_ffi_set_jit_stack_size(value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: we use 4-space indentation in this project.

@alubbe
Copy link
Contributor Author

alubbe commented Jun 2, 2016

The function body now uses 4 spaces instead of 2

@alubbe alubbe changed the title WIP: Add jit_stack_size option Add jit_stack_size option Jun 11, 2016
@alubbe
Copy link
Contributor Author

alubbe commented Jun 14, 2016

Regarding tests for resty-core, can we reuse the tests from lua-nginx-module's repo somehow or do you want me to copy them over to this PR?

@agentzh
Copy link
Member

agentzh commented Jun 14, 2016

@alubbe Yes, we can run ngx_lua's test suite using lua-resty-core by specifying the following environment beforehand:

export TEST_NGINX_INIT_BY_LUA="package.path = '$PWD/../lua-resty-core/lib/?.lua;$PWD/../lua-resty-lrucache/lib/?.lua;;' .. (package.path or '') require 'resty.core'"

assuming that lua-resty-core and lua-resty-lrucache are cloned in the same (parent) directory as ngx_lua.

@alubbe
Copy link
Contributor Author

alubbe commented Jun 14, 2016

Awesome, they pass locally.
So, this PR does not need additional tests, correct?
What is your opinion on the status of openresty/lua-nginx-module#782?

@agentzh
Copy link
Member

agentzh commented Jun 14, 2016

@alubbe I think we still need some test cases to ensure that this new Lua API is indeed JIT compiled, as with the existing tests of this project.

@@ -135,6 +135,9 @@ ffi.cdef[[
unsigned char *dst);

uint32_t ngx_http_lua_ffi_max_regex_cache_size(void);

void ngx_http_lua_ffi_set_jit_stack_size(int size);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we remove this empty line?

@alubbe
Copy link
Contributor Author

alubbe commented Jun 15, 2016

I've updated this PR to include the exact same functionality and error messages as the other PR.

@agentzh
Copy link
Member

agentzh commented Jun 16, 2016

@alubbe I think we still need a simple test to ensure LuaJIT's JIT compiler does not complain about any NYI when running this API function in a loop (see other tests for such examples). Thanks!

@alubbe
Copy link
Contributor Author

alubbe commented Jun 30, 2016

I've been thinking about this for a while, and, if possible, I'd simply like to re-run all find, match and sub tests with this option enabled. It would take care of NYI checks and other potential issues that we might have missed. Is there a simple way of doing this or do we need to duplicate every single test? If the latter, maybe we should add only one test per test file.

@agentzh
Copy link
Member

agentzh commented Jun 30, 2016

@alubbe I think you can just write typical tests. I don't mind duplications in the test suite since tricky tests often hide bugs of their own :) Simplicity takes preference in testing.

@alubbe
Copy link
Contributor Author

alubbe commented Jul 7, 2016

I have added two NYI tests. Presumely, they can't pass until openresty/lua-nginx-module#782 is merged, right?

@alubbe alubbe force-pushed the jit_stack_size branch 2 times, most recently from 55e1a7b to 59bcec0 Compare July 22, 2016 11:50
@alubbe
Copy link
Contributor Author

alubbe commented Jul 22, 2016

I've updated the travis file to use my other branch. The PCRE allocation fails, even though it works locally on my machine (I ran a minimal example, not the test suite). Could you help me figure out what's going on?

Also, my perl-foo was not strong enough to add a switch to use ngx.re.opt only for the last two tests. Or do you want to create a whole new file for these tests?

Beyond those two points, this PR should be finished - it's been working fine in production for several weeks now.

@alubbe
Copy link
Contributor Author

alubbe commented Aug 3, 2016

ping @agentzh
if you're busy just let me know

t/re-find.t Outdated
--- config
location = /re {
access_log off;
content_by_lua '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New tests should always use the *_by_lua_block {} form :)

@agentzh
Copy link
Member

agentzh commented Nov 13, 2016

@alubbe I see the tests in Travis CI are failing. Maybe you should rebase your lua-resty-core and lua-nginx-module branches to the their latest masters?

@alubbe
Copy link
Contributor Author

alubbe commented Nov 13, 2016

I have just rebased, but the issues are still the same as described in #44 (comment) and openresty/lua-nginx-module#782 (comment)
Specifically, the init_by_lua handler fails in this test run (even though it works fine in 'real' code. If possible, I'd have it so that all test in that file run twice, with and without a changed jit_stack_size. But I cannot figure out how to do that.

@agentzh
Copy link
Member

agentzh commented Nov 13, 2016

@alubbe What I'm seeing in your lua-resty-core PR's travis CI report is actually a compilation error:

https://travis-ci.org/openresty/lua-resty-core/jobs/175504983

Please provide links to the travis CI report you're talking about. I'm not sure what you mean here.

@agentzh
Copy link
Member

agentzh commented Nov 13, 2016

@alubbe

If possible, I'd have it so that all test in that file run twice, with and without a changed jit_stack_size. But I cannot figure out how to do that.

Maybe you'll find the repeat_each(N) thing helpful? Though I'm not sure what exactly you mean here.

@alubbe
Copy link
Contributor Author

alubbe commented Apr 29, 2017

It broke because of the new commit removing the empty lines from the test files - rebased!

@agentzh
Copy link
Member

agentzh commented May 5, 2017

@alubbe Merged with the following extra patch. Thanks!

diff --git a/.travis.yml b/.travis.yml
index 5c70fc8..f99be4c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -56,7 +56,7 @@ install:
   - git clone https://github.com/openresty/openresty.git ../openresty
   - git clone https://github.com/openresty/nginx-devel-utils.git
   - git clone https://github.com/simpl/ngx_devel_kit.git ../ndk-nginx-module
-  - git clone -b pcre_jit_stack_size https://github.com/alubbe/lua-nginx-module.git ../lua-nginx-module
+  - git clone https://github.com/openresty/lua-nginx-module.git ../lua-nginx-module
   - git clone https://github.com/openresty/no-pool-nginx.git ../no-pool-nginx
   - git clone https://github.com/openresty/echo-nginx-module.git ../echo-nginx-module
   - git clone https://github.com/openresty/lua-resty-lrucache.git
diff --git a/lib/ngx/re.lua b/lib/ngx/re.lua
index 93e29c9..28e9ed0 100644
--- a/lib/ngx/re.lua
+++ b/lib/ngx/re.lua
@@ -36,8 +36,8 @@ local split_ctx = new_tab(0, 1)
 
 
 ffi.cdef[[
-    int ngx_http_lua_ffi_set_jit_stack_size(int size, unsigned char *errstr,
-                                            size_t *errstr_size);
+int ngx_http_lua_ffi_set_jit_stack_size(int size, unsigned char *errstr,
+    size_t *errstr_size);
 ]]
 
 
@@ -235,8 +235,8 @@ end
 function _M.opt(option, value)
     if option == "jit_stack_size" then
         if not is_regex_cache_empty() then
-            return error("changing jit stack size is not allowed when some " ..
-                         "regexs have already been compiled and cached")
+            error("changing jit stack size is not allowed when some " ..
+                  "regexs have already been compiled and cached")
         end
 
         local errbuf = get_string_buf(MAX_ERR_MSG_LEN)
@@ -247,13 +247,12 @@ function _M.opt(option, value)
 
         if rc == FFI_OK then
             return
-
-        else
-            return error(ffi_str(errbuf, sizep[0]))
         end
+
+        error(ffi_str(errbuf, sizep[0]))
     end
 
-    return error("unrecognized option name")
+    error("unrecognized option name")
 end
 
 
diff --git a/lib/ngx/re.md b/lib/ngx/re.md
index 153daba..c1df8ed 100644
--- a/lib/ngx/re.md
+++ b/lib/ngx/re.md
@@ -176,7 +176,7 @@ The `jit_stack_size` cannot be set to a value lower than PCRE's default of 32K.
 
 This method requires the PCRE library enabled in Nginx.
 
-This feature was first introduced in the `XXX` release.
+This feature was first introduced in the `v0.1.12` release.
 
 [Back to TOC](#table-of-contents)
 
diff --git a/t/re-find.t b/t/re-find.t
index b896949..772ec3b 100644
--- a/t/re-find.t
+++ b/t/re-find.t
@@ -260,4 +260,3 @@ matched: 234
 NYI
 --- error_log eval
 qr/\[TRACE   \d+ content_by_lua\(nginx\.conf:\d+\):4 loop\]/
-
diff --git a/t/re-opt.t b/t/re-opt.t
index d2bda46..18f66a3 100644
--- a/t/re-opt.t
+++ b/t/re-opt.t
@@ -69,12 +69,13 @@ __DATA__
 error: pcre_exec() failed: -27
 --- no_error_log
 [error]
+--- timeout: 10
 
 
 
 === TEST 2: increase jit_stack_size
 --- http_config eval
-<<_EOC_;
+qq{
     lua_package_path "$::pwd/lib/?.lua;../lua-resty-lrucache/lib/?.lua;;";
     init_by_lua_block {
         -- local verbose = true
@@ -97,7 +98,7 @@ error: pcre_exec() failed: -27
         local ngx_re = require "ngx.re"
         ngx_re.opt("jit_stack_size", 128 * 1024)
     }
-_EOC_
+}
 --- config
     location /re {
         content_by_lua_block {
@@ -124,6 +125,7 @@ from: 1
 to: 1563
 --- no_error_log
 [error]
+--- timeout: 10
 
 
 
@@ -153,6 +155,7 @@ qr/changing jit stack size is not allowed when some regexs have already been com
 
 --- grep_error_log_out eval
 ["", "changing jit stack size is not allowed when some regexs have already been compiled and cached\n"]
+--- timeout: 10
 
 
 
@@ -169,7 +172,8 @@ qr/changing jit stack size is not allowed when some regexs have already been com
     }
 --- request
     GET /re
---- response_body
-unrecognized option name
+--- response_body_like chomp
+unrecognized option name$
 --- no_error_log
 [error]
+--- timeout: 10

@agentzh agentzh closed this May 5, 2017
@alubbe
Copy link
Contributor Author

alubbe commented May 5, 2017

Perfect, it's been a long journey :D
Thanks again for all of your input and patience with me!

@alubbe alubbe deleted the jit_stack_size branch May 5, 2017 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants