mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
sessions: start session gc at startup but only after between 10 - 180 seconds
This commit is contained in:
parent
ebdd35d799
commit
c3202d3f99
@ -1,6 +1,7 @@
|
|||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-macaron/session"
|
"github.com/go-macaron/session"
|
||||||
@ -8,6 +9,7 @@ import (
|
|||||||
_ "github.com/go-macaron/session/mysql"
|
_ "github.com/go-macaron/session/mysql"
|
||||||
_ "github.com/go-macaron/session/postgres"
|
_ "github.com/go-macaron/session/postgres"
|
||||||
_ "github.com/go-macaron/session/redis"
|
_ "github.com/go-macaron/session/redis"
|
||||||
|
"github.com/grafana/grafana/pkg/log"
|
||||||
"gopkg.in/macaron.v1"
|
"gopkg.in/macaron.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -22,10 +24,12 @@ var sessionManager *session.Manager
|
|||||||
var sessionOptions *session.Options
|
var sessionOptions *session.Options
|
||||||
var startSessionGC func()
|
var startSessionGC func()
|
||||||
var getSessionCount func() int
|
var getSessionCount func() int
|
||||||
|
var sessionLogger = log.New("session")
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
startSessionGC = func() {
|
startSessionGC = func() {
|
||||||
sessionManager.GC()
|
sessionManager.GC()
|
||||||
|
sessionLogger.Debug("Session GC")
|
||||||
time.AfterFunc(time.Duration(sessionOptions.Gclifetime)*time.Second, startSessionGC)
|
time.AfterFunc(time.Duration(sessionOptions.Gclifetime)*time.Second, startSessionGC)
|
||||||
}
|
}
|
||||||
getSessionCount = func() int {
|
getSessionCount = func() int {
|
||||||
@ -67,7 +71,9 @@ func Sessioner(options *session.Options) macaron.Handler {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
go startSessionGC()
|
// start GC threads after some random seconds
|
||||||
|
rndSeconds := 10 + rand.Int63n(180)
|
||||||
|
time.AfterFunc(time.Duration(rndSeconds)*time.Second, startSessionGC)
|
||||||
|
|
||||||
return func(ctx *Context) {
|
return func(ctx *Context) {
|
||||||
ctx.Next()
|
ctx.Next()
|
||||||
|
Loading…
Reference in New Issue
Block a user