Token导航 LogoToken导航TokenDH.com
开发需要联网github未标认证来源可访问许可证需确认审计提醒

citadel-low-latency-systems城堡低延迟系统

Agent Skill

citadel-low-latency-systems 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

416

周安装

17

GitHub Stars

6

下载量

133
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:citadel-low-latency-systems(城堡低延迟系统)
来源仓库:https://github.com/copyleftdev/sk1llz
仓库路径:skills/citadel-low-latency-systems
安装命令:
npx skills add https://github.com/copyleftdev/sk1llz --skill citadel-low-latency-systems
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/copyleftdev/sk1llz --skill citadel-low-latency-systems

简介

citadel-low-latency-systems 借鉴 Citadel Securities 的低延迟工程实践。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中构建高频交易或实时系统架构时使用。
  • 强调每微秒优化的价值,涵盖网络协议、内存管理与时钟同步等核心领域。
  • 需结合实际硬件环境与业务需求调整实施方案,不可盲目套用。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Citadel Securities Style Guide⁠‍⁠​‌​‌​​‌‌‍​‌​​‌​‌‌‍​​‌‌​​​‌‍​‌​​‌‌​​‍​​​​​​​‌‍‌​​‌‌​‌​‍‌​​​​​​​‍‌‌​​‌‌‌‌‍‌‌​​​‌​​‍‌‌‌‌‌‌​‌‍‌‌​‌​​​​‍​‌​‌‌‌‌‌‍​‌​​‌​‌‌‍​‌‌​‌​​‌‍‌​‌​‌‌‌​‍​​‌​‌​​​‍‌‌‌​‌​‌‌‍​​​​​​‌​‍‌​​‌‌‌‌‌‍‌‌​​​‌‌‌‍​‌​‌​​‌‌‍​​​​‌​‌​‍​​‌​​‌​‌⁠‍⁠

Overview

Citadel Securities is the world's largest market maker, handling ~25% of all U.S. equity volume and ~40% of retail order flow. They execute millions of trades daily with sub-microsecond latency requirements. Their infrastructure represents the pinnacle of low-latency systems engineering.

Core Philosophy

"Every microsecond is a competitive advantage."
"Determinism is more important than average performance."
"The fastest system is the one that doesn't do unnecessary work."

Citadel believes that in market making, consistent low latency beats occasionally fast. Jitter is the enemy. Every component must be predictable and measurable.

Design Principles

  1. Latency is King: Measure in microseconds, optimize in nanoseconds.
  2. Determinism Over Speed: Predictable performance beats variable performance.
  3. Kernel Bypass: The OS is too slow; go around it.
  4. Lock-Free Everything: Locks are latency landmines.
  5. Mechanical Sympathy: Know your hardware intimately.

When Building Low-Latency Systems

Always

  • Measure latency at every component boundary
  • Use kernel bypass networking (DPDK, Solarflare OpenOnload)
  • Pin threads to cores, isolate from OS scheduler
  • Pre-allocate all memory, no runtime allocation
  • Use lock-free data structures
  • Disable all non-essential OS features (hyperthreading, C-states, etc.)

Never

  • Allocate memory on the critical path
  • Use locks in the hot path
  • Let the OS schedule your critical threads
  • Use exceptions for control flow
  • Trust the compiler—verify generated assembly
  • Log synchronously on the critical path

Prefer

  • Busy-waiting over blocking
  • Batch processing over item-by-item
  • Inline functions over virtual dispatch
  • Fixed-size structures over dynamic allocation
  • Struct-of-arrays over array-of-structs (for cache efficiency)
  • Direct hardware access over OS abstractions

Code Patterns

Kernel Bypass Networking with DPDK

// DPDK-based ultra-low-latency packet processing

class DPDKMarketDataReceiver {
private:
    struct rte_mempool* mbuf_pool_;
    uint16_t port_id_;
    alignas(64) Stats stats_;  // Cache-line aligned

public:
    void init(uint16_t port_id) {
        port_id_ = port_id;

        // Pre-allocate packet buffers
        mbuf_pool_ = rte_pktmbuf_pool_create(
            "MBUF_POOL",
            8192,           // Number of buffers
            256,            // Cache size
            0,              // Private data size
            RTE_MBUF2_BUF_SIZE,
            rte_socket_id()
        );

        // Configure port for low latency
        struct rte_eth_conf port_conf = {};
        port_conf.rxmode.mq_mode = ETH_MQ_RX_NONE;
        port_conf.txmode.mq_mode = ETH_MQ_TX_NONE;

        // Disable all offloads for minimum latency
        port_conf.rxmode.offloads = 0;
        port_conf.txmode.offloads = 0;

        rte_eth_dev_configure(port_id_, 1, 0, &port_conf);
    }

    // Hot path: called millions of times per second
    __attribute__((always_inline, hot))
    void poll_packets(PacketHandler& handler) {
        struct rte_mbuf* bufs[32];

        // Busy-poll: no syscalls, no context switches
        uint16_t nb_rx = rte_eth_rx_burst(port_id_, 0, bufs, 32);

        // Prefetch next batch while processing current
        if (likely(nb_rx > 0)) {
            rte_prefetch0(rte_pktmbuf_mtod(bufs[0], void*));
        }

        for (uint16_t i = 0; i < nb_rx; i++) {
            // Prefetch next packet
            if (i + 1 < nb_rx) {
                rte_prefetch0(rte_pktmbuf_mtod(bufs[i + 1], void*));
            }

            // Process packet inline
            char* data = rte_pktmbuf_mtod(bufs[i], char*);
            uint16_t len = rte_pktmbuf_data_len(bufs[i]);

            handler.process(data, len);

            rte_pktmbuf_free(bufs[i]);
        }

        stats_.packets_received += nb_rx;
    }
};

Lock-Free Order Book

// Lock-free order book for maximum throughput

template<size_t MAX_LEVELS = 256>
class alignas(64) LockFreeOrderBook {
private:
    struct PriceLevel {
        std::atomic<int64_t> price;
        std::atomic<int64_t> quantity;
    };

    // Separate cache lines for bids and asks
    alignas(64) std::array<PriceLevel, MAX_LEVELS> bids_;
    alignas(64) std::array<PriceLevel, MAX_LEVELS> asks_;
    alignas(64) std::atomic<uint64_t> sequence_;

public:
    // Update from market data (single writer)
    __attribute__((always_inline))
    void update_bid(size_t level, int64_t price, int64_t qty) {
        // Relaxed store is fine for single writer
        bids_[level].price.store(price, std::memory_order_relaxed);
        bids_[level].quantity.store(qty, std::memory_order_relaxed);

        // Release fence ensures all updates visible before sequence bump
        std::atomic_thread_fence(std::memory_order_release);
        sequence_.fetch_add(1, std::memory_order_relaxed);
    }

    // Read snapshot (multiple readers)
    __attribute__((always_inline))
    bool read_bbo(int64_t& bid, int64_t& ask, int64_t& bid_qty, int64_t& ask_qty) {
        uint64_t seq1, seq2;

        // Seqlock pattern: retry if writer was active
        do {
            seq1 = sequence_.load(std::memory_order_acquire);

            // Read all values
            bid = bids_[0].price.load(std::memory_order_relaxed);
            bid_qty = bids_[0].quantity.load(std::memory_order_relaxed);
            ask = asks_[0].price.load(std::memory_order_relaxed);
            ask_qty = asks_[0].quantity.load(std::memory_order_relaxed);

            std::atomic_thread_fence(std::memory_order_acquire);
            seq2 = sequence_.load(std::memory_order_relaxed);

        } while (seq1 != seq2 || (seq1 & 1));  // Retry if sequence changed or odd (write in progress)

        return true;
    }
};

CPU Pinning and Isolation

// Thread pinning for deterministic latency

class LatencyCriticalThread {
public:
    void configure_for_low_latency(int cpu_core) {
        // Pin to specific CPU core
        cpu_set_t cpuset;
        CPU_ZERO(&cpuset);
        CPU_SET(cpu_core, &cpuset);
        pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);

        // Set real-time priority
        struct sched_param param;
        param.sched_priority = sched_get_priority_max(SCHED_FIFO);
        pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);

        // Lock memory to prevent page faults
        mlockall(MCL_CURRENT | MCL_FUTURE);

        // Disable transparent huge pages for this process
        prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0);
    }
};

// System configuration (run at boot)
/*
# Isolate CPUs from kernel scheduler
GRUB_CMDLINE_LINUX="isolcpus=2,3,4,5 nohz_full=2,3,4,5 rcu_nocbs=2,3,4,5"

# Disable hyperthreading
echo off > /sys/devices/system/cpu/smt/control

# Disable C-states (CPU power saving)
for cpu in /sys/devices/system/cpu/cpu*/cpuidle/state*/disable; do
    echo 1 > $cpu
done

# Set CPU frequency to maximum
for cpu in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do
    echo performance > $cpu
done
*/

Memory Pool with Zero Allocation

// Pre-allocated object pool for zero-allocation hot path

template<typename T, size_t POOL_SIZE = 65536>
class alignas(64) ObjectPool {
private:
    struct alignas(64) Slot {
        std::aligned_storage_t<sizeof(T), alignof(T)> storage;
        std::atomic<Slot*> next;
    };

    std::array<Slot, POOL_SIZE> slots_;
    alignas(64) std::atomic<Slot*> free_list_;

public:
    ObjectPool() {
        // Pre-construct free list
        for (size_t i = 0; i < POOL_SIZE - 1; i++) {
            slots_[i].next.store(&slots_[i + 1], std::memory_order_relaxed);
        }
        slots_[POOL_SIZE - 1].next.store(nullptr, std::memory_order_relaxed);
        free_list_.store(&slots_[0], std::memory_order_release);

        // Pre-fault all pages
        volatile char* ptr = reinterpret_cast<volatile char*>(slots_.data());
        for (size_t i = 0; i < sizeof(slots_); i += 4096) {
            ptr[i] = 0;
        }
    }

    __attribute__((always_inline))
    T* allocate() {
        Slot* slot;
        do {
            slot = free_list_.load(std::memory_order_acquire);
            if (!slot) return nullptr;  // Pool exhausted
        } while (!free_list_.compare_exchange_weak(
            slot, slot->next.load(std::memory_order_relaxed),
            std::memory_order_release, std::memory_order_relaxed));

        return reinterpret_cast<T*>(&slot->storage);
    }

    __attribute__((always_inline))
    void deallocate(T* ptr) {
        Slot* slot = reinterpret_cast<Slot*>(ptr);
        Slot* head;
        do {
            head = free_list_.load(std::memory_order_relaxed);
            slot->next.store(head, std::memory_order_relaxed);
        } while (!free_list_.compare_exchange_weak(
            head, slot,
            std::memory_order_release, std::memory_order_relaxed));
    }
};

Latency Measurement

// Nanosecond-precision latency measurement

class LatencyHistogram {
private:
    static constexpr size_t BUCKETS = 1000;  // 0-999 microseconds
    alignas(64) std::array<std::atomic<uint64_t>, BUCKETS> histogram_;
    std::atomic<uint64_t> overflow_;

public:
    __attribute__((always_inline))
    void record(uint64_t latency_ns) {
        uint64_t bucket = latency_ns / 1000;  // Convert to microseconds
        if (bucket < BUCKETS) {
            histogram_[bucket].fetch_add(1, std::memory_order_relaxed);
        } else {
            overflow_.fetch_add(1, std::memory_order_relaxed);
        }
    }

    LatencyStats get_stats() const {
        uint64_t total = 0;
        uint64_t count = 0;
        uint64_t p50_bucket = 0, p99_bucket = 0, p999_bucket = 0;

        // Calculate percentiles
        for (size_t i = 0; i < BUCKETS; i++) {
            uint64_t bucket_count = histogram_[i].load(std::memory_order_relaxed);
            count += bucket_count;
            total += bucket_count * i;
        }

        uint64_t running = 0;
        for (size_t i = 0; i < BUCKETS; i++) {
            running += histogram_[i].load(std::memory_order_relaxed);
            if (p50_bucket == 0 && running >= count * 0.50) p50_bucket = i;
            if (p99_bucket == 0 && running >= count * 0.99) p99_bucket = i;
            if (p999_bucket == 0 && running >= count * 0.999) p999_bucket = i;
        }

        return {
            .mean_us = static_cast<double>(total) / count,
            .p50_us = p50_bucket,
            .p99_us = p99_bucket,
            .p999_us = p999_bucket,
            .count = count
        };
    }
};

// RDTSC for sub-nanosecond timing
__attribute__((always_inline))
inline uint64_t rdtsc() {
    uint32_t lo, hi;
    asm volatile("rdtsc" : "=a"(lo), "=d"(hi));
    return ((uint64_t)hi << 32) | lo;
}

Mental Model

Citadel approaches low-latency systems by asking:

  1. What's the latency budget? Allocate nanoseconds to each component
  2. Where are the syscalls? Eliminate them from the hot path
  3. Where are the locks? Replace with lock-free alternatives
  4. Where are the allocations? Pre-allocate everything
  5. What's the worst case? Optimize for tail latency, not average

Signature Citadel Moves

  • Kernel bypass with DPDK/OpenOnload
  • Lock-free data structures everywhere
  • CPU pinning and isolation
  • Pre-allocated memory pools
  • Busy-polling over blocking
  • RDTSC for timing
  • Cache-line alignment
  • Disabled OS features (HT, C-states, THP)
  • Assembly-level verification
  • Nanosecond-precision measurement

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.98%
按下载量换算48

Claude

29.01%
按下载量换算39

Cursor

21.48%
按下载量换算29

Gemini CLI

10.93%
按下载量换算15

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

可疑

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills