tempfiles

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package tempfiles defines a workload which executes queries that produce on-disk temporary files because their sort genuinely needs more memory than the server's work_mem — NOT because work_mem is artificially lowered. On a default-configured PostgreSQL (work_mem = 4MB) every query spills to an external merge; raising work_mem (per-role / per-database / session) makes the same query run fully in memory, so the "size work_mem correctly" remediation can actually be demonstrated.

On start the workload seeds its own per-run dataset table (noisia_tempfiles_<random8>, a wide incompressible (id, payload) heap whose size is configurable via --tempfiles.table-size, default 64 MiB) on a dedicated connection, following the bloatchurn/slotbloat convention. It then fans out Jobs workers; each opens its own connection pool and, in a rate-limited loop, fires a big "ORDER BY random()" sort over the dataset in a dedicated goroutine — asynchronously, so a slow spilling query does not throttle the required rate (this is why a pool, not a single connection, is used per worker: several spilling queries may be in flight at once, the deliberate exception to ADR-003-1). The dataset table is dropped on exit on a fresh connection (ADR-002-2). Total temp bytes are reported before/after via pg_stat_get_db_temp_bytes(); this is database-wide and cumulative, so the delta may include temp bytes produced by concurrent workload in the same database.

Workload duration is controlled by a context created outside and passed to Run. The context is the only stop mechanism: when it expires the loop drains in-flight queries and stops.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWorkload

func NewWorkload(config Config, logger log.Logger) (noisia.Workload, error)

NewWorkload creates a new workload with specified config.

Types

type Config

type Config struct {
	// Conninfo defines connection string used for connecting to Postgres.
	// It is a secret and must never be logged.
	Conninfo string
	// Jobs defines how many workers should be created for producing temp files.
	Jobs uint16
	// Rate defines rate interval for queries executing (queries per second, per worker).
	Rate float64
	// TableSize defines the target on-disk size in bytes of the per-run dataset table
	// (from --tempfiles.table-size, base-2 parsed; default 64 MiB). It is converted to a
	// row count via a payload-aware estimate. A full sort of the table must comfortably
	// exceed the default work_mem (4MB) so every query spills to an external merge, and the
	// payload MUST stay incompressible (random bytes, never zeros) or the table — and the
	// sort volume — would collapse below the target and might not spill (ADR-008-2).
	TableSize int64
}

Config defines configuration settings for temp files workload.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL