Question

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')
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top