在python中執行go webserver
在 python 中使用 go 做 webserver,便利和效能兼得,有沒有這種玩法?
答案是肯定的,就有這麼個專案gohttplib
使用示例:
from gohttp import route, run @route('/') def index(w, req): w.write("%s %s %s\n" % (req.method, req.host, req.url)) w.write("Hello, world.\n") run(host='127.0.0.1', port=5000)
作者還做了個簡單的壓力測試
NAME | TOTAL | REQ/SEC | TIME/REQ |
---|---|---|---|
go-net/http | 1.115 | 8969.89 | 0.111 |
gohttp-c | 1.181 | 8470.97 | 0.118 |
gohttp-python | 1.285 | 7779.87 | 0.129 |
gunicorn-flask | 7.826 | 1277.73 | 0.783 |
werkzeug-flask | 15.029 | 665.37 | 1.503 |
看起來效能比flask要好。
然而你需要自己管理 c 的一堆依賴,此專案已經三年沒更新了,估計實踐效果不怎麼樣。