传说中1200k的python微框架japronto

只因瞄到http://developer.51cto.com/art/201704/537960.htm这篇文章
也不知道哪里来的120万,也没有好几倍那么夸张。
英文原文在这里https://medium.com/@squeaky_pl/million-requests-per-second-with-python-95c137af319

只是个毫无意义的hello world benchmark
对比对象是go的标准库与fasthttp,竟然超出那么多,不科学

环境

Mac mini (Late 2014)
处理器: 2.6 GHz Intel Core i5
内存: 8 GB 1600 MHz DDR3

go version: go1.8 darwin/amd64
python version: 3.6
japronto version: 0.1.1  https://github.com/squeaky-pl/japronto
fasthttp version: 最新  https://github.com/valyala/fasthttp

工具
hey https://github.com/rakyll/hey

go stdlib

package main

import (
    "net/http"
)

func say(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("hello world"))
}

func main() {
    http.HandleFunc(`/`, say)
    http.ListenAndServe(":8082", nil)
}

go fasthttp

package main

import (
    fst "github.com/valyala/fasthttp"
    "fmt"
)

func Handler(c *fst.RequestCtx) {
    c.Write([]byte("hello world"))
}

func main() {
    var port = ":8081"
    fmt.Println("serv on", port)
    fst.ListenAndServe(port, Handler)
}

python japronto

from japronto import Application


def hello(req):
    return req.Response(text='hello world')


app = Application()
app.router.add_route('/', hello)
app.run(debug=False)

测试结果

hellobench.png

虽然只是简单的hello world测试,但是还是可以看出japronto的io处理还是极具效率的,只是以其目前的生态还难以投入生产,等其周边配套齐全后,应该是个非常不错的框架。

绝大多数环境下的服务器瓶颈都在于io,所以python的慢根本微不足道。而其简洁快速的开发与强大的胶水能力才是其杀手锏。

当然其部署也是个短板,永远没有go来得方便

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容