mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 18:41:59 -07:00
Tweak the database block cache size, and add config for it
This commit is contained in:
parent
179c9ee8cc
commit
c2f2d8771f
@ -715,22 +715,21 @@ func syncthingMain() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dbOpts() *opt.Options {
|
func dbOpts() *opt.Options {
|
||||||
// Calculate a sutiable database block cache capacity. We start at the
|
// Calculate a sutiable database block cache capacity. Default is 8 MiB.
|
||||||
// default of 8 MiB and use larger values for machines with more memory.
|
|
||||||
// In reality, the database will use twice the amount we calculate here,
|
// In reality, the database will use twice the amount we calculate here,
|
||||||
// as it also has two write buffers each sized at half the block cache.
|
// as it also has two write buffers each sized at half the block cache.
|
||||||
|
|
||||||
blockCacheCapacity := 8 << 20
|
blockCacheCapacity := 8 << 20
|
||||||
if bytes, err := memorySize(); err == nil {
|
|
||||||
if bytes > 74<<30 {
|
if v := cfg.Options().DatabaseBlockCacheMiB; v != 0 {
|
||||||
// At 74 GiB of RAM, we hit a 256 MiB block cache (per the
|
// Use the value from the config, if it's set.
|
||||||
// calculations below). There's probably no point in growing the
|
blockCacheCapacity = v << 20
|
||||||
// cache beyond this point.
|
} else if bytes, err := memorySize(); err == nil {
|
||||||
blockCacheCapacity = 256 << 20
|
// We start at the default of 8 MiB and use larger values for machines
|
||||||
} else if bytes > 8<<30 {
|
// with more memory.
|
||||||
// Slowly grow from 128 MiB at 8 GiB of RAM up to 256 MiB for a
|
|
||||||
// ~74 GiB RAM machine
|
if bytes > 8<<30 {
|
||||||
blockCacheCapacity = int(bytes/512) + 128 - 16
|
// Cap the cache at 128 MB when we reach 8 GiB of RAM
|
||||||
|
blockCacheCapacity = 128 << 20
|
||||||
} else if bytes > 512<<20 {
|
} else if bytes > 512<<20 {
|
||||||
// Grow from 8 MiB at start to 128 MiB of cache at 8 GiB of RAM.
|
// Grow from 8 MiB at start to 128 MiB of cache at 8 GiB of RAM.
|
||||||
blockCacheCapacity = int(bytes / 64)
|
blockCacheCapacity = int(bytes / 64)
|
||||||
|
@ -240,6 +240,7 @@ type OptionsConfiguration struct {
|
|||||||
ProgressUpdateIntervalS int `xml:"progressUpdateIntervalS" json:"progressUpdateIntervalS" default:"5"`
|
ProgressUpdateIntervalS int `xml:"progressUpdateIntervalS" json:"progressUpdateIntervalS" default:"5"`
|
||||||
SymlinksEnabled bool `xml:"symlinksEnabled" json:"symlinksEnabled" default:"true"`
|
SymlinksEnabled bool `xml:"symlinksEnabled" json:"symlinksEnabled" default:"true"`
|
||||||
LimitBandwidthInLan bool `xml:"limitBandwidthInLan" json:"limitBandwidthInLan" default:"false"`
|
LimitBandwidthInLan bool `xml:"limitBandwidthInLan" json:"limitBandwidthInLan" default:"false"`
|
||||||
|
DatabaseBlockCacheMiB int `xml:"databaseBlockCacheMiB" json:"databaseBlockCacheMiB" default:"0"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (orig OptionsConfiguration) Copy() OptionsConfiguration {
|
func (orig OptionsConfiguration) Copy() OptionsConfiguration {
|
||||||
|
@ -52,6 +52,7 @@ func TestDefaultValues(t *testing.T) {
|
|||||||
ProgressUpdateIntervalS: 5,
|
ProgressUpdateIntervalS: 5,
|
||||||
SymlinksEnabled: true,
|
SymlinksEnabled: true,
|
||||||
LimitBandwidthInLan: false,
|
LimitBandwidthInLan: false,
|
||||||
|
DatabaseBlockCacheMiB: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := New(device1)
|
cfg := New(device1)
|
||||||
@ -158,6 +159,7 @@ func TestOverriddenValues(t *testing.T) {
|
|||||||
ProgressUpdateIntervalS: 10,
|
ProgressUpdateIntervalS: 10,
|
||||||
SymlinksEnabled: false,
|
SymlinksEnabled: false,
|
||||||
LimitBandwidthInLan: true,
|
LimitBandwidthInLan: true,
|
||||||
|
DatabaseBlockCacheMiB: 42,
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := Load("testdata/overridenvalues.xml", device1)
|
cfg, err := Load("testdata/overridenvalues.xml", device1)
|
||||||
|
1
internal/config/testdata/overridenvalues.xml
vendored
1
internal/config/testdata/overridenvalues.xml
vendored
@ -23,5 +23,6 @@
|
|||||||
<progressUpdateIntervalS>10</progressUpdateIntervalS>
|
<progressUpdateIntervalS>10</progressUpdateIntervalS>
|
||||||
<symlinksEnabled>false</symlinksEnabled>
|
<symlinksEnabled>false</symlinksEnabled>
|
||||||
<limitBandwidthInLan>true</limitBandwidthInLan>
|
<limitBandwidthInLan>true</limitBandwidthInLan>
|
||||||
|
<databaseBlockCacheMiB>42</databaseBlockCacheMiB>
|
||||||
</options>
|
</options>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
Loading…
Reference in New Issue
Block a user