Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Making a connection class of redis.py for Tornado
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Chris  
View profile  
 More options Nov 1 2012, 10:28 am
From: Chris <bhp...@gmail.com>
Date: Thu, 1 Nov 2012 07:28:00 -0700 (PDT)
Subject: Making a connection class of redis.py for Tornado

The python redis client, redis.py, uses hiredis for parsing, which gives
itself considerable performance advantage over some other async redis
libraries.

However, redis.py is blocking, which goes against Tornado's design. To make
it work better with Tornado, the author of redis.py has suggested something
on the redis google group:

To make redis-py work well with Tornado, I believe all you'd have to do is

> implement your own Connection class, using whatever async socket calls
> Tornado provides. Take a look at redis-py/redis/connection.py. With
> redis-py, you can easily tell the client what connection class you want to
> use in your app by passing the "connection_class" argument to either a
> ConnectionPool, or to the base Redis class itself.

However, it seems like no one has implemented this. Can someone point some
direction about how we can do this for Tornado?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Serge S. Koval  
View profile  
 More options Nov 1 2012, 10:39 am
From: "Serge S. Koval" <serge.ko...@gmail.com>
Date: Thu, 1 Nov 2012 16:39:19 +0200
Local: Thurs, Nov 1 2012 10:39 am
Subject: Re: [tornado] Making a connection class of redis.py for Tornado

There's toredis, which uses hiredis parser. I made small fork of original
toredis with some bug fixes and disabled connection pooling, as I needed
PUB/SUB: https://github.com/mrjoes/toredis/

There are no examples and documentation and it follows original redis spec
for most of the commands. If there's need for docs/examples, I can make
some.

Serge.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris  
View profile  
 More options Nov 1 2012, 11:59 am
From: Chris <bhp...@gmail.com>
Date: Thu, 1 Nov 2012 08:59:05 -0700 (PDT)
Local: Thurs, Nov 1 2012 11:59 am
Subject: Re: [tornado] Making a connection class of redis.py for Tornado

Is it easy to switch the connection pooling back on? Or make it
configurable? At the moment, I don't need PUB/SUB, so connection pooling
would be nice!

Some small examples of using it would be great, as I find hardly any in the
original toredis repository. Thanks.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Serge S. Koval  
View profile  
 More options Nov 1 2012, 12:12 pm
From: "Serge S. Koval" <serge.ko...@gmail.com>
Date: Thu, 1 Nov 2012 18:12:00 +0200
Subject: Re: [tornado] Making a connection class of redis.py for Tornado

It depends why you need connection pooling.

If you're using redis blocking operations, like BLPOP, you still need
separate connection, which you can create and use it for that operation.
If you're not using blocking operations, you just use one connection for
your application.

I will add pooling on top, but don't have any deadline.

Small example how to use:
https://github.com/mrjoes/toredis/blob/master/tests/test_handler.py

Serge.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris  
View profile  
 More options Nov 1 2012, 12:44 pm
From: Chris <bhp...@gmail.com>
Date: Thu, 1 Nov 2012 09:44:04 -0700 (PDT)
Local: Thurs, Nov 1 2012 12:44 pm
Subject: Re: [tornado] Making a connection class of redis.py for Tornado

> It depends why you need connection pooling.

Hi serge, i guess you're the best person to confirm this: i think
connection pooling would benefit multiple sockjs-tornado clients. In other
words, instead of having one redis connection for each connected client,
they share a connection pool. Would that work?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Serge S. Koval  
View profile  
 More options Nov 1 2012, 12:57 pm
From: "Serge S. Koval" <serge.ko...@gmail.com>
Date: Thu, 1 Nov 2012 18:57:37 +0200
Local: Thurs, Nov 1 2012 12:57 pm
Subject: Re: [tornado] Making a connection class of redis.py for Tornado

Hi,

Redis is single-threaded, it can't run more than one operation at the same
time. So, if you only use operations that return results immediately (GET,
SET, PUBLISH, etc), it does not matter if you open one connection to redis
or use connection pool.

However, it makes difference if you have redis cluster and distribute
requests between two servers. For this, connection pool will be more
efficient, as it will manage connections internally and you don't have to
worry about managing them yourself.

If you use blocking operations, SUBSCRIBE, etc - you will need per-client
redis connection.

To summarise: it is perfectly fine to open one redis connection to serve
all SockJS clients as long as they don't use any blocking commands (BLPOP,
BRPOP, SUBSCRIBE, etc).

Serge.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris  
View profile  
 More options Nov 1 2012, 1:43 pm
From: Chris <bhp...@gmail.com>
Date: Thu, 1 Nov 2012 10:43:55 -0700 (PDT)
Local: Thurs, Nov 1 2012 1:43 pm
Subject: Re: [tornado] Making a connection class of redis.py for Tornado

> To summarise: it is perfectly fine to open one redis connection to serve
> all SockJS clients as long as they don't use any blocking commands (BLPOP,
> BRPOP, SUBSCRIBE, etc).

Ok, as I am only using commands like sadd, hset etc, and pipelining (I
don't think that is blocking), I think i'm good to use a single redis
connection for all connected sockjs clients. To confirm, this means that I
create a class-level variable such as 'redis_conn' inside my
SockJSConnection class, which will then be shared by all connected SockJS
clients afterwards.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Grigorev  
View profile  
 More options Nov 1 2012, 1:44 pm
From: Andrew Grigorev <and...@ei-grad.ru>
Date: Thu, 01 Nov 2012 21:44:12 +0400
Local: Thurs, Nov 1 2012 1:44 pm
Subject: Re: [tornado] Making a connection class of redis.py for Tornado
Hi!

I work on a more advanced version of the toredis, with a proper
connection pooling and pythonic API: https://github.com/ei-grad/toredis

Usage example: https://bitbucket.org/eigrad/passage/src/master/models.py

It also uses a monkey-patching to add a @task decorator to the
toredis.commands.RedisCommandsMixin methods. Equivalent decorator looks
to be added into the 3.X.X version of tornado 3, and I'll add it to the
toredis source code in future. So I suggest you to use it too.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Grigorev  
View profile  
 More options Nov 1 2012, 1:46 pm
From: Andrew Grigorev <and...@ei-grad.ru>
Date: Thu, 01 Nov 2012 21:46:29 +0400
Local: Thurs, Nov 1 2012 1:46 pm
Subject: Re: [tornado] Making a connection class of redis.py for Tornado
01.11.2012 18:39, Serge S. Koval пишет:

> If there's need for docs/examples, I can make some.

It would be cool.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »