Maximum clients reached on Heroku and Redistogo Nano - heroku

I am using celerybeat on Heroku with RedisToGo Nano addon
There is one web dyno and one worker dyno
The celerybeat worker is set to perform a task every minute.
The problem is: Whenever I deploy a new commit, dynos restart, and I get this error
2014-02-27T13:19:31.552352+00:00 app[worker.1]: Traceback (most recent call last):
2014-02-27T13:19:31.552352+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/celery/worker/consumer.py", line 389, in start
2014-02-27T13:19:31.552352+00:00 app[worker.1]: self.reset_connection()
2014-02-27T13:19:31.552352+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/celery/worker/consumer.py", line 727, in reset_connection
2014-02-27T13:19:31.552352+00:00 app[worker.1]: self.connection = self._open_connection()
2014-02-27T13:19:31.552352+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/celery/worker/consumer.py", line 792, in _open_connection
2014-02-27T13:19:31.552352+00:00 app[worker.1]: callback=self.maybe_shutdown)
2014-02-27T13:18:23.864287+00:00 app[worker.1]: self.on_connect()
2014-02-27T13:18:23.864287+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/redis/connection.py", line 263, in on_connect
2014-02-27T13:18:23.864287+00:00 app[worker.1]: if nativestr(self.read_response()) != 'OK':
2014-02-27T13:18:23.864287+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/redis/connection.py", line 314, in read_response
2014-02-27T13:18:23.864287+00:00 app[worker.1]: raise response
2014-02-27T13:18:23.864287+00:00 app[worker.1]: ResponseError: max number of clients reached
2014-02-27T13:19:31.552352+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 272, in ensure_connection
2014-02-27T13:19:31.552352+00:00 app[worker.1]: interval_start, interval_step, interval_max, callback)
2014-02-27T13:19:31.552591+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/utils/__init__.py", line 218, in retry_over_time
2014-02-27T13:19:31.552591+00:00 app[worker.1]: return fun(*args, **kwargs)
2014-02-27T13:19:31.552591+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 162, in connect
2014-02-27T13:19:31.552591+00:00 app[worker.1]: return self.connection
2014-02-27T13:19:31.552591+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 617, in connection
2014-02-27T13:18:23.870811+00:00 app[worker.1]: [2014-02-27 13:18:23,870: ERROR/MainProcess] consumer: Connection to broker lost. Trying to re-establish the connection...
and those logs go on endlessly. till I stop both dynos and restart them.
It has become a problem because it happens almost every time a new commit is deployed.
Any ideas why this is happening and how to solve this?

The nano redistogo plan caps concurrent redis connections at 10.
The number of redis connects used will vary based on your front-end and celery worker settings. It sounds like you are using >= 5 redis connections for your production stack.
When you deploy new code, Heroku spins up an entirely new stack. This means you are using >= 10 redis connections at the time of deploy.
There are two ways to fix this:
Increase the maximum number of redistogo connections allowed, by upgrading to a larger plan ($$$)
Decrease the number of used connections for your stack (decrease celery concurrency or redis connections used by your web worker)
This is a simple matter of resource exhaustion. I would just pay for a larger RedisToGo plan.

Related

Discord bot not running with heroku

I'm in the process of moving my discord bot from locally hosting to heroku and i seem to have everything down except for actually running it.
When I enable the python worker, it doesn't seem to bring my bot online.
I'm not sure why this would be the case. It's connected to my GitHub and the bot token is defined using the vars.
The build logs look normal but the app logs have some errors that I'm not sure how to fix, which I have to assume is the problem.
Application logs:
2022-04-15T05:10:52.792118+00:00 app[worker.1]: from .client import Client
2022-04-15T05:10:52.792127+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord/client.py", line 53, in <module>
2022-04-15T05:10:52.792226+00:00 app[worker.1]: from .webhook import Webhook
2022-04-15T05:10:52.792234+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord/webhook/__init__.py", line 12, in <module>
2022-04-15T05:10:52.792307+00:00 app[worker.1]: from .async_ import *
2022-04-15T05:10:52.792315+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord/webhook/async_.py", line 52, in <module>
2022-04-15T05:10:52.792382+00:00 app[worker.1]: from ..channel import PartialMessageable
2022-04-15T05:10:52.792405+00:00 app[worker.1]: ImportError: cannot import name 'PartialMessageable' from 'discord.channel' (/app/.heroku/python/lib/python3.10/site-packages/discord/channel.py)
2022-04-15T05:10:52.949575+00:00 heroku[worker.1]: Process exited with status 1
2022-04-15T05:10:53.184475+00:00 heroku[worker.1]: State changed from up to crashed
2022-04-15T06:01:19.686916+00:00 heroku[worker.1]: State changed from crashed to starting
2022-04-15T06:01:23.574488+00:00 heroku[worker.1]: Starting process with command `python3 bot.py`
2022-04-15T06:01:24.141886+00:00 heroku[worker.1]: State changed from starting to up
2022-04-15T06:01:25.439092+00:00 heroku[worker.1]: State changed from up to crashed
2022-04-15T06:01:25.319879+00:00 heroku[worker.1]: Process exited with status 1
2022-04-15T06:01:25.157617+00:00 app[worker.1]: Traceback (most recent call last):
2022-04-15T06:01:25.157650+00:00 app[worker.1]: File "/app/bot.py", line 1, in <module>
2022-04-15T06:01:25.157743+00:00 app[worker.1]: import discord
2022-04-15T06:01:25.157748+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord/__init__.py", line 25, in <module>
2022-04-15T06:01:25.157813+00:00 app[worker.1]: from .client import Client
2022-04-15T06:01:25.157822+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord/client.py", line 53, in <module>
2022-04-15T06:01:25.157898+00:00 app[worker.1]: from .webhook import Webhook
2022-04-15T06:01:25.157900+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord/webhook/__init__.py", line 12, in <module>
2022-04-15T06:01:25.157953+00:00 app[worker.1]: from .async_ import *
2022-04-15T06:01:25.157961+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord/webhook/async_.py", line 52, in <module>
2022-04-15T06:01:25.158026+00:00 app[worker.1]: from ..channel import PartialMessageable
2022-04-15T06:01:25.158049+00:00 app[worker.1]: ImportError: cannot import name 'PartialMessageable' from 'discord.channel' (/app/.heroku/python/lib/python3.10/site-packages/discord/channel.py)
My code is too long to put here but when I run it locally it works anyway, but if any specific code is needed I can reply with it.
Any help is appreciated, thanks!
Fixed by updating to discord.py v2.0.0a because for some reason when i installed it, i was on v1.7
if anyone needs the import code:
python3 -m pip install -U git+https://github.com/Rapptz/discord.py

Heroku + Redis Cloud: Temporary failure in name resolution

I am using the Redis Cloud add-in on my Heroku application and I keep getting this error sporadically. I have tried flushing the redis DB and restarting dynos and that seems to fix it but I am curious why this is happening so often.
I am running worker dynos that use this redis DB and I am using python-rq to schedule jobs on the worker queues.
File "/usr/local/lib/python3.8/site-packages/redis/connection.py", line 563, in connect
raise ConnectionError(self._error_message(e))
2020-08-05T17:12:25.451733+00:00 app[worker_proc.5]: redis.exceptions.ConnectionError: Error -3 connecting to redis-13618.c73.us-east-1-2.ec2.cloud.redislabs.com:13618. Temporary failure in name resolution.
2020-08-05 17:12:25,461 INFO exited: worker_proc-0 (exit status 1; not expected)
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/redis/connection.py", line 559, in connect
sock = self._connect()
File "/usr/local/lib/python3.8/site-packages/redis/connection.py", line 584, in _connect
for res in socket.getaddrinfo(self.host, self.port, self.socket_type,
File "/usr/local/lib/python3.8/socket.py", line 918, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

Cloudera Manager - Service Monitor is not running

It seems there is something wrong with connection issues.But I don't know what lead to this problem.Could anyone help me?What connection issue am I facing?
(9 skipped) Error sending messages to firehose: mgmt-SERVICEMONITOR-73cd125b24d5013535b3d65d46703b65
Traceback (most recent call last):
File "/opt/cm-5.13.0/lib64/cmf/agent/build/env/lib/python2.6/site-packages/cmf-5.13.0-py2.6.egg/cmf/monitor/firehose.py", line 116, in _send
self._port)
File "/opt/cm-5.13.0/lib64/cmf/agent/build/env/lib/python2.6/site-packages/avro-1.6.3-py2.6.egg/avro/ipc.py", line 469, in __init__
self.conn.connect()
File "/usr/lib64/python2.6/httplib.py", line 720, in connect
self.timeout)
File "/usr/lib64/python2.6/socket.py", line 567, in create_connection
raise error, msg
error: [Errno 111] Connection refused
The error message indicates that CM agent is not able to reach out to Service Monitor due to Connection refused.
The most common reason is Service Monitor not running. Check if Service Monitor is actually running.
Another reason could be CM agent is not able to connect Service Monitor on port 9997. Check from CM agent host using
telnet <SMON_Host> 9997

uploading web.py app on Heroku

just started on using web.py and heroku, so...
I have this simple app that I want to upload to heroku and I have followed the instruction from http://joshuaoiknine.com/post/47196802362/publishing-for-the-web-py-python-framework-to-heroku
This is my Procfile:
web: python code.py $PATH
But after I uploaded it to heroku, it gives me the application error.
The heroku log shows me this:
2013-08-08T03:27:44.956675+00:00 heroku[web.1]: Starting process with command `python code.py /usr/local/bin:/usr/bin:/bin`
2013-08-08T03:27:45.673358+00:00 app[web.1]: Traceback (most recent call last):
2013-08-08T03:27:45.673358+00:00 app[web.1]: File "code.py", line 52, in <module>
2013-08-08T03:27:45.673358+00:00 app[web.1]: app.run()
2013-08-08T03:27:45.673358+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/web/application.py", line 313, in run
2013-08-08T03:27:45.673358+00:00 app[web.1]: return wsgi.runwsgi(self.wsgifunc(*middleware))
2013-08-08T03:27:45.673358+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/web/wsgi.py", line 54, in runwsgi
2013-08-08T03:27:45.673358+00:00 app[web.1]: return httpserver.runsimple(func, validip(listget(sys.argv, 1, '')))
2013-08-08T03:27:45.673358+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/web/net.py", line 76, in validip
2013-08-08T03:27:45.673358+00:00 app[web.1]: port = int(port)
2013-08-08T03:27:45.673552+00:00 app[web.1]: ValueError: invalid literal for int() with base 10: '/usr/local/bin:/usr/bin:/bin'
2013-08-08T03:27:46.866238+00:00 heroku[web.1]: Process exited with status 1
2013-08-08T03:27:46.881655+00:00 heroku[web.1]: State changed from starting to crashed
However, when i tried the second method, I receive this error:
Traceback (most recent call last):
File "code.py", line 55, in <module>
app.run(host='0.0.0.0', port=port)
TypeError: run() got an unexpected keyword argument 'host'
Any ideas how to get my app onto heroku up and running?
code.py expects an integer argument first, not your $PATH. It is probably a port it is expecting, so instead of $PATH in your Procfile pass $PORT.
Even better: change your code to use ENV["PORT"] and if that's not defined (as might be the case in your local dev env) then a default (say, 8000 or 8080 for your dev env).
On Heroku, the port your server needs to listen on is not fixed -- it changes with every restart of every dyno. Heroku will set the environment variable PORT to let you know which port to listen on.

zeromq and bind_to_random_port - how to get port chosen

In python, I am using the following:
context = zmq.Context()
socket = context.socket(zmq.PUSH)
socket.bind_to_random_port('tcp://*', min_port=6001, max_port=6004, max_tries=100)
port_selected = socket.???????
How do I know what port is chosen? I will have a look up table in redis for the workers to read.
I am using a push pull model. I need to let workers know what ports to connect to.
I have to do this because I am using the gevent loop in uwsgi and specifying a a plain blind thows and error becuase of a fork. If a use bind_to_random_port then a port is seleced, I just dont know which.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gevent-1.0b2-py2.7-linux-x86_64.egg/gevent/greenlet.py",
line 328, in run
result = self._run(*self.args, **self.kwargs)
File "/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbUwsgiPixelServer/uwsgiPixelServer.py",
line 43, in sendthis
socket.send(push)
File "/usr/local/lib/python2.7/dist-packages/zmq/green/core.py",
line 173, in send
self._wait_write()
File "/usr/local/lib/python2.7/dist-packages/zmq/green/core.py",
line 108, in _wait_write
assert self.__writable.ready(), "Only one greenlet can be waiting
on this event"
AssertionError: Only one greenlet can be waiting on this event
<Greenlet at 0x2d41370: sendthis('2012-07-02 04:05:15')> failed with
AssertionError
port_selected = socket.bind_to_random_port('tcp://*', min_port=6001, max_port=6004, max_tries=100)

Resources