imposm3/cache/config.go

101 lines
2.1 KiB
Go
Raw Normal View History

2013-06-18 18:04:20 +04:00
package cache
import (
"encoding/json"
"io/ioutil"
"log"
"os"
)
2013-07-04 19:27:22 +04:00
type cacheOptions struct {
2013-06-18 18:04:20 +04:00
CacheSizeM int
MaxOpenFiles int
BlockRestartInterval int
WriteBufferSizeM int
BlockSizeK int
}
2013-07-04 19:27:22 +04:00
type coordsCacheOptions struct {
cacheOptions
BunchSize int
BunchCacheCapacity int
2013-06-18 18:04:20 +04:00
}
2013-07-04 19:27:22 +04:00
type osmCacheOptions struct {
Coords coordsCacheOptions
Ways cacheOptions
Nodes cacheOptions
Relations cacheOptions
CoordsIndex cacheOptions
WaysIndex cacheOptions
2013-06-18 18:04:20 +04:00
}
const defaultConfig = `
{
"Coords": {
"CacheSizeM": 16,
"WriteBufferSizeM": 64,
"BlockSizeK": 0,
"MaxOpenFiles": 64,
"BlockRestartInterval": 256,
"BunchSize": 32,
"BunchCacheCapacity": 8096
2013-06-18 18:04:20 +04:00
},
"Nodes": {
"CacheSizeM": 16,
"WriteBufferSizeM": 64,
"BlockSizeK": 0,
"MaxOpenFiles": 64,
"BlockRestartInterval": 128
},
"Ways": {
"CacheSizeM": 16,
"WriteBufferSizeM": 64,
"BlockSizeK": 0,
"MaxOpenFiles": 64,
"BlockRestartInterval": 128
},
"Relations": {
"CacheSizeM": 16,
"WriteBufferSizeM": 64,
"BlockSizeK": 0,
"MaxOpenFiles": 64,
"BlockRestartInterval": 128
},
"CoordsIndex": {
"CacheSizeM": 32,
"WriteBufferSizeM": 128,
"BlockSizeK": 0,
"MaxOpenFiles": 256,
"BlockRestartInterval": 256
},
"WaysIndex": {
"CacheSizeM": 16,
"WriteBufferSizeM": 64,
"BlockSizeK": 0,
"MaxOpenFiles": 64,
"BlockRestartInterval": 128
}
}
`
2013-07-04 19:27:22 +04:00
var globalCacheOptions osmCacheOptions
2013-06-18 18:04:20 +04:00
func init() {
2013-07-04 19:27:22 +04:00
err := json.Unmarshal([]byte(defaultConfig), &globalCacheOptions)
2013-06-18 18:04:20 +04:00
if err != nil {
panic(err)
}
2013-09-02 15:09:26 +04:00
cacheConfFile := os.Getenv("IMPOSM_CACHE_CONFIG")
2013-06-18 18:04:20 +04:00
if cacheConfFile != "" {
data, err := ioutil.ReadFile(cacheConfFile)
if err != nil {
log.Println("Unable to read cache config:", err)
}
2013-07-04 19:27:22 +04:00
err = json.Unmarshal(data, &globalCacheOptions)
2013-06-18 18:04:20 +04:00
if err != nil {
log.Println("Unable to parse cache config:", err)
}
}
}