Linux 关于服务器上的内存和进程

Linux 关于服务器上的内存和进程,linux,django,apache,celery,Linux,Django,Apache,Celery,还是个学习者。我有一个Django网站,从一个月以来一直部署在Web派系服务器上 昨天我尝试设置芹菜,使用主管在后台发送电子邮件。我刚完成设置,一切正常,突然收到来自Webfaction的电子邮件: Hello, Right now (2013-12-23 00:06:06 UTC) it appears that your processes on Web330 are using a lot more memory than your plan allows. I

还是个学习者。我有一个Django网站,从一个月以来一直部署在Web派系服务器上

昨天我尝试设置
芹菜
,使用
主管
在后台发送电子邮件。我刚完成设置,一切正常,突然收到来自Webfaction的电子邮件:

    Hello,

    Right now (2013-12-23 00:06:06 UTC) it appears that your processes on Web330 are using a lot more memory than your plan allows.

    If you haven't read it yet, we recommend that you have a look at our "Reducing Memory Usage" article (http://docs.webfaction.com/software/general.html#reducing-memory-usage) for tips on how to keep your memory usage down.

    Your total allowed memory is 512MB and your current memory usage is 1023MB.

    Since your high memory usage is impacting other users on the server we had to kill your processes (our watchdog first sends a SIGTERM to your processes and then sends a SIGKILL a few seconds later).

    You need to either find a way to keep your memory down or you'll have to upgrade to a plan that allows more memory.

    Please respond to this message to let us know how you're dealing with the problem.

    Below is the list of processes that you're running with the memory that they use (the command used to list these processes is "ps -u hammad -o rss,etime,pid,command"):

    User - Memory - Elapsed Time - Pid - Command:
    --------------------------------------------
/home/hammad/webapps/gccfishing/apache2/bin/httpd.worker -f /home/hammad/webapps/gccfishing/apache2/conf/httpd.conf -k start
    hammad - 51MB - 0:16:44 - 428360 - /home/hammad/webapps/gccfishing/apache2/bin/httpd.worker -f /home/hammad/webapps/gccfishing/apache2/conf/httpd.conf -k start
    hammad - 49MB - 0:16:44 - 428361 - /home/hammad/webapps/gccfishing/apache2/bin/httpd.worker -f /home/hammad/webapps/gccfishing/apache2/conf/httpd.conf -k start
    hammad - 52MB - 0:16:44 - 428362 - /home/hammad/webapps/gccfishing/apache2/bin/httpd.worker -f /home/hammad/webapps/gccfishing/apache2/conf/httpd.conf -k start
    hammad - 50MB - 0:16:44 - 428363 - /home/hammad/webapps/gccfishing/apache2/bin/httpd.worker -f /home/hammad/webapps/gccfishing/apache2/conf/httpd.conf -k start
    hammad - 53MB - 0:16:44 - 428364 - /home/hammad/webapps/gccfishing/apache2/bin/httpd.worker -f /home/hammad/webapps/gccfishing/apache2/conf/httpd.conf -k start
    hammad - 2MB - 0:16:44 - 428365 - /home/hammad/webapps/gccfishing/apache2/bin/httpd.worker -f /home/hammad/webapps/gccfishing/apache2/conf/httpd.conf -k start
    hammad - 11MB - 0:06:29 - 435573 - /home/hammad/webapps/gccfishing/bin/python2.7 /home/hammad/webapps/gccfishing/bin/supervisord -c supervisord_prod.conf
    hammad - 48MB - 0:06:28 - 435577 - /home/hammad/webapps/gccfishing/bin/python2.7 /home/hammad/webapps/gccfishing/bin/celery -A gccFishing worker -l info
    hammad - 39MB - 0:06:27 - 435589 - /home/hammad/webapps/gccfishing/bin/python2.7 /home/hammad/webapps/gccfishing/bin/celery -A gccFishing worker -l info
    hammad - 39MB - 0:06:27 - 435590 - /home/hammad/webapps/gccfishing/bin/python2.7 /home/hammad/webapps/gccfishing/bin/celery -A gccFishing worker -l info
    hammad - 39MB - 0:06:27 - 435591 - /home/hammad/webapps/gccfishing/bin/python2.7 /home/hammad/webapps/gccfishing/bin/celery -A gccFishing worker -l info
    hammad - 39MB - 0:06:27 - 435592 - /home/hammad/webapps/gccfishing/bin/python2.7 /home/hammad/webapps/gccfishing/bin/celery -A gccFishing worker -l info
    hammad - 39MB - 0:06:27 - 435593 - /home/hammad/webapps/gccfishing/bin/python2.7 /home/hammad/webapps/gccfishing/bin/celery -A gccFishing worker -l info
    hammad - 39MB - 0:06:27 - 435594 - /home/hammad/webapps/gccfishing/bin/python2.7 /home/hammad/webapps/gccfishing/bin/celery -A gccFishing worker -l info
    hammad - 39MB - 0:06:27 - 435595 - /home/hammad/webapps/gccfishing/bin/python2.7 /home/hammad/webapps/gccfishing/bin/celery -A gccFishing worker -l info
    hammad - 39MB - 0:06:27 - 435596 - /home/hammad/webapps/gccfishing/bin/python2.7 /home/hammad/webapps/gccfishing/bin/celery -A gccFishing worker -l info
    hammad - 39MB - 0:06:27 - 435597 - /home/hammad/webapps/gccfishing/bin/python2.7 /home/hammad/webapps/gccfishing/bin/celery -A gccFishing worker -l info
    hammad - 41MB - 0:06:27 - 435598 - /home/hammad/webapps/gccfishing/bin/python2.7 /home/hammad/webapps/gccfishing/bin/celery -A gccFishing worker -l info
    hammad - 39MB - 0:06:27 - 435599 - /home/hammad/webapps/gccfishing/bin/python2.7 /home/hammad/webapps/gccfishing/bin/celery -A gccFishing worker -l info
    hammad - 39MB - 0:06:27 - 435600 - /home/hammad/webapps/gccfishing/bin/python2.7 /home/hammad/webapps/gccfishing/bin/celery -A gccFishing worker -l info
    hammad - 39MB - 0:06:27 - 435601 - /home/hammad/webapps/gccfishing/bin/python2.7 /home/hammad/webapps/gccfishing/bin/celery -A gccFishing worker -l info
    hammad - 39MB - 0:06:27 - 435602 - /home/hammad/webapps/gccfishing/bin/python2.7 /home/hammad/webapps/gccfishing/bin/celery -A gccFishing worker -l info
    hammad - 39MB - 0:06:27 - 435603 - /home/hammad/webapps/gccfishing/bin/python2.7 /home/hammad/webapps/gccfishing/bin/celery -A gccFishing worker -l info
    hammad - 39MB - 0:06:27 - 435604 - /home/hammad/webapps/gccfishing/bin/python2.7 /home/hammad/webapps/gccfishing/bin/celery -A gccFishing worker -l info
    hammad - 0MB - 52 days, 14:45:11 - 702447 - 


    Regards,

    WebFaction team - http://www.webfaction.com
我想知道一些关于这方面的事情:

  • 为什么有这么多Apache实例,这些内存是用来做什么的?Apache不只是处理请求吗?如果是,那么每个实例的内存中都有什么

  • 为什么主管产生了这么多芹菜实例?这是我的supervisord.conf文件:

    [unix_http_server]
    file=/tmp/supervisor.sock   ; (the path to the socket file)
    
    [supervisord]
    logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
    logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)
    logfile_backups=10           ; (num of main logfile rotation backups;default 10)
    loglevel=info                ; (log level;default info; others: debug,warn,trace)
    pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
    nodaemon=false               ; (start in foreground if true;default false)
    minfds=1024                  ; (min. avail startup file descriptors;default 1024)
    minprocs=200                 ; (min. avail process descriptors;default 200)
    
    [supervisorctl]
    serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket
    
    [program:celeryd]
    command=/home/hammad/webapps/gccfishing/bin/celery -A gccFishing worker -l info
    directory=/home/hammad/webapps/gccfishing/gccFishing/gccFishing
    numprocs=1
    autostart=true
    autorestart=true
    startsecs = 10 
    stopwaitsecs = 900 
    
  • 再说一遍,每个芹菜实例的内存用于什么?我只是用它来发送一些html(没有图像或图形)电子邮件,偶尔给15-20个人发邮件


    它需要这么多内存吗?每次任务完成后是否可以清除内存,或者内存是否继续累积

    为什么有这么多Apache实例?同时回答请求。如果您的站点不需要每秒处理多次点击,您可能希望减少Apache Worker的数量。您还可以进一步减少内存使用

    另一种可能是用nginx替换Apache,用其他东西替换mod_wsgi,例如gunicorn。您可能希望在您的开发环境中检查每个gunicorn进程对于您的应用程序来说有多大。Nginx本身非常轻量级,在我的一台生产服务器上,每个Nginx工作人员占用的内存不到3MB

    内存用于什么?假设您使用mod_wsgi,它不仅用于Apache本身,还用于您的web应用程序。您可以使用,比如,来深入了解单个内存的使用情况。通常,您导入的每一位代码和创建的每一个对象都会占用内存


    celeryd Worker和的数量可以通过
    celeryd\u并发性
    设置进行调整。这些工人不是直接由supervisord产生的,而是芹菜本身产生的。如果您不需要大量的吞吐量,您甚至可以将工作人员的数量减少到1或2,并节省大量内存。

    感谢sk1p,芹菜工作人员的数量为16,我将其减少到2,现在一切正常。