Colocation Latency Budget Accounting 标志

Colocation Latency Budget Accounting

社区
HimanshuJ16
colocation-latency-budget-accounting

分析共置服务器在主机内部的关键路径时使用:将 NIC 入站到 NIC 出站的过程拆分为纳秒级阶段,并根据各阶段的预算审查每条跟踪记录。主机外的所有环节都属于其他技能的范围。

Add to TypingMind

概览

发布者HimanshuJ16
代码仓库Algo-Trading-Skills
技能名称colocation-latency-budget-accounting
星标数
50
复刻数
7
附带文件
5
许可协议Apache-2.0
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 5 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 HimanshuJ16 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Colocation Latency Budget Accounting AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/colocation-latency-budget-accounting
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/HimanshuJ16/Algo-Trading-Skills.git /tmp/Algo-Trading-Skills
mkdir -p .claude/skills
cp -r /tmp/Algo-Trading-Skills/skills/colocation-latency-budget-accounting .claude/skills/colocation-latency-budget-accounting
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Colocation Latency Budget Accounting,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Colocation Latency Budget Accounting。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Colocation Latency Budget Accounting 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

When to Use

Use this skill when profiling and auditing the "hot path" of a high-frequency trading (HFT) server in a co-located data centre. Tick-to-trade (T2T) latency is the elapsed time from hardware packet arrival at the NIC ($T_0$) to order byte transmission ($T_5$). This module decomposes T2T into discrete processing phases (NIC ingress → decode → alpha signal → pre-trade risk → binary encode → NIC egress), audits them against a total and per-phase budget, names the phase most over its budget, and reports tail jitter ($P_{99}$, $P_{99.9}$).

When NOT to Use

  • For anything outside the box. This skill starts at NIC ingress and stops at NIC egress. Cross-venue propagation, facility choice and cross-connects belong to co-location-provider-selection-and-network-topology; the end-to-end measurement harness belongs to tick-to-trade-latency-measurement.
  • As the instrumentation itself. This is the offline accounting half. It consumes traces that some lock-free hot-path instrumentation already captured; it does not capture timestamps, and it must never be called from the hot path.
  • When the timestamps are not on one clock. $T_0/T_5$ come from the NIC's PTP hardware clock (PHC); $T_1 \dots T_4$ typically come from CLOCK_MONOTONIC. Convert to a single time base before building a HotPathTrace — see Pitfalls. The engine rejects traces that go backwards, but it cannot detect a constant inter-domain offset.
  • As a regulatory timestamping record. MiFID II RTS 25 governs business clock accuracy and granularity for reportable events against UTC. CLOCK_MONOTONIC is not UTC-traceable, and this module's relative nanosecond deltas are not a substitute for a compliant timestamping record. See references/standards.md.
  • For sub-100 sample batches. Percentiles finer than the batch can resolve are interpolations, not measurements (see Pitfalls).

Prerequisites

  • Hardware timestamping enabled on the NIC. On Linux, request SOF_TIMESTAMPING_RX_HARDWARE / SOF_TIMESTAMPING_TX_HARDWARE via SO_TIMESTAMPING, and confirm driver support with ethtool -T <iface>.
  • A high-resolution in-host timer for $T_1 \dots T_4$: clock_gettime(CLOCK_MONOTONIC), or rdtsc. rdtsc returns cycle counts, not nanoseconds — converting requires a calibrated invariant-TSC frequency (invariant TSC is advertised by CPUID.80000007H:EDX[8]), and readings are only comparable across cores when the TSC is invariant and synchronised.
  • A documented conversion between the NIC PHC domain and the in-host timer domain.
  • NumPy.

Units

All timestamps, phase durations and SLAs are nanoseconds (ns), as Python int. Percentile outputs are floats rounded to 1 dp; count is the batch size. Nothing in this module is microseconds — a value pasted in as µs is off by 1,000x and will not be caught.

Workflow

  1. Hot Path Instrumentation: record high-resolution timestamps at each stage boundary into a fixed-size lock-free buffer — $T_0$ NIC ingress, $T_1$ decode complete, $T_2$ alpha signal evaluated, $T_3$ pre-trade risk complete, $T_4$ order encoded, $T_5$ NIC egress.
  2. Normalise to One Clock: convert $T_0/T_5$ (NIC PHC) and $T_1 \dots T_4$ (CLOCK_MONOTONIC) onto a single monotonic nanosecond base before constructing traces.
  3. Ingest with Quarantine: build HotPathTrace objects off the hot path. Construction raises ValueError on non-monotonic timestamps — catch it per trace, increment a quarantine counter, and continue. A non-monotonic trace is an instrumentation or clock-domain defect, not a fast execution; do not clamp it to zero and do not let it abort the batch.
  4. Configure the Budget (LatencyBudgetAccountingEngine): total_sla_ns plus a phase_slas_ns map covering every phase in PHASE_NAMES. Unknown or missing keys raise — a typo must not silently give a phase a 0 ns budget. If the phase budgets sum above the total, the engine logs a warning: that configuration is legal but means a trace can breach the total with no phase over its own budget.
  5. Audit (audit_trace): is_sla_breach is a strict >, so a trace landing exactly on total_sla_ns is inside budget. On breach the report carries phase_excess_ns (duration − budget, per phase) and names as primary_bottleneck_phase the phase with the greatest excess — even when every excess is negative, in which case it is the phase closest to its limit. Ties break by hot-path order.
  6. Tail Reporting (compute_percentiles): $P_{50}, P_{95}, P_{99}, P_{99.9}$ plus mean and count for the total and every phase. Read count before trusting a tail figure.

Full procedure: see references/workflows.md. Standards reference: see references/standards.md. Printable pre-flight checklist: see assets/checklist.md.

Common Pitfalls

  • Mixing Clock Domains: NIC hardware timestamps are taken in the NIC's own PHC domain; CLOCK_MONOTONIC is a different clock. Subtracting one from the other yields an offset, not a duration — often large enough to be negative, sometimes small enough to look plausible. The engine rejects the negative case; the plausible case is silently wrong, which is why the conversion must be documented rather than assumed.
  • Using time.time() for Hot-Path Timestamps: time.time() reads CLOCK_REALTIME, which NTP steps and slews — it can move backwards, so a phase can measure negative. Use CLOCK_MONOTONIC for in-host deltas and NIC hardware timestamps for $T_0/T_5$. A userspace timestamp also includes interrupt-handling and scheduler delay that the NIC timestamp excludes; that gap is not bounded and grows exactly when the machine is busiest.
  • Profiling in the Hot-Path Thread: writing log lines or computing percentiles inside the execution thread adds I/O and allocation latency to the order it is measuring. Record into a lock-free ring buffer and run this module out-of-band.
  • Reading a P99.9 off a Small Batch: a percentile finer than $1/(1-q)$ samples is interpolated between the top two observations. P99.9 from 10 samples is a restatement of the maximum with a decimal point on it. compute_percentiles warns and returns count — check it before putting the figure on a dashboard.
  • Believing a Breach Has No Bottleneck: whenever the per-phase budgets sum above the total, every phase can be inside its own budget while the total breaches. A breached trace always names a phase; a negative phase_excess_ns on that phase is the signal that the budget allocation, not the code, is the problem.
  • Focusing on Mean Latency: a 10 µs mean is meaningless if $P_{99.9}$ spikes to 5 ms during a volatility burst — the spike is exactly when the fill mattered. Evaluate SLAs on tails.
  • Silently Dropping Rejected Traces: quarantining a bad trace without counting it biases the tail downwards, because instrumentation defects correlate with the slow path. Count and alert on the quarantine rate.

Verification

  • Construct LatencyBudgetAccountingEngine(total_sla_ns=10000) (default phase budgets). Audit a trace with phase durations [1000, 1000, 8000, 1000, 4000] ns: total is 15,000 ns, is_sla_breach is True, and primary_bottleneck_phase is signal_to_risk_ns with phase_excess_ns["signal_to_risk_ns"] == 6500 (8,000 ns against a 1,500 ns budget).
  • Construct LatencyBudgetAccountingEngine(total_sla_ns=5000) — the default phase budgets sum to 8,000 ns, so the engine warns. Audit a trace of five 1,100 ns phases: total 5,500 ns breaches, yet every phase is inside its own budget. primary_bottleneck_phase must still be non-None, with a negative excess.
  • HotPathTrace("BAD", 1000, 900, 2000, 3000, 4000, 5000) must raise ValueError, not produce a −100 ns phase.
  • Run python -m unittest discover -s skills/colocation-latency-budget-accounting/scripts.

Related Skills

  • tick-to-trade-latency-measurement
  • strategy-latency-budget-decomposition
  • clock-drift-monitoring-alerting-thresholds
  • hardware-timestamping-vs-software-timestamping-accuracy
  • co-location-provider-selection-and-network-topology

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Colocation Latency Budget Accounting AI 技能有什么作用?

分析共置服务器在主机内部的关键路径时使用:将 NIC 入站到 NIC 出站的过程拆分为纳秒级阶段,并根据各阶段的预算审查每条跟踪记录。主机外的所有环节都属于其他技能的范围。

为什么在 TypingMind 中使用 Colocation Latency Budget Accounting?

因为您只需安装一次,就能搭配任何模型使用。Colocation Latency Budget Accounting 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Colocation Latency Budget Accounting?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/colocation-latency-budget-accounting。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Colocation Latency Budget Accounting?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Colocation Latency Budget Accounting 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Colocation Latency Budget Accounting 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Colocation Latency Budget Accounting AI 技能免费吗?

是的。HimanshuJ16 已在 GitHub 上根据 Apache-2.0 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇