mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vminsert: replace hybrid sync.Pool+channel-based pool scheme for poolCtx with plain sync.Pool
This simplifies the code, while doesn't increase memory usage under low and high data ingestion rate.
This is a follow-up for 1decbcf6eb
This commit is contained in:
parent
1decbcf6eb
commit
8942f290eb
3 changed files with 8 additions and 31 deletions
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert/common"
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert/common"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert/relabel"
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert/relabel"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup"
|
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompb"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompb"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
||||||
parserCommon "github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/common"
|
parserCommon "github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/common"
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert/common"
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert/common"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert/relabel"
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert/relabel"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup"
|
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
||||||
parserCommon "github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/common"
|
parserCommon "github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/common"
|
||||||
|
@ -90,25 +89,15 @@ func (ctx *pushCtx) reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPushCtx() *pushCtx {
|
func getPushCtx() *pushCtx {
|
||||||
select {
|
if v := pushCtxPool.Get(); v != nil {
|
||||||
case ctx := <-pushCtxPoolCh:
|
return v.(*pushCtx)
|
||||||
return ctx
|
|
||||||
default:
|
|
||||||
if v := pushCtxPool.Get(); v != nil {
|
|
||||||
return v.(*pushCtx)
|
|
||||||
}
|
|
||||||
return &pushCtx{}
|
|
||||||
}
|
}
|
||||||
|
return &pushCtx{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func putPushCtx(ctx *pushCtx) {
|
func putPushCtx(ctx *pushCtx) {
|
||||||
ctx.reset()
|
ctx.reset()
|
||||||
select {
|
pushCtxPool.Put(ctx)
|
||||||
case pushCtxPoolCh <- ctx:
|
|
||||||
default:
|
|
||||||
pushCtxPool.Put(ctx)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var pushCtxPool sync.Pool
|
var pushCtxPool sync.Pool
|
||||||
var pushCtxPoolCh = make(chan *pushCtx, cgroup.AvailableCPUs())
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert/common"
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert/common"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert/relabel"
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert/relabel"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup"
|
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
||||||
parserCommon "github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/common"
|
parserCommon "github.com/VictoriaMetrics/VictoriaMetrics/lib/protoparser/common"
|
||||||
|
@ -96,25 +95,15 @@ func (ctx *pushCtx) reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPushCtx() *pushCtx {
|
func getPushCtx() *pushCtx {
|
||||||
select {
|
if v := pushCtxPool.Get(); v != nil {
|
||||||
case ctx := <-pushCtxPoolCh:
|
return v.(*pushCtx)
|
||||||
return ctx
|
|
||||||
default:
|
|
||||||
if v := pushCtxPool.Get(); v != nil {
|
|
||||||
return v.(*pushCtx)
|
|
||||||
}
|
|
||||||
return &pushCtx{}
|
|
||||||
}
|
}
|
||||||
|
return &pushCtx{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func putPushCtx(ctx *pushCtx) {
|
func putPushCtx(ctx *pushCtx) {
|
||||||
ctx.reset()
|
ctx.reset()
|
||||||
select {
|
pushCtxPool.Put(ctx)
|
||||||
case pushCtxPoolCh <- ctx:
|
|
||||||
default:
|
|
||||||
pushCtxPool.Put(ctx)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var pushCtxPool sync.Pool
|
var pushCtxPool sync.Pool
|
||||||
var pushCtxPoolCh = make(chan *pushCtx, cgroup.AvailableCPUs())
|
|
||||||
|
|
Loading…
Reference in a new issue