推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
skyduy
V2EX  ›  Python

在 Apache2 上部署 Flask 应用,内存不断消耗的问题,求大神解释指导。

  •  
  •   skyduy ·
    skyduy · Jun 9, 2016 · 4639 views
    This topic created in 3640 days ago, the information mentioned may be changed or developed.

    普通 Flask 应用,如果直接调试运行的话(就是使用 python app.py 运行的时候),仅会在第一次访问网页(第一次调用各种函数、包)的时候消耗部分内存(在这里是 50M )。但是部署在 Apache2 上之后,每次访问都会吃掉我 50M 内存。这是什么原因?

    下面是 apache2 的 conf 代码:

    <VirtualHost *:80>
                    ServerName s.example.com
    
                    WSGIScriptAlias / /var/www/my_app/index.wsgi
                    <Directory /var/www/my_app>
                            Order Deny,Allow
                            Deny from all
                            Allow from ....
                            Require all granted
                    </Directory>
    
                    ErrorLog ${APACHE_LOG_DIR}/error.log
                    LogLevel warn
                    CustomLog ${APACHE_LOG_DIR}/access.log combined
    
    </VirtualHost>
    

    下面是 index.wsgi 代码( virtualenv 创建了 /var/www/my_app/env 目录并安装了依赖包):

    #!/usr/bin/python
    import logging
    import os, sys
    sys.path.insert(0, "/var/www/my_app")
    
    activate_this = os.path.join('/var/www/my_app/env', 'bin', 'activate_this.py')
    execfile(activate_this, dict(__file__=activate_this))
    logging.basicConfig(stream=sys.stderr)
    
    from app import create_app
    application = create_app()
    
    

    还是那句话,在我调试运行的时候,第一次加载各种包的时候吃掉我 50M 内存,之后正常,但是部署到 apache2 中之后,每次访问都要吃掉我 50M 内存,求大神指导...

    1 replies    2016-06-09 13:22:41 +08:00
    wsy2220
        1
    wsy2220  
       Jun 9, 2016 via Android
    检查一下 apache 的 mpm 是不是 prefork ,最好用 event
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4083 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 04:12 · PVG 12:12 · LAX 21:12 · JFK 00:12
    ♥ Do have faith in what you're doing.