2

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
  • I tested a similar code in a project, in my case the stream freezed on a debian 7/Wheezy with mod_wsgi on apache2 Commented Dec 11, 2014 at 15:53

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I've switched to Tornado+Nginx instead of Flask+Apache. Nginx' support for VirtualHosts is as nice as Apache's and Tornado works perfectly for HTTP streaming. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.