1

I have django application in a Digital Ocean(512MB Memory) with Postgres, Nginx, and Gunicorn on Ubuntu 16.04. On running the application, it consuming more memory. If I navigate through the pages, it also consuming the memory on checking with top command. What will be the problem and what are the possible reason.

Gunicorn

[Unit]
Description=veeyar daemon
After=network.target

[Service]
User=root
Group=www-data
WorkingDirectory=/home/webapps/myproject/
ExecStart=/home/webapps/myproject/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/webapps/myproject/myproject.sock myproject.wsgi:application

[Install]
WantedBy=multi-user.target

Nginx

server {
    listen 9090;
    location = /favicon.ico { access_log off; log_not_found off; }
    location ^/static/ {
        root /home/webapps/myproject/staticfiles;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/webapps/myproject/myproject.sock;
    }
}

And also in settings.py I had set DEBUG=False.

I tried by googling it but i cannot understand properly.why it is happening so and did I missed anything. Can you guys please help me to sort out this problem. This will be very great full for me. Thanks in advance.

7
  • Your settings looks just fine, do you do any long running/computing tasks?
    – Or Duan
    Commented Jul 14, 2017 at 5:08
  • @OrDuan Thanks for your reply. No I don't have any long running/computing tasks in it. But has more records nearly 14000 rows from different tables.
    – Ajay Kumar
    Commented Jul 14, 2017 at 5:17
  • You have a memory leak, it is hard to say where without the code. Check if you change variables that persist over the calls because they are global or imported.
    – Klaus D.
    Commented Jul 14, 2017 at 5:17
  • @KlausD. Thanks for your response. Memory leak in the sense, where i can figure out this in my code?
    – Ajay Kumar
    Commented Jul 14, 2017 at 5:20
  • There are too many ways the create a memory leak to explain them here. Sorry.
    – Klaus D.
    Commented Jul 14, 2017 at 5:23

3 Answers 3

4

I will recommend you this post for Django performance, one of the principal reasons of the huge memory in Django is because you are using list instead of iterators.

Regards.

1
  • 1
    This is recommend. Thanks
    – Ajay Kumar
    Commented Jul 17, 2017 at 5:50
2

By looking at the memory consumes doesn't really reflect what the problem is or whether there is actually a problem. (unless your concern is how much memory left for other application running from the same box). Otherwise the memory takes up is for caching actually is needed for the application.

I think you should focus on the page loading time (and memory used) instead. For each page are you always retrieving a large queryset and iterate/filter from the code? Are there queryset you can re-use or combined so you don't need to make another query? These are what'd give you trouble when you have more user to the application rather than the memory needed to start the instance.

1
  • Thanks for your answer, your explanation make some sense. let me go through your quires.
    – Ajay Kumar
    Commented Jul 15, 2017 at 7:53
1

Check out what the Django docs has to say about application optimisation. It's hard to say what'll be relevant without seeing your code. But it's a good starting point.

One massive help is—if you're iterating over large QuerySets—the use of QuerySet.iterator() - which stops the entire QuerySet from being cached.

1
  • Thank you so much for your reply, Can you please tell me where should I user the QuerySet.iterator() , any example.
    – Ajay Kumar
    Commented Jul 14, 2017 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.