Python Heroku,内部服务器错误,错误R14(超出内存配额)

Python Heroku,内部服务器错误,错误R14(超出内存配额),python,heroku,fastapi,Python,Heroku,Fastapi,我在heroku上有一个FastAPI应用程序,它工作得很好,但现在我得到了 打开应用程序时出现内部服务器错误,我检查了日志,发现了此错误 2020-06-25T09:18:54.922877+00:00 app[web.1]: [2020-06-25 09:18:54 +0000] [10] [ERROR] Exception in ASGI application 2020-06-25T09:18:54.922878+00:00 app[web.1]: Traceback (most rec

我在heroku上有一个FastAPI应用程序,它工作得很好,但现在我得到了 打开应用程序时出现内部服务器错误,我检查了日志,发现了此错误

2020-06-25T09:18:54.922877+00:00 app[web.1]: [2020-06-25 09:18:54 +0000] [10] [ERROR] Exception in ASGI application
2020-06-25T09:18:54.922878+00:00 app[web.1]: Traceback (most recent call last):
2020-06-25T09:18:54.922879+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/uvicorn/protocols/http/httptools_impl.py", line 375, in run_asgi
2020-06-25T09:18:54.922880+00:00 app[web.1]:     result = await app(self.scope, self.receive, self.send)
2020-06-25T09:18:54.922880+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/starlette/applications.py", line 133, in __call__
2020-06-25T09:18:54.922881+00:00 app[web.1]:     await self.error_middleware(scope, receive, send)
2020-06-25T09:18:54.922881+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/starlette/middleware/errors.py", line 177, in __call__
2020-06-25T09:18:54.922882+00:00 app[web.1]:     raise exc from None
2020-06-25T09:18:54.922882+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/starlette/middleware/errors.py", line 155, in __call__
2020-06-25T09:18:54.922883+00:00 app[web.1]:     await self.app(scope, receive, _send)
2020-06-25T09:18:54.922883+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/starlette/exceptions.py", line 73, in __call__
2020-06-25T09:18:54.922883+00:00 app[web.1]:     raise exc from None
2020-06-25T09:18:54.922884+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/starlette/exceptions.py", line 62, in __call__
2020-06-25T09:18:54.922884+00:00 app[web.1]:     await self.app(scope, receive, sender)
2020-06-25T09:18:54.922884+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/starlette/routing.py", line 590, in __call__
2020-06-25T09:18:54.922885+00:00 app[web.1]:     await route(scope, receive, send)
2020-06-25T09:18:54.922885+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/starlette/routing.py", line 208, in __call__
2020-06-25T09:18:54.922885+00:00 app[web.1]:     await self.app(scope, receive, send)
2020-06-25T09:18:54.922888+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/starlette/routing.py", line 41, in app
2020-06-25T09:18:54.922888+00:00 app[web.1]:     response = await func(request)
2020-06-25T09:18:54.922889+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/fastapi/routing.py", line 113, in app
2020-06-25T09:18:54.922889+00:00 app[web.1]:     raw_response = await run_in_threadpool(dependant.call, **values)
2020-06-25T09:18:54.922889+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/starlette/concurrency.py", line 25, in run_in_threadpool
2020-06-25T09:18:54.922890+00:00 app[web.1]:     return await loop.run_in_executor(None, func, *args)
2020-06-25T09:18:54.922890+00:00 app[web.1]:   File "uvloop/loop.pyx", line 2658, in uvloop.loop.Loop.run_in_executor
2020-06-25T09:18:54.922891+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/concurrent/futures/thread.py", line 123, in submit
2020-06-25T09:18:54.922891+00:00 app[web.1]:     self._adjust_thread_count()
2020-06-25T09:18:54.922891+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/concurrent/futures/thread.py", line 142, in _adjust_thread_count
2020-06-25T09:18:54.922892+00:00 app[web.1]:     t.start()
2020-06-25T09:18:54.922893+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/threading.py", line 846, in start
2020-06-25T09:18:54.922893+00:00 app[web.1]:     _start_new_thread(self._bootstrap, ())
2020-06-25T09:18:54.923075+00:00 app[web.1]: RuntimeError: can't start new thread
2020-06-25T09:18:55.285447+00:00 heroku[web.1]: Process running mem=805M(157.1%)
2020-06-25T09:18:55.287435+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2020-06-25T09:19:15.525510+00:00 heroku[web.1]: Process running mem=805M(157.1%)
2020-06-25T09:19:15.527704+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2020-06-25T09:19:35.447648+00:00 heroku[web.1]: Process running mem=805M(157.1%)
2020-06-25T09:19:35.450563+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
我不是后端方面的专家,所以我不知道这些错误是什么意思,这是第一次发生这种错误,它正常工作了一个多月,只是为了测试,但如果高兴的话,我发现这个错误现在不在生产中。 我在这里使用免费层。 如果我升级到业余爱好,我会面临同样的问题吗?
问题到底出在哪里?

应用程序的ram使用量已经超过了可用的qouta,因为您使用的是空闲层,内存qouta为512 MB。如果您看到日志,最后一行的第二行表示mem=805M。升级到hobby不会解决此问题,因为它还有512 MB内存qouta

有关更多详细信息,请参阅此链接


我通过将平台上的工作线程数量从4个减少到2个来修复此问题。允许应用程序使用一定数量的RAM(512 MB)。你超过了那个数额。