|
@@ -13,8 +13,6 @@ import (
|
|
|
"runtime"
|
|
|
"sort"
|
|
|
"sync"
|
|
|
- "sync/atomic"
|
|
|
- "time"
|
|
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
"github.com/valyala/fasthttp"
|
|
@@ -95,22 +93,7 @@ func main() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const maxConnDuration = time.Millisecond * 1500
|
|
|
-
|
|
|
-var connDurationJitter uint64
|
|
|
-
|
|
|
func mainHandler(ctx *fasthttp.RequestCtx) {
|
|
|
- // Performance hack for prefork mode - periodically close keepalive
|
|
|
- // connections for evenly distributing connections among available
|
|
|
- // processes.
|
|
|
- if *prefork {
|
|
|
- maxDuration := maxConnDuration + time.Millisecond*time.Duration(atomic.LoadUint64(&connDurationJitter))
|
|
|
- if time.Since(ctx.ConnTime()) > maxDuration {
|
|
|
- atomic.StoreUint64(&connDurationJitter, uint64(rand.Intn(100)))
|
|
|
- ctx.SetConnectionClose()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
path := ctx.Path()
|
|
|
switch string(path) {
|
|
|
case "/plaintext":
|