fix #287. make the lru cache size configurable
parent
1565e554b2
commit
1c9e14f68f
|
@ -74,6 +74,11 @@ query-shard-buffer-size = 1000
|
|||
# the process
|
||||
max-open-files = 40
|
||||
|
||||
# LRU cache size, LRU is used by leveldb to store contents of the
|
||||
# uncompressed sstables. You can use `m` or `g` prefix for megabytes
|
||||
# and gigabytes, respectively.
|
||||
lru-cache-size = "200m"
|
||||
|
||||
# These options specify how data is sharded across the cluster. There are two
|
||||
# shard configurations that have the same knobs: short term and long term.
|
||||
# Any series that begins with a capital letter like Exceptions will be written
|
||||
|
|
|
@ -70,6 +70,7 @@ query-shard-buffer-size = 1000
|
|||
# Maximum mmap open files, this will affect the virtual memory used by
|
||||
# the process
|
||||
# max-open-files = 40
|
||||
# lru-cache-size = "200m"
|
||||
|
||||
# These options specify how data is sharded across the cluster. There are two
|
||||
# shard configurations that have the same knobs: short term and long term.
|
||||
|
|
|
@ -9,9 +9,38 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type size struct {
|
||||
int
|
||||
}
|
||||
|
||||
const (
|
||||
ONE_MEGABYTE = 1024 * 1024
|
||||
ONE_GIGABYTE = 1024 * ONE_MEGABYTE
|
||||
)
|
||||
|
||||
func (d *size) UnmarshalText(text []byte) error {
|
||||
str := string(text)
|
||||
length := len(str)
|
||||
size, err := strconv.ParseInt(string(text[:length-1]), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch suffix := text[len(text)-1]; suffix {
|
||||
case 'm':
|
||||
size *= ONE_MEGABYTE
|
||||
case 'g':
|
||||
size *= ONE_GIGABYTE
|
||||
default:
|
||||
return fmt.Errorf("Unknown size suffix %s", suffix)
|
||||
}
|
||||
d.int = int(size)
|
||||
return nil
|
||||
}
|
||||
|
||||
type duration struct {
|
||||
time.Duration
|
||||
}
|
||||
|
@ -59,6 +88,7 @@ type LoggingConfig struct {
|
|||
|
||||
type LevelDbConfiguration struct {
|
||||
MaxOpenFiles int `toml:"max-open-files"`
|
||||
LruCacheSize int `toml:"lru-cache-size"`
|
||||
}
|
||||
|
||||
type ShardingDefinition struct {
|
||||
|
@ -154,6 +184,7 @@ type Configuration struct {
|
|||
LogLevel string
|
||||
BindAddress string
|
||||
LevelDbMaxOpenFiles int
|
||||
LevelDbLruCacheSize int
|
||||
ShortTermShard *ShardConfiguration
|
||||
LongTermShard *ShardConfiguration
|
||||
ReplicationFactor int
|
||||
|
@ -226,6 +257,7 @@ func parseTomlConfiguration(filename string) (*Configuration, error) {
|
|||
Hostname: tomlConfiguration.Hostname,
|
||||
BindAddress: tomlConfiguration.BindAddress,
|
||||
LevelDbMaxOpenFiles: tomlConfiguration.LevelDb.MaxOpenFiles,
|
||||
LevelDbLruCacheSize: tomlConfiguration.LevelDb.LruCacheSize,
|
||||
LongTermShard: &tomlConfiguration.Sharding.LongTerm,
|
||||
ShortTermShard: &tomlConfiguration.Sharding.ShortTerm,
|
||||
ReplicationFactor: tomlConfiguration.Sharding.ReplicationFactor,
|
||||
|
@ -251,6 +283,11 @@ func parseTomlConfiguration(filename string) (*Configuration, error) {
|
|||
config.LevelDbMaxOpenFiles = 100
|
||||
}
|
||||
|
||||
// if it wasn't set, set it to 100
|
||||
if config.LevelDbLruCacheSize == 0 {
|
||||
config.LevelDbLruCacheSize = 200 * ONE_MEGABYTE
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -50,3 +50,11 @@ func (self *LoadConfigurationSuite) TestConfig(c *C) {
|
|||
c.Assert(config.WalIndexAfterRequests, Equals, 1000)
|
||||
c.Assert(config.WalRequestsPerLogFile, Equals, 10000)
|
||||
}
|
||||
|
||||
func (self *LoadConfigurationSuite) TestSizeParsing(c *C) {
|
||||
var s size
|
||||
c.Assert(s.UnmarshalText([]byte("200m")), IsNil)
|
||||
c.Assert(s.int, Equals, 200*ONE_MEGABYTE)
|
||||
c.Assert(s.UnmarshalText([]byte("10g")), IsNil)
|
||||
c.Assert(s.int, Equals, 10*ONE_GIGABYTE)
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ func NewLevelDbShardDatastore(config *configuration.Configuration) (*LevelDbShar
|
|||
return nil, err
|
||||
}
|
||||
opts := levigo.NewOptions()
|
||||
opts.SetCache(levigo.NewLRUCache(ONE_MEGABYTE))
|
||||
opts.SetCache(levigo.NewLRUCache(config.LevelDbLruCacheSize))
|
||||
opts.SetCreateIfMissing(true)
|
||||
opts.SetBlockSize(64 * ONE_KILOBYTE)
|
||||
filter := levigo.NewBloomFilter(SHARD_BLOOM_FILTER_BITS_PER_KEY)
|
||||
|
|
Loading…
Reference in New Issue