http://uwsgi-docs.readthedocs.io/en/latest/Gevent.html?highlight=gevent While watching, try running uwsgi in gevent mode.
nginx: 1.10.1 python: 2.7.10 uwsgi: 2.0.13.1 Since it is built locally, nginx-uwsgi communicates on Unix domain sockets.
Added gevent parameter
uwsgi.ini
[uwsgi]
...
gevent = 40
The value here is the number of workers in gevent, but I don't know the optimal value. (I want someone to tell me)
It seems that gevent does not support the MySQL connector if it is MySQL Python. Use PyMySQL. Also, if you use Django, if you use PyMySQL as it is, it will not mesh with the backend implementation, so at startup,
import pymysql
pymysql.install_as_MySQLdb()
You need to do.
At the beginning of the uwsgi startup module,
import gevent.monkey
gevent.monkey.patch_all()
Apply the monkey patch with. (To be executed before other imports) It seems that gevent-monkey-patch = true can also be used in uwsgi.ini, In my environment, I got an error around MySQL and it didn't work. Perhaps it's related to the internal import order.
Run uwsgi as usual,
*** running gevent loop engine [addr:0x10e228440] ***
If a message like this is displayed, the startup is successful in gevent mode. After that, try HTTP request and if no error occurs, it's OK.
It is hard to realize the difference between no gevent and not (because it is local). I still don't know the optimum value of the parameter, so I will try various things and verify it.
Recommended Posts