Home > front end >  Uvicron process becom zombie after OOM killer
Uvicron process becom zombie after OOM killer

Time:04-04

I have a fast-api service wrapped in a docker, I am running it with the following command:

uvicorn --host 0.0.0.0 --workers 10 --backlog 20 --timeout-keep-alive 65 my_python_main:app

The service works OK most of the time, but after a while it can get a "heavy" request which will cause the memory of the machine to rise up, as a result the OOM killer start killing many processes (but not this service). The python processes are staying alive but stop serving requests.

Is there a way to tell the uvircorn that in case it is unreachable it should restart itself or kill itself so the docker restart will do it for him?

Is there a way to do it in the level of the docker? meaning if the docker suppose to expose port 80 and is not reachable restart it?

CodePudding user response:

You can limit the memory a container is allowed to use, with docker itself. If a container exceeds this memory and throws an OOM error, it is killed.

docker run --memory=128m --restart on-failure myapp

You can also enable health checks, which on their own do not much other than letting you know if a container is healthy according to the configured health command. It is up to the operator, or operating framework, to act upon this information.

docker run --health-cmd <some-cmd> myapp

In order to do something useful with that, you need to inspect the container, or as mentioned, let your operating framework decide what to do.

That said, while these options are good for safety measurement, you shouldn't rely on them for your regular workflow. If you know your container crashes all the time, or is causing other problems with your system, you should fix the root of the problem instead of simply restarting it over and over.

In your case, this might involve using an adequately equipped machine to begin with. At the end you want to provide production value, if your setup cannot handle the business requirements, then you should improve your setup and ensure the required resources are given.

  • Related