item count for mapblock accessor
This commit is contained in:
parent
7533036967
commit
dfbb63aec7
@ -57,6 +57,11 @@ The mapserver will generate a fresh `mapserver.json` if there is none at startup
|
|||||||
"smartshop": true,
|
"smartshop": true,
|
||||||
"fancyvend": true,
|
"fancyvend": true,
|
||||||
"atm": true
|
"atm": true
|
||||||
|
},
|
||||||
|
"mapblockaccessor": {
|
||||||
|
"expiretime": "10s",
|
||||||
|
"purgetime": "15s",
|
||||||
|
"maxitems": 10
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -107,3 +112,6 @@ Faster system can use the default (10'000)
|
|||||||
|
|
||||||
#### enableprometheus
|
#### enableprometheus
|
||||||
Enables the [Prometheus](./prometheus.md) metrics endpoint
|
Enables the [Prometheus](./prometheus.md) metrics endpoint
|
||||||
|
|
||||||
|
#### mapblockaccessor.maxitems
|
||||||
|
Number of mapblocks to keep in memory, dial this down if you have memory issues
|
||||||
|
@ -13,25 +13,24 @@ import (
|
|||||||
func (a *MapBlockAccessor) GetMapBlock(pos *coords.MapBlockCoords) (*mapblockparser.MapBlock, error) {
|
func (a *MapBlockAccessor) GetMapBlock(pos *coords.MapBlockCoords) (*mapblockparser.MapBlock, error) {
|
||||||
key := getKey(pos)
|
key := getKey(pos)
|
||||||
|
|
||||||
if a.c.ItemCount() > a.maxcount {
|
cacheBlocks.Set(float64(a.blockcache.ItemCount()))
|
||||||
|
if a.blockcache.ItemCount() > a.maxcount {
|
||||||
//flush cache
|
//flush cache
|
||||||
fields := logrus.Fields{
|
fields := logrus.Fields{
|
||||||
"cached items": a.c.ItemCount(),
|
"cached items": a.blockcache.ItemCount(),
|
||||||
"maxcount": a.maxcount,
|
"maxcount": a.maxcount,
|
||||||
}
|
}
|
||||||
logrus.WithFields(fields).Warn("Flushing cache")
|
logrus.WithFields(fields).Debug("Flushing cache")
|
||||||
|
|
||||||
a.c.Flush()
|
a.blockcache.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
cachedblock, found := a.c.Get(key)
|
cachedblock, found := a.blockcache.Get(key)
|
||||||
if found {
|
if found {
|
||||||
getCacheHitCount.Inc()
|
getCacheHitCount.Inc()
|
||||||
return cachedblock.(*mapblockparser.MapBlock), nil
|
return cachedblock.(*mapblockparser.MapBlock), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
getCacheMissCount.Inc()
|
|
||||||
|
|
||||||
timer := prometheus.NewTimer(dbGetDuration)
|
timer := prometheus.NewTimer(dbGetDuration)
|
||||||
defer timer.ObserveDuration()
|
defer timer.ObserveDuration()
|
||||||
|
|
||||||
@ -41,9 +40,14 @@ func (a *MapBlockAccessor) GetMapBlock(pos *coords.MapBlockCoords) (*mapblockpar
|
|||||||
}
|
}
|
||||||
|
|
||||||
if block == nil {
|
if block == nil {
|
||||||
|
//no mapblock here
|
||||||
|
cacheBlockCount.Inc()
|
||||||
|
a.blockcache.Set(key, nil, cache.DefaultExpiration)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCacheMissCount.Inc()
|
||||||
|
|
||||||
mapblock, err := mapblockparser.Parse(block.Data, block.Mtime, pos)
|
mapblock, err := mapblockparser.Parse(block.Data, block.Mtime, pos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -51,7 +55,8 @@ func (a *MapBlockAccessor) GetMapBlock(pos *coords.MapBlockCoords) (*mapblockpar
|
|||||||
|
|
||||||
a.Eventbus.Emit(eventbus.MAPBLOCK_RENDERED, mapblock)
|
a.Eventbus.Emit(eventbus.MAPBLOCK_RENDERED, mapblock)
|
||||||
|
|
||||||
a.c.Set(key, mapblock, cache.DefaultExpiration)
|
cacheBlockCount.Inc()
|
||||||
|
a.blockcache.Set(key, mapblock, cache.DefaultExpiration)
|
||||||
|
|
||||||
return mapblock, nil
|
return mapblock, nil
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,8 @@ func (a *MapBlockAccessor) FindNextLegacyBlocks(s settings.Settings, layers []*l
|
|||||||
|
|
||||||
a.Eventbus.Emit(eventbus.MAPBLOCK_RENDERED, mapblock)
|
a.Eventbus.Emit(eventbus.MAPBLOCK_RENDERED, mapblock)
|
||||||
|
|
||||||
a.c.Set(key, mapblock, cache.DefaultExpiration)
|
a.blockcache.Set(key, mapblock, cache.DefaultExpiration)
|
||||||
|
cacheBlockCount.Inc()
|
||||||
mblist = append(mblist, mapblock)
|
mblist = append(mblist, mapblock)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type MapBlockAccessor struct {
|
type MapBlockAccessor struct {
|
||||||
accessor db.DBAccessor
|
accessor db.DBAccessor
|
||||||
c *cache.Cache
|
blockcache *cache.Cache
|
||||||
Eventbus *eventbus.Eventbus
|
Eventbus *eventbus.Eventbus
|
||||||
maxcount int
|
maxcount int
|
||||||
}
|
}
|
||||||
|
|
||||||
func getKey(pos *coords.MapBlockCoords) string {
|
func getKey(pos *coords.MapBlockCoords) string {
|
||||||
@ -23,12 +23,12 @@ func getKey(pos *coords.MapBlockCoords) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewMapBlockAccessor(accessor db.DBAccessor, expiretime, purgetime time.Duration, maxcount int) *MapBlockAccessor {
|
func NewMapBlockAccessor(accessor db.DBAccessor, expiretime, purgetime time.Duration, maxcount int) *MapBlockAccessor {
|
||||||
c := cache.New(expiretime, purgetime)
|
blockcache := cache.New(expiretime, purgetime)
|
||||||
|
|
||||||
return &MapBlockAccessor{
|
return &MapBlockAccessor{
|
||||||
accessor: accessor,
|
accessor: accessor,
|
||||||
c: c,
|
blockcache: blockcache,
|
||||||
Eventbus: eventbus.New(),
|
Eventbus: eventbus.New(),
|
||||||
maxcount: maxcount,
|
maxcount: maxcount,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,8 @@ func (a *MapBlockAccessor) FindMapBlocksByMtime(lastmtime int64, limit int, laye
|
|||||||
|
|
||||||
a.Eventbus.Emit(eventbus.MAPBLOCK_RENDERED, mapblock)
|
a.Eventbus.Emit(eventbus.MAPBLOCK_RENDERED, mapblock)
|
||||||
|
|
||||||
a.c.Set(key, mapblock, cache.DefaultExpiration)
|
a.blockcache.Set(key, mapblock, cache.DefaultExpiration)
|
||||||
|
cacheBlockCount.Inc()
|
||||||
mblist = append(mblist, mapblock)
|
mblist = append(mblist, mapblock)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,18 @@ var (
|
|||||||
Help: "Count of db cache miss",
|
Help: "Count of db cache miss",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
cacheBlockCount = prometheus.NewCounter(
|
||||||
|
prometheus.CounterOpts{
|
||||||
|
Name: "dbcache_block_count",
|
||||||
|
Help: "Count of db blocks inserted",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
cacheBlocks = prometheus.NewGauge(
|
||||||
|
prometheus.GaugeOpts{
|
||||||
|
Name: "dbcache_blocks",
|
||||||
|
Help: "Block count currently in the cache",
|
||||||
|
},
|
||||||
|
)
|
||||||
dbGetDuration = prometheus.NewHistogram(prometheus.HistogramOpts{
|
dbGetDuration = prometheus.NewHistogram(prometheus.HistogramOpts{
|
||||||
Name: "db_get_duration",
|
Name: "db_get_duration",
|
||||||
Help: "Histogram for db mapblock get durations",
|
Help: "Histogram for db mapblock get durations",
|
||||||
@ -33,6 +45,9 @@ func init() {
|
|||||||
prometheus.MustRegister(getCacheHitCount)
|
prometheus.MustRegister(getCacheHitCount)
|
||||||
prometheus.MustRegister(getCacheMissCount)
|
prometheus.MustRegister(getCacheMissCount)
|
||||||
|
|
||||||
|
prometheus.MustRegister(cacheBlockCount)
|
||||||
|
prometheus.MustRegister(cacheBlocks)
|
||||||
|
|
||||||
prometheus.MustRegister(dbGetDuration)
|
prometheus.MustRegister(dbGetDuration)
|
||||||
prometheus.MustRegister(dbGetMtimeDuration)
|
prometheus.MustRegister(dbGetMtimeDuration)
|
||||||
}
|
}
|
||||||
|
@ -9,5 +9,6 @@ import (
|
|||||||
|
|
||||||
func (a *MapBlockAccessor) Update(pos *coords.MapBlockCoords, mb *mapblockparser.MapBlock) {
|
func (a *MapBlockAccessor) Update(pos *coords.MapBlockCoords, mb *mapblockparser.MapBlock) {
|
||||||
key := getKey(pos)
|
key := getKey(pos)
|
||||||
a.c.Set(key, mb, cache.DefaultExpiration)
|
cacheBlockCount.Inc()
|
||||||
|
a.blockcache.Set(key, mb, cache.DefaultExpiration)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user