Python redis client performance

3,087 views
Skip to first unread message

chinatian

unread,
Feb 7, 2012, 10:40:16 PM2/7/12
to Redis DB
Why do I use pure Python redis connection the redis db get speed is
only 10k / s, while redis-benckmark speed to 40k?

Didier Spezia

unread,
Feb 8, 2012, 10:14:01 AM2/8/12
to redi...@googlegroups.com

It may be because redis-benchmark is written in optimized C
which is 50 times faster than pure Python, and/or because
your Python script does not use pipelining or multiple
connections to limit the impact of network latency.

See http://redis.io/topics/benchmarks for more information.

Regards,
Didier.

lsbardel

unread,
Feb 8, 2012, 10:58:15 AM2/8/12
to redi...@googlegroups.com
You may also find an explanation in  http://redis.io/topics/latency

Luca

Josiah Carlson

unread,
Feb 8, 2012, 11:47:19 AM2/8/12
to redi...@googlegroups.com
Are you using the optional hiredis accelerator and pipelines? With a
single connection, I can typically push 70% of redis-benchmark's speed
with Python + redis + hiredis + pipelines.

Regards,
- Josiah

On Tue, Feb 7, 2012 at 7:40 PM, chinatian <taoh...@gmail.com> wrote:
> Why do I use pure Python redis  connection the redis db get speed is
> only 10k / s, while redis-benckmark speed to 40k?
>

> --
> You received this message because you are subscribed to the Google Groups "Redis DB" group.
> To post to this group, send email to redi...@googlegroups.com.
> To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.
>

David Montgomery

unread,
Feb 8, 2012, 11:58:51 AM2/8/12
to redi...@googlegroups.com
Can you show how to use the hiredis accelerator and pipelines for a get and set?

I am new to python redis and will be using it a lot.

Thanks

Didier Spezia

unread,
Feb 8, 2012, 12:20:03 PM2/8/12
to redi...@googlegroups.com
Hi,

to use hiredis, you just have to install the hiredis package on top of the redis python package.
It is then used automatically if it is present.

pip install redis
pip install hiredis

You can find an example of pipelining with Python in the documentation

>>> r = redis.Redis(...)
>>> r.set('bing', 'baz')
>>> # Use the pipeline() method to create a pipeline instance
>>> pipe = r.pipeline()
>>> # The following SET commands are buffered
>>> pipe.set('foo', 'bar')
>>> pipe.get('bing')
>>> # the EXECUTE call sends all buffered commands to the server, returning
>>> # a list of responses, one for each command.
>>> pipe.execute()
[True, 'baz']

Here is another example in a larger script:

Regards,
Didier.

Josiah Carlson

unread,
Feb 8, 2012, 2:22:42 PM2/8/12
to redi...@googlegroups.com
Also, if you want to bypass the multi/exec calls around it, and just
want to buffer your commands, you can use 'r.pipeline(False)' .

Regards,
- Josiah

> --
> You received this message because you are subscribed to the Google Groups
> "Redis DB" group.

> To view this discussion on the web visit
> https://groups.google.com/d/msg/redis-db/-/qQW8AA-TdskJ.

Reply all
Reply to author
Forward
0 new messages