Would increasing the limit from 16 to something bigger make this more
easy?  16 was selected arbitrarily by me.

On 15:12 Fri 05 Oct     , Carlo Pires wrote:
>    Just to keep in the archives...
>    I had to poll the control port to check the bytes_written in order to
>    not flood mongrel2.
>    I found out to send data from handler to mongrel2 in chunks of 100K the
>    optimal size
>    in my setup. Big chunks makes M2 very busy and the other tasks almost
>    don't have
>    a chance to run. Small chunks makes M2 to reach the limit of 16 very
>    fast lowering
>    the client bandwidth to very bad levels.
>    How is too simple to hang M2 flooding it from the handler, it would be
>    interesting to have
>    documented how to get around this problem.
>    The relevant part of code is:
>    [code]
>    bytes_sent = 0
>    Â Â Â  Â Â Â  Â Â Â
>    for msg in http_chunked_response(body, code, status, headers):
>    Â Â Â  self.reply(req, msg)
>    Â Â Â  Â Â Â  Â Â Â  Â Â Â
>    Â Â Â  gevent.sleep(0)
>    Â Â Â  if bytes_sent:
>    Â Â Â  Â Â Â  conn_status = self.control.conn_status(int(req.conn_id))
>    Â Â Â  Â Â Â  if conn_status:
>    Â Â Â  Â Â Â  Â Â Â  while conn_status and conn_status[7] < bytes_sent:
>    Â Â Â  Â Â Â  Â Â Â  Â Â Â  log.debug('Waiting mongrel2 deliver
>    data...')
>    Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â
>    Â Â Â  Â Â Â  Â Â Â  Â Â Â  gevent.sleep(.25)
>    Â Â Â  Â Â Â  Â Â Â  Â Â Â  conn_status =
>    self.control.conn_status(int(req.conn_id))
>    Â Â Â  Â Â Â  else:
>    Â Â Â  Â Â Â  Â Â Â  log.error('No response from mongrel2. Is it
>    died?')
>    Â Â Â  Â Â Â  Â Â Â  break
>    Â Â Â  bytes_sent += len(msg)
>    [/code]
>    self.control is a very simple client to m2 control port:
>    [code]
>    class ConnectionControl(object):
>    Â Â Â  def __init__(self, zeromq_context):
>    Â Â Â  Â Â Â  self._control = zeromq_context.socket(zmq.REQ)
>    Â Â Â  Â Â Â  self._control.connect(MONGREL_CONTROL_PORT)
>    Â Â Â  def get(self, cmd, **kwargs):Â Â Â
>    Â Â Â  Â Â Â  self._control.send(tnetstring.dumps([cmd, kwargs]))
>    Â Â Â  Â Â Â  return tnetstring.loads(self._control.recv())
>    Â Â Â
>    Â Â Â  def conn_status(self, conn_id):
>    Â Â Â  Â Â Â  connections = self.get('status', what='net')['rows']
>    Â Â Â  Â Â Â  conn_status = [conn for conn in connections if conn[0] ==
>    conn_id]
>    Â Â Â  Â Â Â  if conn_status:
>    Â Â Â  Â Â Â  Â Â Â  return conn_status[0]
>    [/code]
>    --
>    Â  Carlo Pires

Reply via email to