aiocache icon indicating copy to clipboard operation
aiocache copied to clipboard

Connection pool won't release its free connection to be used after so many timeout errors

Open Hesarn opened this issue 6 years ago • 2 comments

I'm having the same problem as in this issue that you mentioned: https://github.com/aio-libs/aioredis/issues/231

and i also saw this issue too: https://github.com/argaen/aiocache/issues/196

I just make a burst of requests to test my redis with cached decorator of aiocache library and i just set the timeout to be too short to get timeout when performing too many requests. so after this load test, i'm just getting timeout error for every single request on connecting to redis.

but it sounds that aioredis fixed this issue by patching the asyncio.Lock. But i'm having this issue still. so maybe i'm missing something.

Here is the code to reproduce this:

import logging
from aiocache import cached, RedisCache
from aiocache.serializers import PickleSerializer

from sanic import Sanic
from sanic.response import json

logger = logging.getLogger(__name__)


@cached(
        cache=RedisCache,
        namespace="main",
        serializer=PickleSerializer(),
        ttl=10,
        endpoint='127.0.0.1',
        pool_max_size=2,
        pool_min_size=2,
        timeout=0.1,
        create_connection_timeout=0.1
    )
async def handler_get(req):
    return json('hello')


if __name__ == '__main__':
    app = Sanic(log_config=None, configure_logging=None)

    app.add_route(handler_get, '/', ['GET'])
    app.run(host='0.0.0.0', port=8080)
aiocache==0.10.1
aioredis==1.2.0

And then i start load testing with ab: ab -n 10000 -c 1000 http://127.0.0.1:8080/

but after this load test, even a single curl is getting timeout error: curl localhost:8080

As i traced down this issue a little, i found out that after load test, in the ConnecionsPool class of aioredis, the state of connections of the pool is not correct, as there is 2 used connection in _used field of pool instance and there is no free connection at all in _pool(which is a deque).

So i was wondering if you could help me out or if let me know if it's a bug or what.

Thanks

Hesarn avatar Feb 16 '19 16:02 Hesarn

Hmmm weird, the code for patching the Lock is still in aioredis: https://github.com/aio-libs/aioredis/blob/master/aioredis/locks.py

I'll have a look when I can and try to reproduce

argaen avatar Feb 18 '19 16:02 argaen

+1 the same problem

fanjindong avatar Apr 13 '19 15:04 fanjindong

We've migrated to the new redis library now, so maybe not a problem now. Please reopen if you can still reproduce on master (or 0.12 once released).

Dreamsorcerer avatar Jan 01 '23 23:01 Dreamsorcerer