HTTP Streaming with Apache mod_wsgi

我的梦境 提交于 2020-01-16 01:19:31

问题


I've got an ubuntu-server where I am running multiple web-apps. All of them are hosted by Apache using named VirtualHosts. One of them is a Flask app, which is running via mod_wsgi. This app is serving continuous, unlimited HTTP streams.

Does this eventually block my app/server/apache worker, if enough clients are connecting to the streaming endpoint? And if yes, are there alternatives? Other non-blocking wsgi-servers that play nicely with VirtualHosts, a different http-streaming paradigm, or some magic apache mod_wsgi settings?

The core of it looks like:

@app.route('/stream')
def get_stream():
    def endless():
        while True:
            yield get_stuff_from_redis()
            time.sleep(1)

    return Response(endless(), mimetype='application/json')

回答1:


If the clients never disconnect, yes, you will eventually run out of processes/threads to handle more requests.

You are more than likely better off using a async framework such as Tornado or Twisted for this specific type of application. Doing async programming can be tricky if you aren't used to that concept.

Some people use coroutine system such as gevent/eventlet, but they also have their own problems you have to watch out for.



来源:https://stackoverflow.com/questions/21424648/http-streaming-with-apache-mod-wsgi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!