Closed paularmand closed 7 years ago
After looking in the code, the producer:new includes memoization for the async version, so little is gained from instantiating this at a global vm level. We would probably need add a local var pointing to the global table in the content_by_lua anyways for performance reasons. If anyone can shed further insights, please do.
@paularmand Sorry for the delay.
Yes, it's thread-safe for async producer.
But I think you need to init producer in init_worker_by_lua
, because ngx.timer.at
is disabled in int_by_lua
.
And inited producer can be stored in Lua VM level: https://github.com/openresty/lua-nginx-module/#data-sharing-within-an-nginx-worker
In the readme example, a broker is instantiated in the scope of a location. Is it possible to do the require statement in an init_by_lua_block? I have the same question for the bp?
So will the following work as expected, or do you believe it not to be thread-safe ?