Gayathri Sai
Gayathri Sai

Reputation: 13

Error R14 (Memory quota exceeded) Heroku Python Flask

I am new to heroku and in general to the world of programming. I am trying to deploy my flask app on heroku. I have used 90MiB of 500MiB of slug size. My procfile has the below:

web gunicorn project.auth:app --timeout 900 --max-requests 1200 --workers 1

But i get the E14 error. I am not sure how exactly can this be solved.

2020-10-16T13:17:05.866355+00:00 heroku[web.1]: Starting process with command `gunicorn project.auth:app --timeout 900 --max-requests 1200 --workers 1`
2020-10-16T13:17:06.657091+00:00 heroku[web.1]: Restarting
2020-10-16T13:17:06.432662+00:00 app[api]: Deploy da7ff20a by user 
2020-10-16T13:17:06.432662+00:00 app[api]: Release v82 created by user
2020-10-16T13:17:08.800005+00:00 app[web.1]: [2020-10-16 13:17:08 +0000] [4] [INFO] Starting gunicorn 19.9.0
2020-10-16T13:17:08.800558+00:00 app[web.1]: [2020-10-16 13:17:08 +0000] [4] [INFO] Listening at: 
2020-10-16T13:17:08.800653+00:00 app[web.1]: [2020-10-16 13:17:08 +0000] [4] [INFO] Using worker: sync
2020-10-16T13:17:08.804880+00:00 app[web.1]: [2020-10-16 13:17:08 +0000] [10] [INFO] Booting worker with pid: 10
2020-10-16T13:17:11.216438+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-10-16T13:17:11.251320+00:00 app[web.1]: [2020-10-16 13:17:11 +0000] [4] [INFO] Handling signal: term
2020-10-16T13:17:12.938661+00:00 heroku[web.1]: Process running mem=608M(118.8%)
2020-10-16T13:17:12.941032+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)

Any help on this would be very much appreciated. Thanks in Advance.

Upvotes: 0

Views: 2467

Answers (2)

Mozz
Mozz

Reputation: 11

Few optimization suggestions when facing the problem esp. with Python ML models in Heroku with Gunicorn.

  1. Import specific libraries from module such as NLTK.
  2. use preload option in procfile if using Gunicorn. This should drastically reduce ram usage.
  3. If using Gunicorn, use max-requests option in procfile. This will restart dynos after set number of use. Prevent memory leakage.
  4. Appropriately set web concurrency. This will increase number of workers and increase RAM per worker. Try reducing it to 2 if you are doing a personal/hobby project.

Upvotes: 1

Beppe C
Beppe C

Reputation: 14003

Even if your slug is pretty small it looks like your application is using too much memory and exceeding the max allowed (512MB).

Remove imported modules (if possible) and review what data you store in memory and how.

If you are using some machine learning or statistical model it is possible that the memory is filled when loading it.

Upvotes: 2

Related Questions