evilkost / brukva

Asynchronous Redis client that works within Tornado IO loop.
Other
265 stars 33 forks source link

Client brukva connection #20

Open burakdede opened 12 years ago

burakdede commented 12 years ago
class MessageUpdatesHandler(BaseHandler):
@tornado.web.authenticated
@tornado.web.asynchronous
def post(self):
    self.listing_id = self.get_argument("listing_id", None)
    self.cursor = self.get_argument("cursor", None)
    self.client = brukva.Client()
    self.client.connect()
    self.client.subscribe(self.listing_id)
    self.client.listen(self.on_new_messages)

def on_new_messages(self, messages):
    # Closed client connection
    if self.request.connection.stream.closed():
        return
    msg = json.loads(messages.body,'ascii')
    self.finish(dict(messages=[msg]))
    self.client.unsubscribe(self.listing_id)

def on_connection_close(self):
    # unsubscribe user from channel
    self.client.unsubscribe(self.listing_id)
    self.client.disconnect()

When I long poll using above code and check redis activity seems like when ever client send or posts something it creates new connection, so total connected client increasing on top of each other like 2 client talking and send 10 messages total connected client show 15 or sth like that. Is this bug or should I use different approach while connecting ?

goldalworming commented 12 years ago

what's your command in redis to monitor? I want to test it

burakdede commented 12 years ago

I am not using any special command just checking the redis server output and as I see there are increasing number of client connected in evert post

burakdede commented 12 years ago

@goldalworming did you find anything related to this problem ?

goldalworming commented 12 years ago

how do you paste your code in this commented system?

I couldn't paste it...

goldalworming commented 12 years ago

just see my repo https://github.com/goldalworming/tornado-redis-chat

I use 'monitor' in redis-cli and it works fine (only 2 subscribers) but I got weird error. maybe you could solve it.

burakdede commented 12 years ago

@goldalworming Yeah I do the same thing before but even its working it firing exception about "reading from non-existing connection" and try to listen channel its weird. And its probably related to this issue https://github.com/evilkost/brukva/issues/10