Hello!
On Sat, Aug 25, 2012 at 12:33 PM, Tzury Bar Yochay wrote:
> I wonder about optimal values shall be used at set_timeout and set_keepalive
> if every seconds, several thousands of requests are sent to the redis over
> this cosocket API.
These highly depend on the characteristics of your Redis queries and
the data set in your Redis store. So you should monitor the actual
concurrency level of your Redis connections and general latency
distribution in your production systems using various utilities
available on your operating system and adjust the configurations
accordingly.
I may write a tutorial on this topic using tools available on Linux to
demonstrate this with an example sometime in the future :) This could
be fun!
> Also, is the fact that `:init_pipeline()` discards existing cached commands
> make it unsafe to use in such load as current function execution will
> discard previous-not-yet-committed commands?
>
It is safe as long as you always call commit_pipeline or
cancel_pipeline before calling init_pipeline on the current
resty.redis instance.
> Assume the following pcode, note the redis_client variable placed on the
> module level and shared among all instances of the function
>
> local redis_client = redis:new()
> redis_client:set_timeout(500)
>
Oh, no! You should never never save the resty.redis instances on the
Lua module level!
If you do that, the resty.redis instances will be shared among all the
concurrent requests handled by nginx, leading to access conflicts of
the underlying cosockets. Consider that several requests attempt to
read from or write to the same socket, which is a disaster. When such
bad things happen, you will usually get the "socket busy" error when
operating on your resty.redis instances.
So always checking the return values of every method call on the
instance is really good idea. And ensure that you always create
separate resty.redis instance for every individual request. For
example, you can store the resty.redis instance into your function or
code chunk's local Lua variables, or a slot in the ngx.ctx special
table.
This also applies to other lua-resty-* libraries like
lua-resty-memcached, lua-resty-mysql, and lua-resty-dns :)
Best regards,
-agentzh