gunicorn

Efficient handling of long running HTTP connections in an nginx/gunicorn/django web architecture

爷,独闯天下 提交于 2019-12-04 07:42:31
问题 I am working on a web service implemented on top of nginx+gunicorn+django. The clients are smartphone applications. The application needs to make some long running calls to external APIs (Facebook, Amazon S3...), so the server simply queues the job to a job server (using Celery over Redis). Whenever possible, once the server has queued the job, it returns right away, and the HTTP connection is closed. This works fine and allows the server to sustain very high load. client server job server .

Gunicorn logging from multiple workers

你说的曾经没有我的故事 提交于 2019-12-04 07:28:05
I have a flask app that runs in multiple gunicorn sync processes on a server and uses TimedRotatingFileHandler to log to a file from within the flask application in each worker. In retrospect this seems unsafe. Is there a standard way to accomplish this in python (at high volume) without writing my own socket based logging server or similar? How do other people accomplish this? We do use syslog to aggregate across servers to a logging server already but I'd ideally like to persist the log on the app node first. Thanks for your insights i use ConcurrentRotatingFileHandler We ended up changing

What can go wrong if I use SimpleCache in my Flask app

送分小仙女□ 提交于 2019-12-04 05:40:16
We are using the following setup: NGINX+Gunicorn+Flask. We need to add just a little bit of caching, no more than 5Mb per Flask worker. SimpleCache seems to be simplest possible solution - it uses memory locally, inside the Python process itself. Unfortunately, the documentation states the following: "Simple memory cache for single process environments. This class exists mainly for the development server and is not 100% thread safe." However, I fail to see where thread safety would matter at all in our setup. I think that Gunicorn keeps several Flask workers running, and each worker has its

tensorflow deployment on openshift, errors with gunicorn and mod_wsgi

那年仲夏 提交于 2019-12-04 05:32:39
问题 I'm implementing a small app based on this git: gitlab.com/osevg/python-flask-modwsgi All I've changed is the wsgi.py to execute a script that analyzes an uploaded file (the file is uploaded through a separate PHP-based app, sent to this Python app via http post). The script itself is pretty trivial and runs without any issues on my local Windows device (takes 5-6s to run, then send back the results via JSON). I'm working on getting the tool running on Openshift v3 now. import os from flask

Restart Python.py when it stops working

99封情书 提交于 2019-12-04 05:03:29
问题 I am using Cherrypy framework to run my python code on server. But the process stops working when the load increases. Every time this happens I have to manually go and start the python code. Is there any way i can use Gunicorn with Cherrypy so that Gunicorn can start the code automatically when it stops working. Any other solution will also work in this case. Just want to make sure that the python program does not stop working. 回答1: I use a cron that checks the memory load every few minutes

gunicorn via mod_proxy is redirecting outside of the project's scope, despite ProxyPassReverse

会有一股神秘感。 提交于 2019-12-04 04:21:32
I have a WSGI-app (a Django project) running under gunicorn on 127.0.0.1:18731 and I use Apache with mod_proxy to redirect requests from http://example.com/my-project/* to http://127.0.0.1:18731/* . Static files are stored outside of /my-project/ . If the Django app does not need to redirect anything, this works just fine, but if it tries to redirect a request (e.g. to add a trailing slash to http://example.com/my-project/foo ), it ends up removing /my-project/ from the URL, leaving me with the invalid URL http://example.com/foo/ . My mod_proxy configuration is as follows: <Proxy *> Order deny

Gunicorn Connection in Use: ('0.0.0.0', 5000)

∥☆過路亽.° 提交于 2019-12-04 03:05:57
I installed redis this afternoon and it caused a few errors, so I uninstalled it but this error is persisting when I launch the app with foreman start . Any ideas on a fix? foreman start 22:46:26 web.1 | started with pid 1727 22:46:26 web.1 | 2013-05-25 22:46:26 [1727] [INFO] Starting gunicorn 0.17.4 22:46:26 web.1 | 2013-05-25 22:46:26 [1727] [ERROR] Connection in use: ('0.0.0.0', 5000) Check your processes. You may have had an unclean exit, leaving a zombie'd process behind that's still running. Just type sudo fuser -k 5000/tcp .This will kill all process associated with port 5000 This

Why is gunicorn_django not recommended anymore?

拥有回忆 提交于 2019-12-04 02:30:23
We have an app deployed using gunicorn_django in production. I've noticed that it's no longer recommended. I'm wondering why it's not recommended, and whether we need to migrate to the newer way. From https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/gunicorn/ If you run Django 1.4 or newer, it’s highly recommended to simply run your application with the WSGI interface using the gunicorn command. Ivan Kharlamov The essential part of gunicorn_django , wsgi.py , became integrated in Django itself. To quote an already existing answer : Starting with Django 1.4, your project will already

从0到1,Python Web开发的进击之路

痞子三分冷 提交于 2019-12-04 00:44:58
本文将以个人(开发)的角度,讲述如何从零开始,编写、搭建和部署一个基于Python的Web应用程序。 从最简单的出发点来剖析,一个web应用后端要完成的工作抽象出来无非就是3点: 接收和解析请求。 处理业务逻辑。 生产和返回响应。 对于初学者来说,我们关心的只需这些步骤就够了。要检验这三个步骤,最简单的方法是先写出一个hello world。 request->"hello world"->response python有许多流行的web框架,我们该如何选择呢?试着考虑三个因素: 易用:该框架是面对初学者友好的,而且具有健全的文档,灵活开发部署。例如flask,bottle。 效率:该框架适合快速开发,拥有丰富的轮子,注重开发效率。例如django。 性能:该框架能承载更大的请求压力,提高吞吐量。例如falcon,tornado,aiohttp,sanic。 根据场景使用合适的框架能少走许多弯路,当然,你还能自己写一个框架,这个下面再说。 对于缺乏经验的人来说,易用性无疑是排在第一位的,推荐用flask作为python web入门的第一个框架,另外也推荐django。 首先用virtualenv创建python的应用环境,为什么用virtualenv呢,virtualenv能创建一个纯净独立的python环境,避免污染全局环境。(顺便安利kennethreitz大神的 pipenv

gunicorn slower than flask development server

馋奶兔 提交于 2019-12-03 21:38:41
My Flask application has a simple feature with a textarea where you input HTML and clicking on a button will strip all the HTML tags and return the text inside the HTML into another textarea, say Text. When I run my application with: app.run(debug=True, host='0.0.0.0', port='8000') it works very fast and smooth. But when I run it with gunicorn like this: gunicorn -w 3 -b 0.0.0.0:8000 --log-file=- myapp.app:app after I click the button 'HtmlToText' it takes too much time to return the text value and the larger the HTML the longest it takes. Context: The button is a simple JQuery function that