Skip to content

Commit 582014e

Browse files
author
Abtahi
committed
xdrive: make segment growth factor configurable
1 parent 41a1e4f commit 582014e

5 files changed

Lines changed: 66 additions & 44 deletions

File tree

‎infra/conf/transport_method.go‎

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -967,18 +967,19 @@ func readFileOrString(f string, s []string) ([]byte, error) {
967967
}
968968

969969
type XDriveConfig struct {
970-
RemoteFolder string `json:"remoteFolder"`
971-
Service string `json:"service"`
972-
Secrets []string `json:"secrets"`
973-
SegmentBytes uint32 `json:"segmentBytes"`
974-
FlushIntervalMs uint32 `json:"flushIntervalMs"`
975-
PollIntervalMs uint32 `json:"pollIntervalMs"`
976-
MaxPollIntervalMs uint32 `json:"maxPollIntervalMs"`
977-
SessionTTLSeconds uint32 `json:"sessionTtlSeconds"`
978-
Concurrency uint32 `json:"concurrency"`
979-
EagerWindowMs uint32 `json:"eagerWindowMs"`
980-
HoleTimeoutMs uint32 `json:"holeTimeoutMs"`
981-
Template json.RawMessage `json:"template"`
970+
RemoteFolder string `json:"remoteFolder"`
971+
Service string `json:"service"`
972+
Secrets []string `json:"secrets"`
973+
SegmentBytes uint32 `json:"segmentBytes"`
974+
FlushIntervalMs uint32 `json:"flushIntervalMs"`
975+
PollIntervalMs uint32 `json:"pollIntervalMs"`
976+
MaxPollIntervalMs uint32 `json:"maxPollIntervalMs"`
977+
SessionTTLSeconds uint32 `json:"sessionTtlSeconds"`
978+
Concurrency uint32 `json:"concurrency"`
979+
EagerWindowMs uint32 `json:"eagerWindowMs"`
980+
HoleTimeoutMs uint32 `json:"holeTimeoutMs"`
981+
SegmentGrowthFactor float64 `json:"segmentGrowthFactor"`
982+
Template json.RawMessage `json:"template"`
982983
}
983984

984985
// Build implements Buildable.
@@ -997,18 +998,19 @@ func (c *XDriveConfig) Build() (proto.Message, error) {
997998
return nil, errors.New("unsupported service")
998999
}
9991000
config := &xdrive.Config{
1000-
RemoteFolder: c.RemoteFolder,
1001-
Service: c.Service,
1002-
Secrets: c.Secrets,
1003-
SegmentBytes: c.SegmentBytes,
1004-
FlushIntervalMs: c.FlushIntervalMs,
1005-
PollIntervalMs: c.PollIntervalMs,
1006-
MaxPollIntervalMs: c.MaxPollIntervalMs,
1007-
SessionTtlSeconds: c.SessionTTLSeconds,
1008-
Concurrency: c.Concurrency,
1009-
EagerWindowMs: c.EagerWindowMs,
1010-
HoleTimeoutMs: c.HoleTimeoutMs,
1011-
Template: string(c.Template),
1001+
RemoteFolder: c.RemoteFolder,
1002+
Service: c.Service,
1003+
Secrets: c.Secrets,
1004+
SegmentBytes: c.SegmentBytes,
1005+
FlushIntervalMs: c.FlushIntervalMs,
1006+
PollIntervalMs: c.PollIntervalMs,
1007+
MaxPollIntervalMs: c.MaxPollIntervalMs,
1008+
SessionTtlSeconds: c.SessionTTLSeconds,
1009+
Concurrency: c.Concurrency,
1010+
EagerWindowMs: c.EagerWindowMs,
1011+
HoleTimeoutMs: c.HoleTimeoutMs,
1012+
SegmentGrowthFactor: c.SegmentGrowthFactor,
1013+
Template: string(c.Template),
10121014
}
10131015
return config, nil
10141016
}

‎transport/internet/xdrive/config.pb.go‎

Lines changed: 25 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎transport/internet/xdrive/config.proto‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ message Config {
1616
uint32 eager_window_ms = 10;
1717
uint32 hole_timeout_ms = 11;
1818
string template = 12;
19+
double segment_growth_factor = 13;
1920
}

‎transport/internet/xdrive/params.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type params struct {
2525
holeTimeout time.Duration
2626
sessionTTL time.Duration
2727
concurrency int
28+
growth float64
2829
}
2930

3031
func millis(value uint32, fallback time.Duration) time.Duration {
@@ -51,6 +52,13 @@ func capped(value uint32, fallback, limit int) int {
5152
return int(value)
5253
}
5354

55+
func growthOrDefault(value float64) float64 {
56+
if value <= 0 {
57+
return 2
58+
}
59+
return value
60+
}
61+
5462
func paramsFromConfig(c *Config) params {
5563
p := params{
5664
segmentBytes: capped(c.SegmentBytes, defaultSegmentBytes, maxSegmentBytes),
@@ -61,6 +69,7 @@ func paramsFromConfig(c *Config) params {
6169
holeTimeout: millis(c.HoleTimeoutMs, defaultHoleTimeout),
6270
sessionTTL: seconds(c.SessionTtlSeconds, defaultSessionTTL),
6371
concurrency: capped(c.Concurrency, defaultConcurrency, maxConcurrency),
72+
growth: growthOrDefault(c.SegmentGrowthFactor),
6473
}
6574
if p.maxPollInterval < p.minPollInterval {
6675
p.maxPollInterval = p.minPollInterval

‎transport/internet/xdrive/wal.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,11 @@ func (w *walWriter) flushLocked() error {
155155

156156
if w.segBytes < 4*1024*1024 {
157157
if d, ok := w.storage.(interface{ deleteAvg() time.Duration }); ok && d.deleteAvg() < 2*time.Second {
158-
w.segBytes *= 2
159-
if w.segBytes > 4*1024*1024 {
160-
w.segBytes = 4 * 1024 * 1024
158+
if n := int(float64(w.segBytes) * w.growth); n > w.segBytes {
159+
w.segBytes = n
160+
if w.segBytes > 4*1024*1024 {
161+
w.segBytes = 4 * 1024 * 1024
162+
}
161163
}
162164
}
163165
}

0 commit comments

Comments
 (0)