mapblock accessor cache cfg

This commit is contained in:
Thomas Rudin 2019-02-22 19:13:47 +01:00
parent 42580ee310
commit bab8b483ed
4 changed files with 42 additions and 17 deletions

View File

@ -10,16 +10,22 @@ import (
)
type Config struct {
Port int `json:"port"`
EnablePrometheus bool `json:"enableprometheus"`
EnableRendering bool `json:"enablerendering"`
Webdev bool `json:"webdev"`
WebApi *WebApiConfig `json:"webapi"`
Layers []*layer.Layer `json:"layers"`
RenderingFetchLimit int `json:"renderingfetchlimit"`
RenderingJobs int `json:"renderingjobs"`
RenderingQueue int `json:"renderingqueue"`
MapObjects *MapObjectConfig `json:"mapobjects"`
Port int `json:"port"`
EnablePrometheus bool `json:"enableprometheus"`
EnableRendering bool `json:"enablerendering"`
Webdev bool `json:"webdev"`
WebApi *WebApiConfig `json:"webapi"`
Layers []*layer.Layer `json:"layers"`
RenderingFetchLimit int `json:"renderingfetchlimit"`
RenderingJobs int `json:"renderingjobs"`
RenderingQueue int `json:"renderingqueue"`
MapObjects *MapObjectConfig `json:"mapobjects"`
MapBlockAccessorCfg *MapBlockAccessorConfig `json:"mapblockaccessor"`
}
type MapBlockAccessorConfig struct {
Expiretime string `json:"expiretime"`
Purgetime string `json:"purgetime"`
}
type MapObjectConfig struct {
@ -106,6 +112,11 @@ func ParseConfig(filename string) (*Config, error) {
ATM: true,
}
mapblockaccessor := MapBlockAccessorConfig{
Expiretime: "500ms",
Purgetime: "1000ms",
}
cfg := Config{
Port: 8080,
EnableRendering: true,
@ -117,6 +128,7 @@ func ParseConfig(filename string) (*Config, error) {
RenderingJobs: runtime.NumCPU(),
RenderingQueue: 100,
MapObjects: &mapobjs,
MapBlockAccessorCfg: &mapblockaccessor,
}
info, err := os.Stat(filename)

View File

@ -13,12 +13,13 @@ import (
"mapserver/tiledb"
"mapserver/tilerenderer"
"mapserver/worldconfig"
"github.com/sirupsen/logrus"
"time"
"io/ioutil"
"os"
"github.com/sirupsen/logrus"
"errors"
)
@ -58,7 +59,17 @@ func Setup(p params.ParamsType, cfg *Config) *App {
}
//mapblock accessor
a.BlockAccessor = mapblockaccessor.NewMapBlockAccessor(a.Blockdb)
expireDuration, err := time.ParseDuration(cfg.MapBlockAccessorCfg.Expiretime)
if err != nil {
panic(err)
}
purgeDuration, err := time.ParseDuration(cfg.MapBlockAccessorCfg.Purgetime)
if err != nil {
panic(err)
}
a.BlockAccessor = mapblockaccessor.NewMapBlockAccessor(a.Blockdb, expireDuration, purgeDuration)
//color mapping
a.Colormapping = colormapping.NewColorMapping()

View File

@ -21,8 +21,8 @@ func getKey(pos *coords.MapBlockCoords) string {
return fmt.Sprintf("Coord %d/%d/%d", pos.X, pos.Y, pos.Z)
}
func NewMapBlockAccessor(accessor db.DBAccessor) *MapBlockAccessor {
c := cache.New(500*time.Millisecond, 1000*time.Millisecond)
func NewMapBlockAccessor(accessor db.DBAccessor, expiretime, purgetime time.Duration) *MapBlockAccessor {
c := cache.New(expiretime, purgetime)
return &MapBlockAccessor{
accessor: accessor,

View File

@ -1,13 +1,15 @@
package mapblockaccessor
import (
"github.com/sirupsen/logrus"
"io/ioutil"
"mapserver/coords"
"mapserver/db/sqlite"
"mapserver/testutils"
"os"
"testing"
"time"
"github.com/sirupsen/logrus"
)
func TestSimpleAccess(t *testing.T) {
@ -30,7 +32,7 @@ func TestSimpleAccess(t *testing.T) {
panic(err)
}
cache := NewMapBlockAccessor(a)
cache := NewMapBlockAccessor(a, 500*time.Millisecond, 1000*time.Millisecond)
mb, err := cache.GetMapBlock(coords.NewMapBlockCoords(0, 0, 0))
if err != nil {