openresty / srcache-nginx-module

Transparent subrequest-based caching layout for arbitrary nginx locations.
http://wiki.nginx.org/NginxHttpSRCacheModule
476 stars 105 forks source link

srcache_store not working with Redis for large files #28

Closed akamatgi closed 10 years ago

akamatgi commented 10 years ago

Hi, I am running nginx-1.4.5 with the HttpSRCache module and using redis as the backend.

srcache-module version: v0.26 ngx_redis2 version: v0.10 echo-nginx version: v0.50 ngx_set_misc version: v0.24

my nginx.conf (snippet) is: location / { set $key $uri; set_escape_uri $escaped_key $key;

    srcache_fetch GET /redis2-get $key;
    srcache_store PUT /redis2-set key=$escaped_key&exptime=3600;

    proxy_pass http://backend;

} location = /redis2-get { internal;

    redis2_query get $arg_key
    redis2_pass <redis_server_ip>:6379;
}

location = /redis2-set {
    internal;

    set_unescape_uri $exptime $arg_exptime;
    set_unescape_uri $key $arg_key;
    set_md5 $key;

    proxy_set_header  Accept-Encoding  "";

    redis2_query set $key $echo_request_body;
    redis2_query expire $key $exptime;
    redis2_pass <redis_server_ip>:6379;
}

I am seeing that when the response is small ( currently I am seeing anything < 1K ), it gets stored on the redis server.

However, when I am fetching a bigger response( currently I am seeing issues with anything > 100K ), everything seems fine, i.e I can see the nginx doing a 'set' on the redis server, but nothing gets stored on the redis.

Is there any size limitation? Can I see any logs to debug this issue? Right now, I see nothing in the nginx or the redis logs.

Is there any known issue? Thanks in advance. -anirudh

akamatgi commented 10 years ago

Also, the redis server version is 2.8.8, running in standalone mode.

agentzh commented 10 years ago

@akamatgi Please enable the NGINX debug logging and check the outputs: http://nginx.org/en/docs/debugging_log.html

akamatgi commented 10 years ago

Hi @agentzh, I enabled the debug logs and found this entry in the logs: 2014/04/20 10:14:28 [info] 18423#0: *21 client prematurely closed connection, so upstream connection is closed too while sending request to upstream, ... The corresponding packet dump revealed that the client( in this case, wget ) was closing the connection before nginx could send the complete request to redis. With curl, I am not seeing the issue. So, it is wget which is the culprit. Thanks for your help.

akamatgi commented 10 years ago

@agentzh Even though I closed this issue, I have a doubt here. Why is the subrequest getting closed when the client connection closes? Is there no way to tie them up, i.e client connection should wait for all subrequests to complete. Thanks, -anirudh

agentzh commented 10 years ago

@akamatgi Thank you for the report! I've just committed a fix to ngx_redis2's git master branch to ignore client aborts. Will you try it out on your side?

akamatgi commented 10 years ago

Yes, it works now. Thanks for the fix, @agentzh