master是调用ngx_http_lua_init函数中的
lmcf->lua = ngx_http_lua_init_vm(NULL, cf->cycle, cf->pool, lmcf, cf->log, NULL);
来创建的lua_State;
而worker请求进来的时候是ngx_http_lua_content_handler_file(以content_by_lua_file指令为例)中通过ngx_http_lua_get_lua_vm获取到的lua_State:
lmcf = ngx_http_get_module_main_conf(r, ngx_http_lua_module);是直接从lmcf->lua中取得的lua_State;
综上,我不理解每个worker的lua_State是怎么fork出来的?
在 2017年12月19日星期二 UTC+8下午5:04:15,wanwan yuan写道:
nginx启动时,master进程会调用ngx_http_lua_init创建lua_State,worker进程中当请求进来后,会创建一个co并与请求关联起来,请问一个worker内多个请求是如何实现对lua module内全局变量的共享的?如果可能的话,是否可以通过代码简单说明一下,谢谢