unbit/uwsgi — pull request #723 by mikekap (2014-09-17 17:12:31+00:00)
Title: Don't spin if we exhaust the async worker pool.

This is a reopened #691 against the master branch (I assume that's why it was closed).

Scenario:
```python
import flask
import gevent
import sys

app = flask.Flask('repro')

@app.route('/')
def index():
gevent.sleep(3)
return 'Hello\n'

if __name__ == '__main__':
app.run(port=8080)
```

Running this with ```--gevent 1``` and starting 10 concurrent requests to the server puts uwsgi into a 100% cpu burn cycle. Gevent keeps notifying that there is a connection to accept and uwsgi ignores the signal due to async exhaustion. This isn't great behavior - in case of an outage of some other downstream server uwsgi burns all the cpu, not letting legitimate work get done. This isn't limited to ```--gevent 1``` of course.

This patch fixes the behavior by stopping the socket watcher if the async queue is exhausted. The worker greenlets resume the watchers when their requests complete if the watchers are not active.