Hello!
On Sat, Apr 18, 2015 at 4:17 AM, joe wrote:
> Our team is doing a poc using aerospike's lua client and openresty. I am
> aware that their c client is synchronous but thought I'd give it a try
> before exploring other options.
Oh that's very bad because while your C client is reading from and
writing to the connection, the whole nginx worker process can do
nothing but block on these I/O operations, which is a disaster.
>
> I read that the module is loaded once when the first request comes in. Does
> this mean that the connection will be created only once?
>
If that Lua module creates the connection upon module loading and
holds it in its module-level variables, then yes, this connection is
created only once upon the first request served by *each* nginx worker
process.
Note that only nginx worker processes serve requests.
> I have 8 worker processes, how does module loading work with the aerospike
> connection and multiple workers?
It is your each nginx worker process serving their own first request,
thus triggering the Lua module loading. So each of your worker
processes loads the Lua module independently.
> I read that workers cannot share data,
Workers *can* share data. See
https://github.com/openresty/lua-nginx-module#lua_shared_dict
though such data excludes sockets.
> does
> this also mean that it cannot share the connection or will each worker
> create a connection?
There is no cheap way of sharing a connection across the process boundary.
> I ideally would like each worker to have its own
> connection and keep them alive.
>
Yes, it is.
Nevertheless I suggest you rewrite the aerospike library with Lua atop
ngx_lua's cosocket API. Thus all the I/O operations are nonblocking
out of the box and you can enjoy the built-in connection pool as well.
Just take a look at the existing client libraries like lua-resty-redis
and lua-resty-mysql. It should be easy.
Best regards,
-agentzh