Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give chance to reuse connection for sequential CMDs #225

Closed
argaen opened this issue May 12, 2017 · 1 comment
Closed

Give chance to reuse connection for sequential CMDs #225

argaen opened this issue May 12, 2017 · 1 comment
Labels
Milestone

Comments

@argaen
Copy link
Member

argaen commented May 12, 2017

In codes like

            await redis_cache.set("hi", "value")
            await redis_cache.get("hi")
            await redis_cache.delete("hi")

backend acquires and releases the connection from the pool every time which adds extra cost. In aioredis, reusing the same connection or acquiring (even when its the same) almost doubles the time.

Usage could be some like:

with redis_cache as conn:
    await conn.set()
    ...

With memory it doesn't make sense but to keep compatibility it will return itself. Its also possible to do it with memcached (although haven't checked the difference).

@argaen argaen added the feature label May 12, 2017
@argaen argaen added this to the 0.6.0 milestone May 12, 2017
@argaen argaen changed the title Give change to reuse connection for sequential CMDs Give chance to reuse connection for sequential CMDs May 12, 2017
@argaen
Copy link
Member Author

argaen commented May 13, 2017

Couple of problems:

  • Due to bad design of memcached its not possible to do that. When calling memcached CMD commands, they retrieve the connection everytime (https://github.com/aio-libs/aiomcache/blob/master/aiomcache/client.py#L13). Code should be changed so a connection can be passed
  • With redis we can retrieve the conn object, but still we want to apply the namespacing, plugin calls, serializers, etc. So its not easy as thought

Also in case of redis, the pool should be initialized in the constructor so we avoid calling the get_connection when the pool is None:

    @pytest.mark.asyncio
    async def test_single_connection(self, cache):
>       async with cache.get_connection() as conn:

tests/acceptance/test_base.py:133: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
aiocache/base.py:457: in __aenter__
    self._conn = await self._pool.acquire()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = RedisCache (127.0.0.1:6379)

    async def acquire(self):
>       return await self._pool.acquire()
E       AttributeError: 'NoneType' object has no attribute 'acquire'

https://github.com/argaen/aiocache/tree/feature_%23225/reuse_connections

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant