Skip to content

Commit 53346dd

Browse files
ChengyuZhu6sondavidb
authored andcommitted
Add PrefetchConfig section
Add PrefetchConfig with enable flag and max_concurrency. Fixes: awslabs#1832 Signed-off-by: ChengyuZhu6 <hudson@cyzhu.com>
1 parent bf86675 commit 53346dd

File tree

9 files changed

+67
-22
lines changed

9 files changed

+67
-22
lines changed

config/config.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ max_concurrency = 100
77
no_prometheus = false
88
mount_timeout_sec = 30
99
fuse_metrics_emit_wait_duration_sec = 60
10-
prefetch_max_concurrency = 0
1110
metrics_address = ''
1211
metrics_network = 'tcp'
1312
debug_address = ''
@@ -55,6 +54,10 @@ skip_check_snapshotter_supported = false
5554
type = 'soci'
5655
containerd_address = '/run/containerd/containerd.sock'
5756

57+
[prefetch]
58+
enable = false
59+
max_concurrency = 0
60+
5861
[pull_modes]
5962
[pull_modes.soci_v1]
6063
enable = false

config/config_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,15 @@ func TestConfigDefaults(t *testing.T) {
7676
expected: int64(defaultMaxConcurrency),
7777
actual: cfg.MaxConcurrency,
7878
},
79+
{
80+
name: "prefetch enabled",
81+
expected: defaultPrefetchEnable,
82+
actual: cfg.PrefetchConfig.Enable,
83+
},
7984
{
8085
name: "prefetch max concurrency",
8186
expected: int64(defaultPrefetchMaxConcurrency),
82-
actual: cfg.PrefetchMaxConcurrency,
87+
actual: cfg.PrefetchConfig.MaxConcurrency,
8388
},
8489
{
8590
name: "fuse attr timeout",

config/defaults.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ const (
8383
// defaultMaxConcurrency is the maximum number of layers allowed to be pulled at once
8484
defaultMaxConcurrency = 100
8585

86+
// defaultPrefetchEnable is the default value for whether prefetch is enabled.
87+
defaultPrefetchEnable = false
88+
8689
// defaultPrefetchMaxConcurrency limits the maximum number of layers that can perform
8790
// prefetch operations concurrently at the snapshotter level.
8891
// 0 means no limit

config/fs.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ type FSConfig struct {
5454
NoPrometheus bool `toml:"no_prometheus"`
5555
MountTimeoutSec int64 `toml:"mount_timeout_sec"`
5656
FuseMetricsEmitWaitDurationSec int64 `toml:"fuse_metrics_emit_wait_duration_sec"`
57-
PrefetchMaxConcurrency int64 `toml:"prefetch_max_concurrency"`
5857

5958
RetryableHTTPClientConfig `toml:"http"`
6059
BlobConfig `toml:"blob"`
@@ -66,6 +65,20 @@ type FSConfig struct {
6665
BackgroundFetchConfig `toml:"background_fetch"`
6766

6867
ContentStoreConfig `toml:"content_store"`
68+
69+
PrefetchConfig `toml:"prefetch"`
70+
}
71+
72+
// PrefetchConfig configures the prefetch feature for downloading specified files
73+
// before marking a layer download as complete.
74+
type PrefetchConfig struct {
75+
// Enable controls whether the prefetch feature is enabled.
76+
Enable bool `toml:"enable"`
77+
78+
// MaxConcurrency limits the maximum number of layers that can perform
79+
// prefetch operations concurrently at the snapshotter level.
80+
// 0 means no limit.
81+
MaxConcurrency int64 `toml:"max_concurrency"`
6982
}
7083

7184
// BlobConfig is config for layer blob management.
@@ -200,9 +213,9 @@ func parseFSConfig(cfg *Config) error {
200213
if cfg.MaxConcurrency < 0 {
201214
cfg.MaxConcurrency = 0
202215
}
203-
// If PrefetchMaxConcurrency is not set or negative, disable concurrency limits entirely.
204-
if cfg.PrefetchMaxConcurrency < 0 {
205-
cfg.PrefetchMaxConcurrency = defaultPrefetchMaxConcurrency
216+
// If PrefetchConfig.MaxConcurrency is negative, disable concurrency limits entirely.
217+
if cfg.PrefetchConfig.MaxConcurrency < 0 {
218+
cfg.PrefetchConfig.MaxConcurrency = defaultPrefetchMaxConcurrency
206219
}
207220

208221
// Parse nested fs configs

docs/config.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ This set of variables must be at the top of your TOML file due to not belonging
2323
- `resolve_result_entry` (int) — Max amount of entries allowed in the cache. Default: 30.
2424
- `debug` (bool) — Enables debugging for go-fuse in logs. This often emits sensitive data, so this should be false in production. Default: false.
2525
- `disable_verification` (bool) — Allows skipping TOC validation, which can give slight performance improvements if files have already been verified elsewhere. Default: false.
26-
- `prefetch_max_concurrency` (int) — Maximum number of layers that can perform prefetch operations concurrently at the snapshotter level. `0` means no limit. Default: 0.
2726
- `no_prometheus` (bool) — Toggle prometheus metrics. Default: false.
2827
- `mount_timeout_sec` (int) — Timeout for mount if a layer can't be resolved. Default: 30.
2928
- `fuse_metrics_emit_wait_duration_sec` (int) — The wait time before the snaphotter emits FUSE operation counts for an image. Default: 60.
@@ -82,6 +81,10 @@ This set of variables must be at the top of your TOML file due to not belonging
8281
- `type` (string) — Sets content store (e.g. "soci", "containerd"). Default: "soci".
8382
- `namespace` (string) — Default: "default".
8483

84+
### [prefetch]
85+
- `enable` (bool) — Enables the prefetch feature for downloading specified files before marking a layer download as complete. Default: false.
86+
- `max_concurrency` (int) — Maximum number of layers that can perform prefetch operations concurrently at the snapshotter level. `0` means no limit. Default: 0.
87+
8588
## config/resolver.go
8689

8790
### [resolver]

docs/prefetch.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,31 +198,38 @@ Total spans to prefetch: 12
198198

199199
## Configuration
200200

201-
### Concurrency Control
201+
### Enabling Prefetch
202202

203-
The snapshotter implements bounded concurrency for prefetch operations to prevent overwhelming the system when multiple containers start simultaneously.
204-
205-
#### Snapshotter Configuration
206-
207-
Prefetch concurrency is controlled via the snapshotter configuration file (typically `/etc/soci-snapshotter-grpc/config.toml`):
203+
Prefetch must be explicitly enabled in the snapshotter configuration file:
208204

209205
```toml
206+
[prefetch]
207+
# Enable the prefetch feature
208+
enable = true
209+
210210
# Maximum number of layers that can perform prefetch operations concurrently
211211
# at the snapshotter level
212212
# 0 = no limit (default)
213213
# Positive value = maximum concurrent prefetch operations
214-
prefetch_max_concurrency = 0
214+
max_concurrency = 0
215215
```
216216

217-
**Configuration options:**
218-
- `0` (default): No limit on concurrent prefetch operations
219-
- Positive integer (e.g., `10`): Maximum number of layers that can prefetch simultaneously
217+
### Configuration Options
220218

221-
#### Example Configuration
219+
- `enable` (default: `false`): Controls whether the prefetch feature is enabled. When disabled, prefetch artifacts are ignored even if present.
220+
- `max_concurrency` (default: `0`): Limits concurrent prefetch operations across all layers.
221+
- `0`: No limit on concurrent prefetch operations
222+
- Positive integer (e.g., `10`): Maximum number of layers that can prefetch simultaneously
223+
224+
### Example Configuration
222225

223226
```toml
224227
# /etc/soci-snapshotter-grpc/config.toml
225228

229+
[prefetch]
230+
# Enable prefetch feature
231+
enable = true
232+
226233
# Limit to 10 concurrent prefetch operations
227-
prefetch_max_concurrency = 10
234+
max_concurrency = 10
228235
```

fs/layer/layer.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ func NewResolver(root string, cfg config.FSConfig, resolveHandlers map[string]re
173173
}
174174

175175
var prefetchSem *semaphore.Weighted
176-
if cfg.PrefetchMaxConcurrency > 0 {
177-
prefetchSem = semaphore.NewWeighted(cfg.PrefetchMaxConcurrency)
176+
if cfg.PrefetchConfig.Enable && cfg.PrefetchConfig.MaxConcurrency > 0 {
177+
prefetchSem = semaphore.NewWeighted(cfg.PrefetchConfig.MaxConcurrency)
178178
}
179179

180180
return &Resolver{
@@ -554,6 +554,11 @@ func (r *Resolver) executePrefetch(ctx context.Context, spanManager *spanmanager
554554
return nil
555555
}
556556

557+
if !r.config.PrefetchConfig.Enable {
558+
log.G(ctx).Debug("Prefetch is disabled in config, skipping prefetch")
559+
return nil
560+
}
561+
557562
prefetchArtifact, err := r.loadPrefetchArtifact(ctx, prefetchDesc)
558563
if err != nil {
559564
if errors.Is(err, soci.ErrEmptyPrefetchArtifact) {

integration/create_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ func TestSociCreateWithPrefetchArtifacts(t *testing.T) {
357357

358358
sh.X("soci", "push", "--user", regConfig.creds(), mirrorImg.ref)
359359

360-
logMonitor := rebootContainerd(t, sh, getContainerdConfigToml(t, false), getSnapshotterConfigToml(t))
360+
logMonitor := rebootContainerd(t, sh, getContainerdConfigToml(t, false), getSnapshotterConfigToml(t, withPrefetch()))
361361

362362
const prefetchMonitorKey = "prefetch-artifact-monitor"
363363
prefetchLogCh := make(chan struct{}, 1)

integration/util_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,12 @@ func withFuseWaitDuration(i int64) snapshotterConfigOpt {
347347
}
348348
}
349349

350+
func withPrefetch() snapshotterConfigOpt {
351+
return func(c *config.Config) {
352+
c.ServiceConfig.FSConfig.PrefetchConfig.Enable = true
353+
}
354+
}
355+
350356
func withPullModes(pullModes config.PullModes) snapshotterConfigOpt {
351357
return func(c *config.Config) {
352358
c.ServiceConfig.PullModes = pullModes

0 commit comments

Comments
 (0)