Articles of gunicorn

优化多个gunicorn实例的工作人员数量

我正在configurationgunicorn(由supervisord监听,并在nginx前端后面),并且对于设置的最佳进程数量感到困惑。 在文件中明确解释说: workers = multiprocessing.cpu_count() * 2 + 1 我的机器是一个四核心,所以应该算9名工人。 但是我想运行几个应用程序,每个应用程序都听一个不同的端口。 那么计数应该(截断): workers_per_application = int(workers / NUM_APPLICATIONS) 还是应该每个人都有上述数量的工人? 我认为这个问题实际上不仅适用于gunicorn,而且适用于所有类似的监听服务器。

在HUP信号后,gunicorn不能完全重新加载

我试图得到一个工作主pipe/ gunicorn / djangostream浪汉设置。 我正在使用python-watchdog在发生代码更改时尝试重新启动gunicorn。 我正在使用gunicorn的以下pipe理员configuration: [program:someapp] environment=PYTHONPATH='/vagrant/libs/unmodified/django-error-capture-middleware/src:/vagrant:/home/vagrant/.virtualenvs/someapp/lib/python2.7/site-packages:/vagrant/wsgi',DJANGO_SETTINGS_MODULE=someapp.settings.vagrant command=/home/vagrant/.virtualenvs/someapp/bin/gunicorn –bind 0.0.0.0:80 –pid=/home/vagrant/.gunicorn.pid –preload –workers=1 –debug –log-level debug –error-logfile – –access-logfile – vagrant_wsgi:application user=root group=root redirect_stderr=true stdout_logfile = /vagrant/logs/gunicorn.log stderr_logfile = /vagrant/logs/gunicorn.log stdout_logfile_maxbytes=0 autostart=true autorestart=true stdout_events_enabled=true loglevel=debug 这一切工作得很好。 看门狗也工作正常。 但是,当我使用看门狗运行一个kill -HUP [pidofgunicorn] ,有时它不会实际上完全重新加载。 有时候django甚至会报告,当模块在之前的时候就会丢失(我根本没有修改过sys.path)。 如果我使用看门狗运行supervisorctl restart someapp ,它工作正常。 但是,这需要更长的时间,特别是在virtualbox实例上。 有什么我可以做得到gunicorn优雅重新加载,实际上看到所作的变化?

部署CherryPy应用程序:独立,WSGI服务器还是NGinx?

我打算使用单个VPS将多个低stream量CherryPy应用程序部署为子目录; 例如: example.com/app1等 在研究WSGI部署之后,看起来部署应用程序的首选方法是在反向代理设置中使用WSGI服务器(Gunicorn,uWSGI等)和NGinx。 看起来使用两个networking服务器似乎有点过分 – 尤其是因为我的CherryPy应用程序本身就是一个networking服务器 – 但我不想随意地将这个想法解雇。 我当然不是专家,所以我想讨论一下。 我看到三个选项: 自己部署CherryPy。 部署在Gunicorn或其他WSGI服务器下。 部署在WSGI服务器之下,并反向代理到NGinx,这似乎是每个人的解决scheme。 我的问题: 我到处看到这种模式的主要原因是什么? NGinx是不是很好? 对于低stream量的应用程序,本地CherryPy服务器是否足够好,还是我应该不尝试? 任何和所有的build议表示赞赏,谢谢。

长时间运行gunicorn + nginx请求

我已经为我们的Django驱动的应用程序整合了一个集成服务器。 一些function仍然是实验性的,并导致过长的请求。 我现在的performance还不错,但我需要能够整合。 无论何时我们使用导致长时间请求的function,应用程序都会挂起(如预期的那样),然后在一分半钟后返回“502 – 错误的网关”。 应用程序的其余部分工作正常。 我检查了gunicorn日志,每当发生这种情况,我得到一条线 2012-01-20 17:30:13 [23128] [DEBUG] GET /results/ 2012-01-20 17:30:43 [23125] [ERROR] WORKER TIMEOUT (pid:23128) Traceback (most recent call last): File "/home/demo/python_envs/frontend/lib/python2.6/site-packages/gunicorn/app/base.py", line 111, in run os.setpgrp() OSError: [Errno 1] Operation not permitted 然而,这发生在实际的工人超时之前,我已经设置为10分钟,以确保。 这是运行gunicorn的暴发剧本的一部分。 description "…" start on runlevel [2345] stop on runlevel [!2345] #Send KILL after 5 […]

nginx在65k字节后终止连接

我已经将nginxconfiguration为在gunicorn下运行的Python应用程序的前端,但nginx在大约65k的数据发送之后正在终止连接。 例如,我有一个看起来像这样的视图: def debug_big_file(request): return HttpResponse("x" * 500000) 但是当我通过nginx访问这个URL时,我只得到了65283个字节: $ curl https://example.com/debug/big-file | wc … curl: (18) transfer closed with outstanding read data remaining 0 1 65283 请注意,当直接访问gunicorn时,一切都按预期运行: $ curl http://localhost:1234/debug/big-file | wc … 0 1 500000 相关的nginxconfiguration: location / { proxy_pass http://localhost:1234/; proxy_redirect off; proxy_headers_hash_bucket_size 96; } 和nginx版本1.7.0 其他一些事实: 从请求到请求的字节数是一致的,但是根据内容而不同(我首先注意到它有一个大的PNG文件,在65,372字节之后被截断,而不是65,283) 正确发送110k字节(即"x" * 110000返回全部110,000字节),但是120k字节不正确 tcpdump表明nginx正在向gunicorn发送一个RST数据包:

如何解决gunicorn关键工人超时错误?

我用nginx和gunicorn来托pipe我的网站在两台服务器上, 两台服务器都有相同版本的软件包,网站成功托pipe, 但在我的一个服务器gunicorn总是超时,我得到错误 [CRITICAL]Worker Timeout Booting worker with pid Worker cannot boot with pid 在此之后,我在网页中得到502 Badgateway错误。 我必须重新启动gunicorn进程来调出网站。 以下是错误日志: 2014-02-16 14:29:53 [1267] [CRITICAL] WORKER TIMEOUT (pid:4994) 2014-02-16 14:29:53 [1267] [CRITICAL] WORKER TIMEOUT (pid:4994) 2014-02-16 14:29:53 [22140] [INFO] Booting worker with pid: 22140 我得到这样的连续性错误, 2014-02-16 14:29:53 [22140] [DEBUG] Ignoring EPIPE Ignoring EPIPE 2014-02-16 14:29:53 [22140] [DEBUG] Ignoring […]

nginx没有server_name和只使用静态IP地址?

这是我的第一个Web应用程序部署,并遇到各种问题。 我目前正在为Django应用程序的nginx + gunicorn实现,但大多数这个问题涉及到nginxconfiguration。 在某些情况下,nginx会收到连接并代理到gunicorn本地服务器。 在Nginx的configuration,它说server_name我必须提供一个? 我不打算使用任何types的域名,只是通过我的networking的外部IP(这是静态的)和端口号来听。 我的愿望是,当我访问像http://xxx.xxx.xxx.xxx:9050东西,我将能够得到的网站。 以下是我将基于configuration参考的示例代码。 server { listen 80; server_name WHAT TO PUT HERE?; root /path/to/test/hello; location /media/ { # if asset versioning is used if ($query_string) { expires max; } } location /admin/media/ { # this changes depending on your python version root /path/to/test/lib/python2.6/site-packages/django/contrib; } location / { proxy_pass_header Server; […]

Supervisor不加载新的configuration文件

我使用Gunicorn和Supervisor部署Django应用程序时遇到问题。 虽然我可以让Gunicorn为我的应用程序服务(通过设置适当的PYTHONPATH并运行适当的命令,来自supervisord config的那个命令),我不能让主pipe运行它。 它只是不会看到我的应用程序。 我不知道如何确定configuration文件是否正常。 以下是主pipe说: # supervisorctl start myapp_live myapp_live: ERROR (no such process) 我使用以下configuration在Ubuntu 10.04上运行它: 文件/home/myapp/live/deploy/supervisord_live.ini: [program:myapp_live] command=/usr/local/bin/gunicorn_django –log-file /home/myapp/logs/gunicorn_live.log –log-level info –workers 2 -t 120 -b 127.0.0.1:10000 -p deploy/gunicorn_live.pid webapp/settings_live.py directory=/home/myapp/live environment=PYTHONPATH='/home/myapp/live/eco/lib' user=myapp autostart=true autorestart=true 在/etc/supervisor/supervisord.conf中,在文件末尾有: [include] files = /etc/supervisor/conf.d/*.conf 这里是我的configuration文件的符号链接: # ls -la /etc/supervisor/conf.d lrwxrwxrwx 1 root root 48 Dec 4 […]