-
Notifications
You must be signed in to change notification settings - Fork 2k
add exit_worker_by* feature #927
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
Conversation
@lixianliang Thank you for your contribution! But please use English instead of Chinese. Thanks for your cooperation! |
src/ngx_http_lua_module.c
Outdated
0, | ||
(void *) ngx_http_lua_exit_worker_by_inline }, | ||
|
||
{ ngx_string("exit_worker_by_lua"), |
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.
Nice work!
I believe the newly added Lua handlers should only use the by_block
form though, as per the ssl_certificate_by_lua_block
demonstrates?
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 believe you would also need to update ngx_http_lua_{phase | common | util}.c
to introduce this new phase context? As well as setting the context itself? I could be wrong.
I believe it will also be requested of you that you introduce tests for this feature.
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 reference to init_worker_by*, there have three method(init_worker_by_lua init_worker_by_lua_block init_worker_by_lua_file)
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.
Yes, the init_worker
phase was introduced before the *_by_lua_block
form and as of today, this module still maintains the older *_by_lua
form for backwards compatibility reasons. However, newly introduced phases (as the ssl_certificate
one) are only implemented in the *_by_lua_block
form.
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.
Hey, on the bright side of things, it's less work for you ;)
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.
ok,thank you. i will add this.
sorry,my english very pool,i need help。latter i will push request again。 |
src/ngx_http_lua_exitworkerby.c
Outdated
@@ -0,0 +1,60 @@ | |||
|
|||
/* | |||
* Copyright (C) Xianliang Li |
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.
For this patch to merge, you have to grant your copyright to the authors of this module. So please remove this copyright notice comment.
src/ngx_http_lua_module.c
Outdated
0, | ||
(void *) ngx_http_lua_exit_worker_by_inline }, | ||
|
||
{ ngx_string("exit_worker_by_lua"), |
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.
Newly added directives should only provide the *_by_lua_block
and *_by_lua_file
forms. Please remove this exit_worker_by_lua
directive. Thank you.
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.
enen,i will correction this。
|
||
lmcf->exit_worker_src.data = name; | ||
lmcf->exit_worker_src.len = ngx_strlen(name); | ||
} else { |
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.
Style: we need a blank line before the } else {
line. See other similar places in the existing code base. Thank you!
Some other suggestions:
Thanks! |
@thibaultcha Thanks for your review! Next time I'll just wait :) |
@agentzh no problem, I think both of use jumped on this at the same time :) side note: quite excited to see this as I was thinking about making the same contribution recently :) Just happy to help. |
@lixianliang At some point, you will also be asked to write the documentation for this new phase handler. If you don't feel comfortable enough for providing an English version, I'd be happy to help you. |
src/ngx_http_lua_exitworkerby.h
Outdated
ngx_int_t ngx_http_lua_exit_worker_by_file(ngx_log_t *log, | ||
ngx_http_lua_main_conf_t *lmcf, lua_State *L); | ||
|
||
void ngx_http_lua_exit_worker(ngx_cycle_t *cycle); |
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.
it only needs one space between void
and ngx_http_lua_exit_worker
Hi, I want to add exit_worker feature, This function runs the specified Lua code upon every Nginx worker process's exiting when the master process is enabled. This hook is often used to release resources when init_worker_by* create resources, To prevent the worker exit abnormal |
src/ngx_http_lua_exitworkerby.c
Outdated
|| lmcf->exit_worker_handler == NULL | ||
|| lmcf->lua == NULL) | ||
{ | ||
return; |
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.
there should be 8 spaces.
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.
ok。
t/151-exit-worker.t
Outdated
@@ -0,0 +1,60 @@ | |||
# vim:set ft= ts=4 sw=4 et fdm=marker: | |||
|
|||
use Test::Nginx::Socket 'no_plan'; |
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.
use plan tests
is more better, its the default way.
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.
sorry, i frist use test-nginx,so something not good.
=== TEST 1: simple exit_worker_by_lua_block | ||
--- http_config | ||
exit_worker_by_lua_block { | ||
ngx.log(ngx.NOTICE, "log from exit_worker_by_lua_block") |
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.
we need to confirm if the log is output
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 fix 151-exit-worker.t base on iresty/test-nginx and commited.
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.
@lixianliang Apparently iresty/test-nginx
is a fork and does not count here :) That feature needs to be merged into the official test-nginx
repo before this can be merged otherwise the Travis CI would be failing.
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.
Yes, Now i use offical test-nginx.
t/151-exit-worker.t
Outdated
--- http_config | ||
exit_worker_by_lua_block { | ||
ngx.log(ngx.NOTICE, "log from exit_worker_by_lua_block") | ||
-- grep_error_log chop |
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.
We'd better delete useless lines from 18-23
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 met a problem when write exit_worker test。this log print when worker process eixtting
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 have submitted a PR openresty/test-nginx#52
You can make the test case with this version.
Here is the example:
=== TEST 1:
--- http_config
--- config
location /t {
echo "ok";
}
--- request
GET /t
--- stop_after_request
--- error_log
received, shutting down
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 make test base on iresty/test-nginx and resubmit 151-exit-worker.t
fix code style |
README.markdown
Outdated
|
||
[Back to TOC](#directives) | ||
|
||
exit_worker_by_lua_block |
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.
Typo? Should be _by_lua_file
here instead, right?
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.
My mistake.
@@ -1013,6 +1013,8 @@ Directives | |||
* [init_worker_by_lua](#init_worker_by_lua) |
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.
BTW, this file is automatically generated (you can check out the comment at the beginning of this file).
You should edit doc/HttpLuaModule.wiki
file instead and use the ngx-releng
tool chain to update this markdown file automatically from the .wiki
file.
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.
ok
t/151-exit-worker.t
Outdated
--- response_body | ||
ok | ||
--- stop_after_request | ||
--- error_log |
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.
We need to add a --- shutdown_error_log
section instead of abusing the request-time --- error_log
directive and the hacky --- stop_after_request
section IMHO :)
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.
This test cast i update util has shutdown_error_log.
add NGX_HTTP_LUA_CONTEXT_EXIT_WORKER and tests
@membphis can you review this exit_worker feature? |
doc/HttpLuaModule.wiki
Outdated
|
||
Runs the specified Lua code upon every Nginx worker process's exiting when the master process is enabled. | ||
|
||
This hook is often used to release resources when init_worker_by* create resources, To prevent the worker exit abnormal. |
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.
init_worker_by*
=> init_worker_by_lua*
.
Also need <code></code>
around init_worker_by_lua*
.
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.
Also, better add a link to the init_worker_by_lua*
label.
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.
@agentzh I add init_worker_by_lua* label to init_worker_by_lua_block not init_worker_by_lua. I want recommend others use init_worker_by_lua_block. It has a problem?
t/152-hup-master-on-exit-worker.t
Outdated
GET /t | ||
--- response_body | ||
ok | ||
--- shutdown_error_log |
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.
Do we have shutdown_error_log
already? It seems that your test plan above explicitly excludes this check.
@membphis I think you were working on this feature for Test::Nginx?
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.
@agentzh shutdown_error_log already use.
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.
shutdown_error_log
does not support the TEST_NGINX_USE_HUP
flag.
TEST_NGINX_USE_HUP
needs to keep nginx working, shutdown_error_log
needs nginx shutdown.
They are in conflict.
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.
ok
I have submitted the PR: openresty/test-nginx#58 |
t/151-exit-worker.t
Outdated
--- response_body | ||
ok | ||
--- shutdown_error_log | ||
get 11val: 1000 |
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.
it seems to wrong
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.
OK,I fix, but use --- shutdown_error_log test success,so shutdown_error_log has bug?
t/151-exit-worker.t
Outdated
ok | ||
--- shutdown_error_log | ||
get val: 100 | ||
|
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.
Better remove this blank line.
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.
ok
|
||
repeat_each(2); | ||
|
||
plan tests => repeat_each() * (blocks() * 2); |
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.
Because the official test-nginx does not come with shutdown_error_log
yet and your branch is currently passing the travis ci tests completely, which means this test plan is wrong since it does not count the shutdown_error_log
test in the first place.
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.
Get.
Please rebase to the latest master. Thank you! |
@agentzh fix |
@lixianliang Great! Thank you! We'll look into this shortly. |
@agentzh |
@lixianliang Will take care of this as soon as I can manage. Sorry for the delay on my side! |
@agentzh ok,Thanks |
@agentzh @doujiang24 it seem other guy need this feature too, openresty/openresty#597, will we merge it into master in future? |
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.
@lixianliang Sorry for the long delay, will you please rebase to the latest master? there are some conflicts, thanks :)
ngx_str_t *value; | ||
ngx_http_lua_main_conf_t *lmcf = conf; | ||
|
||
dd("enter"); |
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.
better use more meaning use debug message here. people will see this message in the error log when they opened the DDEBUG.
This pull request is now in conflict :( |
Thanks, already merged in #1682. |
I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.
你好,我在使用ngx_lua的场景中是一些图片计算或GPU(ai)计算,在init_worker_by阶段会初始GPU或图片Caffe资源,当进行reload的时候,由于worker process exit没有去清理GPU或者Caffe内部的资源,会导致worker出现core,所以我针对此请求再ngx_lua添加了exit_worker_by阶段。希望eixt_worker_by能合并到master。我相信其他的使用者也有可能会用此功能。
我们的技术堆栈为 nginx + lua + (imagexxx.so | aixxx.so ==> 会封转成lua扩展)