Skip to content

Commit b00519e

Browse files
committed
perf: optimize postgres on macOS/Windows for CI, remove ramdisk
Previously we used ramdisk for embedded postgres on macOS and Windows to improve test performance. This wastes memory since data ends up cached twice: once in the ramdisk and again in postgres's own buffers. Instead, we give postgres more memory and tune it more aggressively: - Increase shared_buffers to 2GB, effective_cache_size to 4GB - Minimal WAL level, infrequent checkpoints - Disable autovacuum, JIT, logging, stats tracking - OS-specific I/O settings This gives postgres more memory to work with while simplifying CI setup.
1 parent 8ead6f7 commit b00519e

File tree

2 files changed

+63
-28
lines changed

2 files changed

+63
-28
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,6 @@ jobs:
363363
sudo mdutil -X /
364364
sudo launchctl bootout system /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
365365
366-
# Set up RAM disks to speed up the rest of the job. This action is in
367-
# a separate repository to allow its use before actions/checkout.
368-
- name: Setup RAM Disks
369-
if: runner.os == 'Windows'
370-
uses: coder/setup-ramdisk-action@e1100847ab2d7bcd9d14bcda8f2d1b0f07b36f1b # v0.1.0
371-
372366
- name: Checkout
373367
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
374368
with:
@@ -426,27 +420,11 @@ jobs:
426420
source scripts/normalize_path.sh
427421
normalize_path_with_symlinks "$RUNNER_TEMP/sym" "$(dirname "$(which terraform)")"
428422
429-
- name: Setup RAM disk for Embedded Postgres (Windows)
430-
if: runner.os == 'Windows'
431-
shell: bash
432-
# The default C: drive is extremely slow:
433-
# https://github.com/actions/runner-images/issues/8755
434-
run: mkdir -p "R:/temp/embedded-pg"
435-
436-
- name: Setup RAM disk for Embedded Postgres (macOS)
423+
- name: Setup macOS (install google-chrome, silence zsh warning)
437424
if: runner.os == 'macOS'
438425
shell: bash
439426
run: |
440-
# Postgres runs faster on a ramdisk on macOS.
441-
mkdir -p /tmp/tmpfs
442-
sudo mount_tmpfs -o noowners -s 8g /tmp/tmpfs
443-
444-
# Install google-chrome for scaletests.
445-
# As another concern, should we really have this kind of external dependency
446-
# requirement on standard CI?
447427
brew install google-chrome
448-
449-
# macOS will output "The default interactive shell is now zsh" intermittently in CI.
450428
touch ~/.bash_profile && echo "export BASH_SILENCE_DEPRECATION_WARNING=1" >> ~/.bash_profile
451429
452430
- name: Test with PostgreSQL Database (Linux)
@@ -476,7 +454,6 @@ jobs:
476454
test-count: ${{ github.ref == 'refs/heads/main' && '1' || '' }}
477455
# Only the CLI and Agent are officially supported on macOS; the rest are too flaky.
478456
test-packages: "./cli/... ./enterprise/cli/... ./agent/..."
479-
embedded-pg-path: "/tmp/tmpfs/embedded-pg"
480457
embedded-pg-cache: ${{ steps.embedded-pg-cache.outputs.embedded-pg-cache }}
481458

482459
- name: Test with PostgreSQL Database (Windows)
@@ -492,7 +469,6 @@ jobs:
492469
test-count: ${{ github.ref == 'refs/heads/main' && '1' || '' }}
493470
# Only the CLI and Agent are officially supported on Windows; the rest are too flaky.
494471
test-packages: "./cli/... ./enterprise/cli/... ./agent/..."
495-
embedded-pg-path: "R:/temp/embedded-pg"
496472
embedded-pg-cache: ${{ steps.embedded-pg-cache.outputs.embedded-pg-cache }}
497473

498474
- name: Upload failed test db dumps

scripts/embedded-pg/main.go

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"os"
99
"path/filepath"
10+
"runtime"
1011
"time"
1112

1213
embeddedpostgres "github.com/fergusstrange/embedded-postgres"
@@ -78,15 +79,73 @@ func main() {
7879
// Windows can't handle.
7980
// Related issue:
8081
// https://github.com/fergusstrange/embedded-postgres/issues/145
82+
//
83+
// Optimized for CI: speed over durability, crash safety disabled.
8184
paramQueries := []string{
82-
`ALTER SYSTEM SET effective_cache_size = '1GB';`,
85+
// Durability off, we don't care if data survives a crash in CI.
8386
`ALTER SYSTEM SET fsync = 'off';`,
87+
`ALTER SYSTEM SET synchronous_commit = 'off';`,
8488
`ALTER SYSTEM SET full_page_writes = 'off';`,
89+
90+
// Minimal WAL, requires max_wal_senders = 0.
91+
`ALTER SYSTEM SET wal_level = 'minimal';`,
92+
`ALTER SYSTEM SET max_wal_senders = '0';`,
93+
94+
// Infrequent checkpoints since we don't care about recovery time.
95+
`ALTER SYSTEM SET checkpoint_timeout = '30min';`,
96+
`ALTER SYSTEM SET max_wal_size = '4GB';`,
97+
`ALTER SYSTEM SET min_wal_size = '1GB';`,
98+
99+
// Prevent backends and checkpointer from requesting OS flushes.
100+
`ALTER SYSTEM SET backend_flush_after = '0';`,
101+
`ALTER SYSTEM SET checkpoint_flush_after = '0';`,
102+
103+
// Large WAL buffer to avoid frequent WAL writes.
104+
`ALTER SYSTEM SET wal_buffers = '64MB';`,
105+
106+
// Memory for parallel test workloads.
107+
`ALTER SYSTEM SET shared_buffers = '2GB';`,
108+
`ALTER SYSTEM SET effective_cache_size = '4GB';`,
109+
`ALTER SYSTEM SET work_mem = '16MB';`,
110+
`ALTER SYSTEM SET maintenance_work_mem = '256MB';`,
111+
`ALTER SYSTEM SET temp_buffers = '32MB';`,
112+
113+
// Many parallel tests.
85114
`ALTER SYSTEM SET max_connections = '1000';`,
86-
`ALTER SYSTEM SET shared_buffers = '1GB';`,
87-
`ALTER SYSTEM SET synchronous_commit = 'off';`,
115+
116+
// Let checkpoints handle dirty pages instead of bgwriter.
117+
`ALTER SYSTEM SET bgwriter_lru_maxpages = '0';`,
118+
119+
// Tests are short-lived, each uses own database.
120+
`ALTER SYSTEM SET autovacuum = 'off';`,
121+
122+
// JIT has startup overhead that hurts short-lived test queries.
123+
`ALTER SYSTEM SET jit = 'off';`,
124+
125+
// Reduce logging overhead.
126+
`ALTER SYSTEM SET log_checkpoints = 'off';`,
127+
`ALTER SYSTEM SET log_connections = 'off';`,
128+
`ALTER SYSTEM SET log_disconnections = 'off';`,
129+
130+
// Stats tracking not needed since autovacuum is off.
131+
`ALTER SYSTEM SET track_activities = 'off';`,
132+
`ALTER SYSTEM SET track_counts = 'off';`,
133+
88134
`ALTER SYSTEM SET client_encoding = 'UTF8';`,
89135
}
136+
137+
// Depot macOS runners have a disk accelerator, Windows runners have
138+
// slow EBS with no accelerator.
139+
switch runtime.GOOS {
140+
case "darwin":
141+
paramQueries = append(paramQueries,
142+
`ALTER SYSTEM SET random_page_cost = '1.0';`,
143+
)
144+
case "windows":
145+
paramQueries = append(paramQueries,
146+
`ALTER SYSTEM SET random_page_cost = '4.0';`,
147+
)
148+
}
90149
db, err := sql.Open("postgres", "postgres://postgres:postgres@127.0.0.1:5432/postgres?sslmode=disable")
91150
if err != nil {
92151
log.Fatalf("Failed to connect to embedded postgres: %v", err)

0 commit comments

Comments
 (0)