scalability improvement: initialize RequestCtx.id only when creating new RequestCtx obect. This should reduce globalCtxID contention

This commit is contained in:
Aliaksandr Valialkin
2015-11-28 17:23:53 +02:00
parent a5a2571194
commit d8c882d360
+7 -6
View File
@@ -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
}