forked from TrueCloudLab/frostfs-node
[#6] services/policer: Reduce the amount of indirect pointers
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
724346a704
commit
b8f8462f38
1 changed files with 16 additions and 21 deletions
|
@ -51,11 +51,11 @@ func (oiw *objectsInWork) add(addr oid.Address) {
|
||||||
// Policer represents the utility that verifies
|
// Policer represents the utility that verifies
|
||||||
// compliance with the object storage policy.
|
// compliance with the object storage policy.
|
||||||
type Policer struct {
|
type Policer struct {
|
||||||
*cfg
|
cfg
|
||||||
|
|
||||||
cache *lru.Cache[oid.Address, time.Time]
|
cache *lru.Cache[oid.Address, time.Time]
|
||||||
|
|
||||||
objsInWork *objectsInWork
|
objsInWork objectsInWork
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option is an option for Policer constructor.
|
// Option is an option for Policer constructor.
|
||||||
|
@ -95,38 +95,33 @@ type cfg struct {
|
||||||
rebalanceFreq, evictDuration time.Duration
|
rebalanceFreq, evictDuration time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultCfg() *cfg {
|
func (c *cfg) initDefault() {
|
||||||
return &cfg{
|
c.log = &logger.Logger{Logger: zap.L()}
|
||||||
log: &logger.Logger{Logger: zap.L()},
|
c.batchSize = 10
|
||||||
batchSize: 10,
|
c.cacheSize = 1024 // 1024 * address size = 1024 * 64 = 64 MiB
|
||||||
cacheSize: 1024, // 1024 * address size = 1024 * 64 = 64 MiB
|
c.rebalanceFreq = 1 * time.Second
|
||||||
rebalanceFreq: 1 * time.Second,
|
c.evictDuration = 30 * time.Second
|
||||||
evictDuration: 30 * time.Second,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates, initializes and returns Policer instance.
|
// New creates, initializes and returns Policer instance.
|
||||||
func New(opts ...Option) *Policer {
|
func New(opts ...Option) *Policer {
|
||||||
c := defaultCfg()
|
var p Policer
|
||||||
|
p.cfg.initDefault()
|
||||||
|
|
||||||
for i := range opts {
|
for i := range opts {
|
||||||
opts[i](c)
|
opts[i](&p.cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.log = &logger.Logger{Logger: c.log.With(zap.String("component", "Object Policer"))}
|
p.log = &logger.Logger{Logger: p.cfg.log.With(zap.String("component", "Object Policer"))}
|
||||||
|
|
||||||
cache, err := lru.New[oid.Address, time.Time](int(c.cacheSize))
|
cache, err := lru.New[oid.Address, time.Time](int(p.cacheSize))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Policer{
|
p.cache = cache
|
||||||
cfg: c,
|
p.objsInWork.objs = make(map[oid.Address]struct{}, p.maxCapacity)
|
||||||
cache: cache,
|
return &p
|
||||||
objsInWork: &objectsInWork{
|
|
||||||
objs: make(map[oid.Address]struct{}, c.maxCapacity),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithHeadTimeout returns option to set Head timeout of Policer.
|
// WithHeadTimeout returns option to set Head timeout of Policer.
|
||||||
|
|
Loading…
Reference in a new issue