Skip to content

[Performance]: every statement calls statfs on the spill directory (ensureAllocationAccountLifecycle → refreshAutomaticSpillDiskCap) #32818

Todo

Description

@cpegeric

Is there an existing issue for performance?

  • I have checked the existing issues.

Environment

- Version or commit-id: main 8e8708a8d3 (compared with 625865c470)
- Hardware parameters: Apple M2 Max, 12 cores, 32 GB
- OS type: macOS 26.5
- Others: 2 CN processes sharing local MinIO, TZ=UTC; TPC-C 10 warehouses, 25 terminals per CN, 5 minutes

Details of Performance

On a TPC-C run, every statement now pays a statfs(2) syscall on the spill directory. Its CPU cost doubled between 625865c and main.

Call path:

  • Compile.ensureAllocationAccountLifecycle (pkg/sql/compile/allocation_account_lifecycle.go:302) calls proc.GetExecutionResourceBudget() whenever the physical plan has an operator that activates an allocation account (hasAllocationAccountActivator).
  • For a new generation, that goes through initializeGenerationSpillBudget → ExecutionResourceBudget.refreshAutomaticSpillDiskCap(proc.automaticSpillDiskAvailable) (pkg/vm/process/execution_resource_budget.go:2224, :521).
  • That calls spillDiskAvailableBytes → unix.Statfs (pkg/vm/process/spill_disk_capacity_unix.go:25), with no caching between statements.

Origin:

Measured:

  • Setup: 60 s CPU profiles of the CN process taken 2 minutes into the run. Each build was cold-restarted, with tpcc restored from the same snapshot.
  • Results:
build unix.Statfs CPU (all of it under ensureAllocationAccountLifecycle) total CPU samples TPC-C tpmC (2 CNs)
625865c (before #32492) 14.7 s / 14.7 s 327 s / 338 s 14,234 / 14,241
main 8e8708a 29.5 s / 31.5 s 299 s / 300 s 11,809 (run 1)

Expected:

  • Don't sample free disk space per statement.
  • For example, cache spillDiskAvailableBytes per spill root and refresh it at most every few hundred milliseconds.
  • Or sample only when a statement actually reserves spill space.
  • The headroom policy in refreshAutomaticSpillDiskCap only needs an approximate, recent value.

Additional information

Profiles and counters: two interleaved runs per build of the same 2-CN TPC-C setup. They can be shared on request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions