fasthttp:一个比官方net/http 快10 倍的http server
Fast HTTP implementation for Go.
Currently fasthttp is successfully used in a production serving up to 1M concurrent keep-alive connections doing 50K qps from a single server.
In short, fasthttp is up to 10 times faster than net/http.
项目地址 https://github.com/valyala/fasthttp 271
跟标准库比,在下面四个方面得到改进:
net/http 的实现是一个连接新建一个 goroutine;fasthttp 是利用一个 worker 复用 goroutine,减轻 runtime 调度 goroutine 的压力
net/http 解析的请求数据很多放在 map[string]string(http.Header) 或 map[string][]string(http.Request.Form),有不必要的 []byte 到 string 的转换,是可以规避的
net/http 解析 HTTP 请求每次生成新的 *http.Request 和 http.ResponseWriter; fasthttp 解析 HTTP 数据到 *fasthttp.RequestCtx,然后使用 sync.Pool 复用结构实例,减少对象的数量
fasthttp 会延迟解析 HTTP 请求中的数据,尤其是 Body 部分。这样节省了很多不直接操作 Body 的情况的消耗
这家伙写了好多'fast' 系列:
fasthttp: Fast HTTP package for Go
ybc: Fast in-process BLOB cache with persistence support
gorpc: Simple, fast and scalable golang rpc library for high load
goloris: Slowloris for nginx DoS. Written in go
gheap: Fast generalized heap tree algorithms in C++ and C. Provides simultaneous support for D-heap and B-heap.
http, 10, server, fasthttp, 官方
相关帖子:
- BAE绑定了域名了欢迎大家来看看和发贴http://www.5036m.com/
- http://youqu.de 2个功能: 1点击列表最右边的数字,可以展开快捷回复哦~2点击人名可以@
- 支持 fasthttp 三个 websocket 库
- 一个国内能访问的golang文档(官方)镜像
- net/http + mux 简单示例
- http://10998.1kapp.com/ 还不错确实很快啊
- ```http://maxgj.net```
- http://www.myfreecams.com/mfc2/static/
- http://img1.gtimg.com/tech/pics/hv1/147/30/1091/70950072.jpg
- [源码探讨]SetCookie和DelCookie为什么要用&http.Cookie这种获取地址的方式啊?
这个库最近发展的很捉急,一下收了1171 颗星。
作者在后面给出了go 程序优化的建议。
有人问道:为什么不去优化net/http? 他说:本来想去优化net/http 的,但它的设计思想只能让我重写。
加上路由的例子
package main
import (
"fmt"
"log"
"github.com/buaazp/fasthttprouter"
"github.com/valyala/fasthttp"
)
func Index(ctx *fasthttp.RequestCtx, _ fasthttprouter.Params) {
fmt.Fprint(ctx, "Welcome!n")
}
func Hello(ctx *fasthttp.RequestCtx, ps fasthttprouter.Params) {
fmt.Fprintf(ctx, "hello, %s!n", ps.ByName("name"))
}
func main() {
router := fasthttprouter.New()
router.GET("/", Index)
router.GET("/hello/:name", Hello)
log.Fatal(fasthttp.ListenAndServe(":8080", router.Handler))
}
fasthttp-postgresql 在最新一轮跑分中脱颖而出
https://www.techempower.com/benchmarks/ 26 https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/frameworks/Go/fasthttp-postgresql 31
新出的一个模版引擎也很牛(20x faster than html/template) https://github.com/valyala/quicktemplate 37 上面的库会编译为一个go 文件,不能动态载入,如果要动态载入可以用 https://github.com/valyala/fasttemplate 39 也是这个牛人写的