This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
backendcritical PriorityID: valkey-8-io-thread-numa-affinity-standard

Valkey 8.0 Multi-Threaded I/O Shard Affinity and NUMA Pinning Standard

Mandates strict CPU core pinning and NUMA node alignment for Valkey 8.0 multi-threaded I/O architectures to prevent cross-socket latency, L3 cache invalidation, and kernel lock contention. Prohibits floating threads across unbalanced sockets by configuring deterministic server-cpulist, bio-cpulist, and io-threads-cpulist parameters along with numactl process memory binding.

Prohibited Anti-Pattern: Unpinned Multi-Threaded I/O Engines Spanning Asymmetric NUMA Nodes Inducing Inter-Socket Cache Thrashing

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Valkey 8.0 Multi-Threaded I/O Shard Affinity and NUMA Pinning Standard - Mandates strict CPU core pinning and NUMA node alignment for Valkey 8.0 multi-threaded I/O architectures to prevent cross-socket latency, L3 cache invalidation, and kernel lock contention. Prohibits floating threads across unbalanced sockets by configuring deterministic server-cpulist, bio-cpulist, and io-threads-cpulist parameters along with numactl process memory binding.
globs: infra/**/*.{yaml,yml,conf,sh}, deploy/**/*.{yaml,yml,sh}, **/valkey*.conf, src/config/**/*.{ts,js,json}, src/infra/**/*.{ts,js}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/valkey-8-io-thread-numa-affinity-standard"
---

# Valkey 8.0 Multi-Threaded I/O Shard Affinity and NUMA Pinning Standard

> **Severity**: CRITICAL | **Category**: backend
> **Anti-Pattern Warning**: Unpinned Multi-Threaded I/O Engines Spanning Asymmetric NUMA Nodes Inducing Inter-Socket Cache Thrashing

## System Constraints
You are a Principal Software Architect enforcing the Valkey 8.0 Multi-Threaded I/O Shard Affinity Standard. You must guarantee that any Valkey 8.0 deployment, configuration generator, or infrastructure orchestration code isolates the engine's main loop, background I/O threads, and worker threads to dedicated physical cores on a single NUMA node. Reject all dynamic scheduling configurations that omit cpulist pinning or run multi-threaded Valkey instances across cross-socket memory boundaries.

## Strict Guidelines
- Engineers MUST ALWAYS enforce strict affinity between the Valkey main loop thread, bio (background I/O) threads, and I/O worker threads within a single NUMA socket using `server-cpulist`, `bio-cpulist`, and `io-threads-cpulist`.
- Engineers MUST NOT configure `io-threads` without explicitly setting matching `io-threads-cpulist` and `server-cpulist` values.
- Engineers MUST allocate physical CPU cores sequentially to avoid hyperthread sibling overlap across distinct execution stages (e.g., pinning main engine thread and heavy I/O threads onto distinct physical cores before allocating SMT siblings).
- Services MUST execute under `numactl --cpunodebind=<node> --membind=<node>` when launched in containerized or bare-metal environments to prevent Linux kernel scheduler thread migration across inter-connect buses (QPI/UPI).
- Code generating Valkey runtime topology MUST query hardware topology (`/sys/devices/system/node` or `hwloc`) and validate that total allocated cores do not exceed the capacity of the target NUMA domain.

## Bad vs Good Implementations
### Deterministic NUMA Topology & Thread Core Affinity Config Generator

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Enables multi-threaded I/O (`io-threads 4`) but fails to pin execution units with `server-cpulist`, `bio-cpulist`, or `io-threads-cpulist`. On multi-socket NUMA servers, memory access and worker threads will cross interconnect boundaries, introducing severe lock latency and L1/L2/L3 cache misses.
```typescript
import { writeFileSync } from 'fs';

interface ValkeyConfigOptions {
  port: number;
  ioThreads: number;
}

// ANTI-PATTERN: Enables multi-threaded I/O without hardware affinity or NUMA constraints.
// The OS scheduler will freely migrate threads across sockets, causing QPI bus saturation
// and cacheline invalidation during high-throughput I/O bursts.
export function generateValkeyConfig(options: ValkeyConfigOptions): void {
  const config = `
port ${options.port}
io-threads ${options.ioThreads}
io-threads-do-reads yes
protected-mode yes
maxmemory 16gb
maxmemory-policy allkeys-lru
`;
  writeFileSync('/etc/valkey/valkey.conf', config, { mode: 0o640 });
}
```

#### Production Standard (Correct)
> **Standard**: Validates distinct core sets and explicitly declares `server-cpulist`, `bio-cpulist`, and `io-threads-cpulist`. This guarantees zero cross-core cache interference and ensures all threads remain co-located on the same local NUMA memory node.
```typescript
import { writeFileSync } from 'fs';

export interface NumaCoreAllocation {
  numaNode: number;
  serverCore: number;
  bioCores: number[];
  ioThreadCores: number[];
}

export interface ProductionValkeyConfigOptions {
  port: number;
  affinity: NumaCoreAllocation;
  maxMemoryBytes: number;
}

// INVARIANT: Deterministically allocates threads strictly to a single NUMA domain's physical cores,
// separating the main event loop, background jobs, and multi-threaded I/O workers.
export function generateProductionValkeyConfig(options: ProductionValkeyConfigOptions): void {
  const { affinity } = options;
  const allAllocated = [affinity.serverCore, ...affinity.bioCores, ...affinity.ioThreadCores];
  const uniqueCores = new Set(allAllocated);
  if (uniqueCores.size !== allAllocated.length) {
    throw new Error('Core allocation conflict: Cores must be mutually exclusive.');
  }

  const config = [
    `port ${options.port}`,
    `protected-mode yes`,
    `maxmemory ${options.maxMemoryBytes}`,
    `maxmemory-policy allkeys-lru`,
    `io-threads ${affinity.ioThreadCores.length + 1}`,
    `io-threads-do-reads yes`,
    `# NUMA Node ${affinity.numaNode} Strict Pinning Invariants`,
    `server-cpulist ${affinity.serverCore}`,
    `bio-cpulist ${affinity.bioCores.join(',')}`,
    `io-threads-cpulist ${affinity.ioThreadCores.join(',')}`
  ].join('\n');

  writeFileSync(`/etc/valkey/valkey-${options.port}.conf`, config, { mode: 0o640 });
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Valkey 8.0 Multi-Threaded I/O Shard Affinity and NUMA Pinning Standard

Valkey 8.0 Multi-Threaded I/O Shard Affinity and NUMA Pinning Standard defines an industrial-grade behavioral standard for backend engineering. Mandates strict CPU core pinning and NUMA node alignment for Valkey 8.0 multi-threaded I/O architectures to prevent cross-socket latency, L3 cache invalidation, and kernel lock contention. Prohibits floating threads across unbalanced sockets by configuring deterministic server-cpulist, bio-cpulist, and io-threads-cpulist parameters along with numactl process memory binding. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Unpinned Multi-Threaded I/O Engines Spanning Asymmetric NUMA Nodes Inducing Inter-Socket Cache Thrashing Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftUnpinned Multi-Threaded I/O Engines Spanning Asymmetric NUMA Nodes Inducing Inter-Socket Cache ThrashingCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS enforce strict affinity between the Valkey main loop thread, bio (background I/O) threads, and I/O worker threads within a single NUMA socket using `server-cpulist`, `bio-cpulist`, and `io-threads-cpulist`.

Engineers MUST ALWAYS enforce strict affinity between the Valkey main loop thread, bio (background I/O) threads, and I/O worker threads within a single NUMA socket using `server-cpulist`, `bio-cpulist`, and `io-threads-cpulist`.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT configure `io-threads` without explicitly setting matching `io-threads-cpulist` and `server-cpulist` values.

Engineers MUST NOT configure `io-threads` without explicitly setting matching `io-threads-cpulist` and `server-cpulist` values.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Engineers MUST allocate physical CPU cores sequentially to avoid hyperthread sibling overlap across distinct execution stages (e.g., pinning main engine thread and heavy I/O threads onto distinct physical cores before allocating SMT siblings).

Engineers MUST allocate physical CPU cores sequentially to avoid hyperthread sibling overlap across distinct execution stages (e.g., pinning main engine thread and heavy I/O threads onto distinct physical cores before allocating SMT siblings).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Services MUST execute under `numactl --cpunodebind=<node> --membind=<node>` when launched in containerized or bare-metal environments to prevent Linux kernel scheduler thread migration across inter-connect buses (QPI/UPI).

Services MUST execute under `numactl --cpunodebind=<node> --membind=<node>` when launched in containerized or bare-metal environments to prevent Linux kernel scheduler thread migration across inter-connect buses (QPI/UPI).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Code generating Valkey runtime topology MUST query hardware topology (`/sys/devices/system/node` or `hwloc`) and validate that total allocated cores do not exceed the capacity of the target NUMA domain.

Code generating Valkey runtime topology MUST query hardware topology (`/sys/devices/system/node` or `hwloc`) and validate that total allocated cores do not exceed the capacity of the target NUMA domain.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Valkey 8.0 Multi-Threaded I/O Shard Affinity and NUMA Pinning Standard critical for AI coding assistants?

Mandates strict CPU core pinning and NUMA node alignment for Valkey 8.0 multi-threaded I/O architectures to prevent cross-socket latency, L3 cache invalidation, and kernel lock contention. Prohibits floating threads across unbalanced sockets by configuring deterministic server-cpulist, bio-cpulist, and io-threads-cpulist parameters along with numactl process memory binding. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Unpinned Multi-Threaded I/O Engines Spanning Asymmetric NUMA Nodes Inducing Inter-Socket Cache Thrashing) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

Valkey