作者:AngryFox 分类: Uncategorized May 8th, 2016 暂无评论

optimization opportunities:
net/http Request object lifetime isn’t limited by request handler execution time. So the server must create new request object per each request instead of reusing existing objects like fasthttp do.
net/http headers are stored in a map[string][]string. So the server must parse all the headers, convert them from []byte to string and put them into the map before calling user-provided request handler. This all requires unnecessary memory allocations avoided by fasthttp.
net/http client API requires creating new response object per each request.

asthttp并没有完全地解析所有的http请求header数据

type RequestHeader struct {
        //bla.....
	contentLength      int
	contentLengthBytes []byte

	method      []byte
	requestURI  []byte
	host        []byte
	contentType []byte
	userAgent   []byte

	h     []argsKV
	bufKV argsKV

	cookies []argsKV

	rawHeaders []byte
}
argsKV

type argsKV struct {
	key   []byte
	value []byte
}

从[]byte转化为string时是有copy和alloc的,net.http中使用了map[string]string来存储各种其他参数,这就需要alloc,为了达成zero alloc,fasthttp采用了遍历所有header参数来返回,[]byte alloc
net.http的header头对象每次创建新的,而不是循环利用,而且做map[string]string转换