Redis Get key takes 250 milliseconds with aioredis

177 views
Skip to first unread message

raghavan p

unread,
May 28, 2020, 5:50:29 PM5/28/20
to Redis DB
I connect to redis using aioredis as below and measure the GET time.

    conn = await aioredis.create_connection(
        os
.getenv('REDIS_URI'), password=os.getenv('REDIS_PASSWORD')
   
)
    t1
= time.time()
    val
= await conn.execute('GET', 'testkey') #value is b'Hello'
   
print(time.time() -t1) # prints 0.2516293525695801


Everytime, I get response as around 250 milliseconds. Whereas, if I execute below in redis-cli, I see the result in 3 microseconds

 
  redis redis-PORT.*-centrMULTI
    OK
    redis redis
-PORT.*-centrTIME
    QUEUED
    redis redis
-PORT.*-centrGET testkey
    QUEUED
    redis redis
-PORT.*-centrTIME
    QUEUED
    redis redis
-PORT.*-centrEXEC
   
1) 1) "1590701669"
       
2) "54837"
   
2) "Hello"
   
3) 1) "1590701669"
       
2) "54840"


Is 250 ms just network latency? Is there any way to reduce it?

Itamar Haber

unread,
May 28, 2020, 6:05:09 PM5/28/20
to redi...@googlegroups.com
Hello Raghavan,

It may be that the connection in your snippet isn't actually opened until it is first used (I'm not familiar w/ aioredis personally) - to assert that/work around you can add a call to `PING` just before you start timing and getting the key.

Cheers,

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/redis-db/c9f592d7-1cec-4397-a92f-a9ef0ed6df81%40googlegroups.com.


--

Itamar Haber
Technicalist Evangely

Phone: +972.54.567.9692

Redis Labs



Disclaimer

The information contained in this communication from the sender is confidential. It is intended solely for use by the recipient and others authorized to receive it. If you are not the recipient, you are hereby notified that any disclosure, copying, distribution or taking action in relation of the contents of this information is strictly prohibited and may be unlawful.

This email has been scanned for viruses and malware, and may have been automatically archived by Mimecast Ltd, an innovator in Software as a Service (SaaS) for business. Providing a safer and more useful place for your human generated data. Specializing in; Security, archiving and compliance. To find out more Click Here.

Message has been deleted

raghavan p

unread,
May 28, 2020, 6:21:52 PM5/28/20
to Redis DB
Hi Itamar,

I do not have ping attribute in conn object. I added conn.address and that prints ('x.x.x.x', PORT) - connected host and port which shows its connected before it GETs the key.

    conn = await aioredis.create_connection(
        os
.getenv('REDIS_URI'), password=os.getenv('REDIS_PASSWORD')
    
)
    print(conn.address) 
    t1 
= time.time()

Itamar Haber

unread,
May 29, 2020, 11:09:50 AM5/29/20
to redi...@googlegroups.com
I do not have ping attribute in conn object

I believe there is one actaully: https://aioredis.readthedocs.io/en/v1.3.0/mixins.html#aioredis.Redis.ping

In any case, I can't reproduce this:

❯ python test.py
('::1', 6379)
0.00026106834411621094
❯ cat test.py
import time
import asyncio
import aioredis

async def go():
    conn = await aioredis.create_connection('redis://localhost')

    print(conn.address)
    t1 = time.time()
    val = await conn.execute('GET', 'testkey') #value is b'Hello'
    print(time.time() -t1) # prints 0.2516293525695801

asyncio.run(go())

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.

Benjamin Sergeant

unread,
May 29, 2020, 12:02:23 PM5/29/20
to redi...@googlegroups.com
Shameless plug for my client library, with another asyncio python library (the library does the connection in the timing)
But it's nowhere near 250ms



(venv) examples$ python connect_and_get_key.py
0.006410121917724609
(venv) examples$ python connect_and_get_key.py
0.006173372268676758


'''Connect and get a key

Copyright (c) 2020 Machine Zone, Inc. All rights reserved.
'''

import asyncio
import time
from rcc.client import RedisClient


async def getKey():
    client = RedisClient()

    start = time.time()
    res = await client.send('GET', 'testkey')
    print(time.time() - start)


if __name__ == '__main__':
    asyncio.get_event_loop().run_until_complete(getKey())






Itamar Haber

unread,
May 29, 2020, 12:50:09 PM5/29/20
to redi...@googlegroups.com
Nothing to be ashamed about, the exact opposite in fact @bsergean

Benjamin Sergeant

unread,
May 29, 2020, 1:23:58 PM5/29/20
to redi...@googlegroups.com
Thanks :)

The real reason for writing this was that aioredis still doesn't support redis cluster, and it has been that way for a long time. It's a shame because the library is good quality, but lately the activity is a quite dormant.

Reply all
Reply to author
Forward
0 new messages