mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
scalability improvement: initialize RequestCtx.id only when creating new RequestCtx obect. This should reduce globalCtxID contention
This commit is contained in:
@@ -1144,21 +1144,20 @@ func releaseWriter(s *Server, w *bufio.Writer) {
|
||||
s.writerPool.Put(w)
|
||||
}
|
||||
|
||||
var globalCtxID uint64
|
||||
|
||||
func (s *Server) acquireCtx(c net.Conn) *RequestCtx {
|
||||
v := s.ctxPool.Get()
|
||||
var ctx *RequestCtx
|
||||
if v == nil {
|
||||
ctx = &RequestCtx{
|
||||
s: s,
|
||||
c: c,
|
||||
}
|
||||
ctx.initID()
|
||||
ctx.v = ctx
|
||||
v = ctx
|
||||
} else {
|
||||
ctx = v.(*RequestCtx)
|
||||
return ctx
|
||||
}
|
||||
ctx.initID()
|
||||
|
||||
ctx = v.(*RequestCtx)
|
||||
ctx.c = c
|
||||
return ctx
|
||||
}
|
||||
@@ -1214,6 +1213,8 @@ func (fa *fakeAddrer) Close() error {
|
||||
panic("BUG: unexpected Close call")
|
||||
}
|
||||
|
||||
var globalCtxID uint64
|
||||
|
||||
func (ctx *RequestCtx) initID() {
|
||||
ctx.id = (atomic.AddUint64(&globalCtxID, 1)) << 32
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user