I wrote the Python program using flask, which reads some data from MongoDB. But after a few hours of running the program on server , it starts to fill up server memory by MongoDB until all the server memory is used.
Status of server resources when running the program
After a few hours, the state of server resources is as follows
Status of server resources after a few hours
FROM python:3.8.7-buster
WORKDIR /flask_app
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY . .
ENV FLASK_APP=server.py
CMD ["gunicorn", "server:app", "-w", "2","--log-level" ,"DEBUG", "--threads", "2", "-b", "0.0.0.0:5000"]
In fact, this problem is due to the MongoDB cache system.
And to solve this problem, you have to limit the amount of RAM consumption for MongoDB.
This does not reduce MongoDB performance and does not have much effect on it, but it does solve the problem.
You need to add these configurations to docker-campus configurations:
.......
deploy:
resources:
limits:
memory: 3G
reservations:
memory: 1G
command: --wiredTigerCacheSizeGB 0.25
.......
In this case, the consumption of MongoDB memory is fixed at 5.2, you can adjust your consumption.
Good luck :)