mirror of
https://github.com/kataras/iris.git
synced 2025-03-15 17:36:29 +01:00
Nothing really special, but tests seems to match better with old-style .New() on contextPool although I though that was the same thing...
This commit is contained in:
parent
1fda6383f3
commit
1537a657c0
26
iris.go
26
iris.go
|
@ -170,7 +170,7 @@ type (
|
||||||
// Implements the FrameworkAPI
|
// Implements the FrameworkAPI
|
||||||
Framework struct {
|
Framework struct {
|
||||||
*muxAPI
|
*muxAPI
|
||||||
contextPool sync.Pool
|
contextPool *sync.Pool
|
||||||
Config *config.Iris
|
Config *config.Iris
|
||||||
sessions fasthttpSessions.Sessions
|
sessions fasthttpSessions.Sessions
|
||||||
responses *responseEngines
|
responses *responseEngines
|
||||||
|
@ -217,7 +217,9 @@ func New(cfg ...config.Iris) *Framework {
|
||||||
"url": s.URL,
|
"url": s.URL,
|
||||||
"urlpath": s.Path,
|
"urlpath": s.Path,
|
||||||
})
|
})
|
||||||
|
s.contextPool = &sync.Pool{New: func() interface{} {
|
||||||
|
return &Context{framework: s}
|
||||||
|
}}
|
||||||
// set the websocket server
|
// set the websocket server
|
||||||
s.Websocket = NewWebsocketServer(s.Config.Websocket)
|
s.Websocket = NewWebsocketServer(s.Config.Websocket)
|
||||||
// set the servemux, which will provide us the public API also, with its context pool
|
// set the servemux, which will provide us the public API also, with its context pool
|
||||||
|
@ -296,28 +298,28 @@ func (s *Framework) initialize() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* not used anymore, we had 2% performance reduce
|
||||||
func (s *Framework) acquireCtx(reqCtx *fasthttp.RequestCtx) *Context {
|
func (s *Framework) acquireCtx(reqCtx *fasthttp.RequestCtx) *Context {
|
||||||
v := s.contextPool.Get()
|
v := s.contextPool.Get()
|
||||||
var ctx *Context
|
|
||||||
if v == nil {
|
if v == nil {
|
||||||
ctx = &Context{
|
return &Context{
|
||||||
RequestCtx: reqCtx,
|
RequestCtx: reqCtx,
|
||||||
framework: s,
|
framework: s,
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
ctx = v.(*Context)
|
ctx := v.(*Context)
|
||||||
ctx.Params = ctx.Params[0:0]
|
ctx.Params = ctx.Params[0:0]
|
||||||
ctx.RequestCtx = reqCtx
|
ctx.RequestCtx = reqCtx
|
||||||
ctx.middleware = nil
|
ctx.middleware = nil
|
||||||
ctx.session = nil
|
ctx.session = nil
|
||||||
}
|
|
||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Framework) releaseCtx(ctx *Context) {
|
func (s *Framework) releaseCtx(ctx *Context) {
|
||||||
s.contextPool.Put(ctx)
|
s.contextPool.Put(ctx)
|
||||||
}
|
}
|
||||||
|
// so .New() is better because of internal .Get() pins
|
||||||
|
*/
|
||||||
|
|
||||||
// Go starts the iris station, listens to all registered servers, and prepare only if Virtual
|
// Go starts the iris station, listens to all registered servers, and prepare only if Virtual
|
||||||
func Go() error {
|
func Go() error {
|
||||||
|
@ -331,9 +333,13 @@ func (s *Framework) Go() error {
|
||||||
// build the fasthttp handler to bind it to the servers
|
// build the fasthttp handler to bind it to the servers
|
||||||
h := s.mux.Handler()
|
h := s.mux.Handler()
|
||||||
reqHandler := func(reqCtx *fasthttp.RequestCtx) {
|
reqHandler := func(reqCtx *fasthttp.RequestCtx) {
|
||||||
ctx := s.acquireCtx(reqCtx)
|
ctx := s.contextPool.Get().(*Context)
|
||||||
|
ctx.Params = ctx.Params[0:0]
|
||||||
|
ctx.RequestCtx = reqCtx
|
||||||
|
ctx.middleware = nil
|
||||||
|
ctx.session = nil
|
||||||
h(ctx)
|
h(ctx)
|
||||||
s.releaseCtx(ctx)
|
s.contextPool.Put(ctx)
|
||||||
}
|
}
|
||||||
if firstErr := s.Servers.OpenAll(reqHandler); firstErr != nil {
|
if firstErr := s.Servers.OpenAll(reqHandler); firstErr != nil {
|
||||||
return firstErr
|
return firstErr
|
||||||
|
|
Loading…
Reference in New Issue
Block a user