-
Notifications
You must be signed in to change notification settings - Fork 460
perf(sandbox): reduce memory dirtying from journald and envd logging #2423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| package pkg | ||
|
|
||
| const Version = "0.5.14" | ||
| const Version = "0.5.15" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #!/bin/bash | ||
| # Measure memory/rootfs diff sizes across pause-resume cycles. | ||
| # | ||
| # This script builds a base template, then runs a series of pause-resume | ||
| # cycles to measure how many pages get dirtied during each cycle — | ||
| # both idle and under normal envd operations (file writes, process starts). | ||
| # | ||
| # Usage: | ||
| # sudo ./measure-memory-dirtying.sh [storage-path] | ||
| # | ||
| # Requires: root, KVM, Docker, NBD, hugepages | ||
| set -euo pipefail | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The paths |
||
| STORAGE="${1:-.local-build}" | ||
| CREATE_BUILD="go run ./packages/orchestrator/cmd/create-build" | ||
| RESUME_BUILD="go run ./packages/orchestrator/cmd/resume-build" | ||
|
Check warning on line 16 in packages/orchestrator/cmd/resume-build/measure-memory-dirtying.sh
|
||
|
Comment on lines
+15
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The script’s documented usage ( Useful? React with 👍 / 👎.
Comment on lines
+14
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 The Extended reasoning...The script at packages/orchestrator/cmd/resume-build/measure-memory-dirtying.sh defines: CREATE_BUILD="go run ./packages/orchestrator/cmd/create-build"
RESUME_BUILD="go run ./packages/orchestrator/cmd/resume-build"These paths are relative to the current working directory at the time the script is invoked — not relative to the script file itself. The Usage comment says: The Step-by-step proof of failure:
The The script only works correctly when invoked from the repo root (e.g. The fix is either: (a) update the Usage comment to require repo-root invocation, or (b) add This is a developer-facing benchmark script, not production code, so the severity is nit — it will cause an immediately obvious failure rather than silent data corruption. |
||
|
|
||
| BASE_ID="measure-base-$(date +%s)" | ||
| echo "=== Step 1: Build base template ===" | ||
| $CREATE_BUILD \ | ||
| -to-build "$BASE_ID" \ | ||
| -storage "$STORAGE" \ | ||
| -hugepages \ | ||
| -v | ||
|
|
||
| echo "" | ||
| echo "=== Step 2: Immediate pause (baseline — no activity) ===" | ||
| LAYER_IDLE="$BASE_ID-idle" | ||
| $RESUME_BUILD \ | ||
| -from-build "$BASE_ID" \ | ||
| -to-build "$LAYER_IDLE" \ | ||
| -storage "$STORAGE" \ | ||
| -pause | ||
|
|
||
| echo "" | ||
| echo "=== Step 3: Resume + sleep 2s + pause (idle drift) ===" | ||
| LAYER_SLEEP="$LAYER_IDLE-sleep2" | ||
| $RESUME_BUILD \ | ||
| -from-build "$LAYER_IDLE" \ | ||
| -to-build "$LAYER_SLEEP" \ | ||
| -storage "$STORAGE" \ | ||
| -cmd-pause "sleep 2" | ||
|
|
||
| echo "" | ||
| echo "=== Step 4: Resume + sleep 5s + pause (longer idle drift) ===" | ||
| LAYER_SLEEP5="$LAYER_SLEEP-sleep5" | ||
| $RESUME_BUILD \ | ||
| -from-build "$LAYER_SLEEP" \ | ||
| -to-build "$LAYER_SLEEP5" \ | ||
| -storage "$STORAGE" \ | ||
| -cmd-pause "sleep 5" | ||
|
|
||
| echo "" | ||
| echo "=== Step 5: Resume + write files via envd + pause ===" | ||
| LAYER_WRITE="$LAYER_SLEEP5-write" | ||
| $RESUME_BUILD \ | ||
| -from-build "$LAYER_SLEEP5" \ | ||
| -to-build "$LAYER_WRITE" \ | ||
| -storage "$STORAGE" \ | ||
| -cmd-pause "dd if=/dev/urandom of=/tmp/testfile bs=1K count=64 2>/dev/null && echo written" | ||
|
|
||
| echo "" | ||
| echo "=== Step 6: Resume + start process via envd + pause ===" | ||
| LAYER_PROC="$LAYER_WRITE-proc" | ||
| $RESUME_BUILD \ | ||
| -from-build "$LAYER_WRITE" \ | ||
| -to-build "$LAYER_PROC" \ | ||
| -storage "$STORAGE" \ | ||
| -cmd-pause "python3 -c 'print(sum(range(10000)))' || echo 'python not available, using echo'; echo done" | ||
|
|
||
| echo "" | ||
| echo "=== Step 7: Multi-iteration pause benchmark (10x immediate pause) ===" | ||
| $RESUME_BUILD \ | ||
| -from-build "$LAYER_IDLE" \ | ||
| -storage "$STORAGE" \ | ||
| -pause \ | ||
| -iterations 10 | ||
|
|
||
| echo "" | ||
| echo "=== Done ===" | ||
| echo "Compare the '📦 Artifacts' memfile/rootfs diff sizes above." | ||
| echo "Smaller diffs = fewer dirty pages = faster snapshot restore." | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| {{- /*gotype:github.com/e2b-dev/infra/packages/orchestrator/pkg/template/build/core/rootfs.templateModel*/ -}} | ||
| {{ .WriteFile "etc/systemd/journald.conf.d/e2b.conf" 0o644 }} | ||
|
|
||
| [Journal] | ||
| Storage=none | ||
| MaxLevelConsole=warning | ||
| MaxLevelKMsg=warning | ||
| MaxLevelWall=emerg | ||
| ForwardToSyslog=no |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,7 +88,7 @@ | |
|
|
||
| keysIter := maps.Keys(actualFiles) | ||
| keys := slices.Collect(keysIter) | ||
| assert.Len(t, keys, 13) | ||
| assert.Len(t, keys, 14) | ||
| assert.Equal(t, "e2b.local", actualFiles["etc/hostname"]) | ||
| assert.Equal(t, "nameserver 8.8.8.8", actualFiles["etc/resolv.conf"]) | ||
|
|
||
|
|
@@ -100,6 +100,10 @@ | |
| [Service] | ||
| WatchdogSec=0`) | ||
| assert.Equal(t, disabledContent, actualFiles["etc/systemd/system/systemd-journald.service.d/override.conf"]) | ||
| assert.Equal(t, disabledContent, actualFiles["etc/systemd/system/systemd-networkd.service.d/override.conf"]) | ||
|
|
||
| journaldConf := strings.TrimSpace(actualFiles["etc/systemd/journald.conf.d/e2b.conf"]) | ||
| assert.Contains(t, journaldConf, "Storage=none") | ||
| assert.Contains(t, journaldConf, "MaxLevelConsole=warning") | ||
| }) | ||
|
Check warning on line 108 in packages/orchestrator/pkg/template/build/core/rootfs/rootfs_test.go
|
||
|
Comment on lines
103
to
108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 The journald conf test only checks Extended reasoning...The new test assertions cover only two of the five settings produced by The The current template (journald.conf.tpl) does correctly include Step-by-step proof of the regression scenario:
The fix is straightforward: either add |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var level zerolog.Levelinitializes to 0, which equalszerolog.DebugLevel. The unconditionallevel = zerolog.DebugLeveloutside the if-else is dead code — it reassigns the same zero value. If the intent is per-branch level selection in the future, the assignment belongs inside each branch; as written it just adds noise.