Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Connections not getting released or reused #42

Open
joerussbowman opened this issue Feb 9, 2012 · 4 comments
Open

Connections not getting released or reused #42

joerussbowman opened this issue Feb 9, 2012 · 4 comments

Comments

@joerussbowman
Copy link

I've set up a simple asyncmongo/zeromq router to act as a message queue as well as manage writes to my datastore.

what I'm finding is that the connections are getting released or reused, so it eventually hits maxconnections and stops.

Here's what I'm working with. You can pass a few messages then it stops and starts throwing TooManyConnections

#!chatforus-ve/bin/python
# -*- coding: utf-8 -*-
#
# Copyright 2011 Joseph Bowman
#
# Posting this in a Google group so I guess
# it's public domain now.
#
import asyncmongo
import zmq
from zmq.eventloop import ioloop, zmqstream
from tornado import escape
from tornado import gen
import datetime

loop = ioloop.IOLoop.instance()

db = asyncmongo.Client(pool_id='mydb', host='127.0.0.1', port=27017, maxconnections=5, dbname='chatforus')

ctx = zmq.Context()
receiver = ctx.socket(zmq.PULL)
broadcast = ctx.socket(zmq.PUSH)
receiver.bind('tcp://127.0.0.1:5555')
broadcast.bind('tcp://127.0.0.1:5556')
receiver_stream = zmqstream.ZMQStream(receiver, loop)
broadcast_stream = zmqstream.ZMQStream(broadcast, loop)

@gen.engine
def handle_message(msg):
    broadcast_stream.send(msg[0]) 
    message = escape.json_decode(msg[0]) 
    if message["type"] == "msg":
        message["ts"] = datetime.datetime.now()
        (response,), error = yield gen.Task(db.msgs.insert, message)

receiver_stream.on_recv(handle_message)

loop.start()
@FlorianLudwig
Copy link

Hi,

did you find a solution or workaround for this problem?

@FlorianLudwig
Copy link

Sorry for the noise. I just want to add that #45 contains a pull request that solves this issue.

Maybe this issue can be closed in favor of #45.

@joerussbowman
Copy link
Author

Hi thanks for following up on this issue. I ended up changing the way I deployed asycnmongo but I can't recall what all I did at this time. I won't have access to that code for a couple days. If there's an pull request that already fixes this, then it might be better if that's chosen.

@ceymard
Copy link

ceymard commented Apr 24, 2012

#45 is precisely to fix this particular issue. It is deployed in production for a product of mine a has so far worked...

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

No branches or pull requests

3 participants