Using @cache.action with Redis takes 10 seconds to return a simple HTTP 503 or 404

28 views
Skip to first unread message

Lisandro

unread,
Jun 6, 2018, 8:45:55 AM6/6/18
to web2py-users
Hi there! I recently upgraded my production environment to web2py 2.16.1, and I'm facing an old issue that was apparently solved.
In my applications I use @cache.action to cache public pages, and as I use Redis for cache, I use it like this:

@cache.action(time_expire=300, cache_model=cache.redis, session=False, vars=False, public=True)
def test():
   
....


Well, I've found that, when the function raises an HTTP 503 or 404, it takes 10 seconds to complete and return the result.
Now, this only happens when cache_model=cache.redis. 
If I change it to cache_model=cache.ram, it takes a few milliseconds to complete as expected.

I'm using Redis 3.2.10 64bit on CentOS7.
The problem had been reported long time ago, and it was also fixed:

I've checked my web2py source code, and it's indeed using the latest stable version 2.16.1, and just in case, I looked at gluon/contrib/redis_cache.py and the fix is there.
However, it appears that the problem still can be reproduced with this code:

from gluon.contrib.redis_cache import RedisCache
from gluon.contrib.redis_session import RedisSession
from gluon.contrib.redis_utils import RConn

_redis_conn
= RConn('localhost', 6379)
cache
.redis = RedisCache(redis_conn=_redis_conn, with_lock=True)

@cache.action(time_expire=300, cache_model=cache.redis, session=False, vars=False, public=True)
def test():
   
raise HTTP(503)


Notice that it always takes 10 seconds, maybe that should bring in some clue about what's happening.
Any suggestion?

Thanks in advance!
Regards, Lisandro

Lisandro

unread,
Jun 6, 2018, 9:16:57 AM6/6/18
to web2py-users
Quick update: apparently the problem doesn't happen using RedisCache(with_lock=False, ...)
Should this be considered a bug or is it the expected behaviour?

I would like to keep with_lock=True but avoid that 10 second delay when a function raises HTTP 503 or 404.
The issue with that delay is that, during that time, the request is using a database connection, and in my environment I have the risk of exhausting db connections.

I'll try to play a bit with the source code of redis_cache.py, but still any suggestion or comment will be much appreciated.
Thanks!

Anthony

unread,
Jun 6, 2018, 9:44:42 AM6/6/18
to web2py-users

Lisandro

unread,
Jun 6, 2018, 9:50:39 AM6/6/18
to web2py-users
Thank you for your fast answer Anthony!
You are right, the problem is fixed in master.
I applied those changes and the problem was solved.

Thank you very much!
Reply all
Reply to author
Forward
0 new messages