调优 #### Python Tracebacker ================== * 要启用这个回溯器,你需要添加选项 ``py-tracebacker=``,,其中,```` 是已创建 UNIX socket 的 ``basename`` * 如果你有 4 个 uWSGI worker,并且添加了 ``py-tracebacker=/tmp/tbsocket``,那么将会创建名字从 ``/tmp/tbsocket1`` 到 ``/tmp/tbsocket4`` 的 4 个 socket。 * 连接到其中任意一个都将会返回 worker 中运行的线程的当前回溯。 * 你可以使用你最喜欢的应用或方法来连接到那些 socket,但是 uWSGI 有一个供你使用的方便的选项 ``connect-and-read`` :: uwsgi --connect-and-read /tmp/tbsocket1 写一个名为 ``slow.py`` 的蠢蠢的测试应用:: import time def dormi(): time.sleep(60) def dormi2(): dormi() def dormi3(): dormi2() def dormi4(): dormi3() def dormi5(): dormi4() def application(e, start_response): start_response('200 OK', [('Content-Type', 'text/html')]) dormi5() return "hello" 运行:: $ uwsgi --http :8080 -w slow --master --processes 2 --threads 4 --py-tracebacker /tmp/tbsocket. *** uWSGI is running in multiple interpreter mode *** spawned uWSGI master process (pid: 8955) spawned uWSGI worker 1 (pid: 8956, cores: 4) spawned uWSGI worker 2 (pid: 8957, cores: 4) spawned uWSGI http 1 (pid: 8958) python tracebacker for worker 1 available on /tmp/tbsocket.1 python tracebacker for worker 2 available on /tmp/tbsocket.2 创建一堆到它的请求:: curl http://localhost:8080 & curl http://localhost:8080 & curl http://localhost:8080 & curl http://localhost:8080 & 当这些请求运行的时候 (每个都会花费几乎一分钟来完成),你就可以检索回溯:: ./uwsgi --connect-and-read /tmp/tbsocket.1 ./uwsgi --connect-and-read /tmp/tbsocket.2 回溯器的输出将会是这样的:: *** uWSGI Python tracebacker output *** thread_id = uWSGIWorker1Core1 filename = ./slow.py lineno = 22 function = application line = dormi5() thread_id = uWSGIWorker1Core1 filename = ./slow.py lineno = 14 function = dormi5 line = def dormi5(): dormi4() thread_id = uWSGIWorker1Core1 filename = ./slow.py lineno = 13 function = dormi4 line = def dormi4(): dormi3() thread_id = uWSGIWorker1Core1 filename = ./slow.py lineno = 12 function = dormi3 line = def dormi3(): dormi2() thread_id = uWSGIWorker1Core1 filename = ./slow.py lineno = 11 function = dormi2 line = def dormi2(): dormi() thread_id = uWSGIWorker1Core1 filename = ./slow.py lineno = 9 function = dormi line = time.sleep(60) thread_id = uWSGIWorker1Core3 filename = ./slow.py lineno = 22 function = application line = dormi5() thread_id = uWSGIWorker1Core3 filename = ./slow.py lineno = 14 function = dormi5 line = def dormi5(): dormi4() thread_id = uWSGIWorker1Core3 filename = ./slow.py lineno = 13 function = dormi4 line = def dormi4(): dormi3() thread_id = uWSGIWorker1Core3 filename = ./slow.py lineno = 12 function = dormi3 line = def dormi3(): dormi2() thread_id = uWSGIWorker1Core3 filename = ./slow.py lineno = 11 function = dormi2 line = def dormi2(): dormi() thread_id = uWSGIWorker1Core3 filename = ./slow.py lineno = 9 function = dormi line = time.sleep(60)