openresty / lua-resty-redis

Lua redis client driver for the ngx_lua based on the cosocket API
1.9k stars 448 forks source link

Disable error logging to nginx error log #26

Open ghost opened 11 years ago

ghost commented 11 years ago

I'm trying to cache errors on connect to a redis instance both by using ok, err = .... and wrapping up the code with a pcall

In both cases still an error line goes to nginx error log. I have a high load application and if a redis instance goes down for a few secs my error log gets flooded with messages. Is there a way around it?

agentzh commented 11 years ago

@liorc11 These error logging is done automatically by the underlying ngx_lua module. You can disable this automatic error logging by putting the following line into the right place in your nginx.conf file:

lua_socket_log_errors off;

See http://wiki.nginx.org/HttpLuaModule#lua_socket_log_errors for more details.

agentzh commented 11 years ago

Just added a new section "Automatic Error Logging" to lua-resty-redis's documentation:

https://github.com/agentzh/lua-resty-redis#automatic-error-logging

This has been a FAQ already :)

ghost commented 11 years ago

I tried adding it both on http, server and location I still get [crit] 72267#0: *306432429 connect() to 127.0.0.1:6381 failed (99: Cannot assign requested address), client: 217.163.21.187, server: 127.0.0.1

It is very easy for me to to reproduce it, as I have a redis with millions of keys, if I just do "keys *" on it I start getting this lines for 10-20 seconds until the system recovers

agentzh commented 11 years ago

Hello!

On Fri, Oct 4, 2013 at 2:53 AM, liorc11 notifications@github.com wrote:

I tried adding it both on http, server and location I still get [crit] 72267#0: *306432429 connect() to 127.0.0.1:6381 failed (99: Cannot assign requested address), client: 217.163.21.187, server: 127.0.0.1

This error is critical and it is generated by the Nginx core. The ngx_lua module cannot disable it on its side.

This error indicates that you've run out of the ephemeral ports. Are you properly enabling the connection pool in lua-resty-redis? See

https://github.com/agentzh/lua-resty-redis#set_keepalive

for how to enable keepalive connection pools for your Redis queries.

Also, you can use the ngx-lua-conn-pools tool to trace the connection pools in any specified nginx worker processes:

https://github.com/agentzh/nginx-systemtap-toolkit#ngx-lua-conn-pools

Regards, -agentzh