Hello!
On Thu, Jul 17, 2014 at 10:01 PM, Vitaly Kosenko wrote:
> reviously in my web-projects I used "mysql" lua-module from
> https://github.com/downloads/keplerproject/luasql/luasql-2.2.0.tar.gz.
This Lua library always blocks the nginx event loop on I/O in the
context of ngx_lua/openresty, and should always be avoided :)
> Now I know about your "resty.mysql" and I want to try it. I read:
>> The resty.mysql object instance cannot be stored in a Lua variable at the
>> Lua module level, because it will then be shared by all the concurrent
>> requests handled by the same nginx worker process
For lua-resty-mysql (and OpenResty in general), the paradigm is not to
share or recycle the Lua cosocket objects directly among different
requests but just to recycle the underlying connections via the
built-in connection pool. In the case of lua-resty-mysql, you should
put your current MySQL connection into the pool via the
set_keepalive() method for other requests to reuse:
https://github.com/openresty/lua-resty-mysql#set_keepalive
(It's worth mentioning that the connect() method always look up the
connection pool for any idle connections before initiating a new
connection. this behavior is also documented:
https://github.com/openresty/lua-resty-mysql#connect )
> 1. Are multiple nginx requests processed concurrently?
Yes, of course. Otherwise it's not scalable at all (we usually run
just 2 or 3 moderate boxes of OpenResty in front of a relatively large
MySQL cluster of a hundred big nodes in production).
> Before I used to
> think that there are a queue of requests in nginx.
>
No.
> 2. If I need to instantiate mysql-connection every requests these would be a
> performance issue. Am I right? (I used luasql as global module variable
> automatically reconnecting it when necessary)
>
Well, you should always use the builtin connection pool, as mentioned above :)
> One more question: Is resty.mysql working in access_by_lua stage?
Yes, of course.
BTW, it's strongly recommended to discuss such details on the
openresty-en mailing list instead:
https://groups.google.com/group/openresty-en Thank you!
Best regards,
-agentzh
P.S. I'm cc'ing the list.