惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
WordPress大学
WordPress大学
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
宝玉的分享
宝玉的分享
爱范儿
爱范儿
月光博客
月光博客
The GitHub Blog
The GitHub Blog
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
B
Blog
T
Tailwind CSS Blog
美团技术团队
D
Docker
V
Visual Studio Blog
Martin Fowler
Martin Fowler
博客园 - 聂微东
The Cloudflare Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How to Benchmark API Latency to Any Endpoint (Polymarket ...
BlueWhale-Quant-Lab · 2026-06-17 · via DEV Community

BlueWhale-Quant-Lab

"Just ping it" is bad latency advice. ICMP gets deprioritized behind CDNs and tells you almost nothing about real request latency. This is how to benchmark API latency properly, with a real case study: finding where Polymarket's order book lives.

Why ping lies

ping measures ICMP echo round-trip. But:

  • CDNs and load balancers often rate-limit or deprioritize ICMP, so the number is noisy or misleadingly high/low.
  • It ignores TLS handshake cost, which dominates short HTTPS requests.
  • It tells you nothing about server processing time (TTFB).

For an API, measure what the API actually does: TCP connect, TLS, and time-to-first-byte.

A proper latency harness (Python)

import socket, ssl, time, statistics, http.client

def percentiles(xs):
    xs = sorted(xs); n = len(xs)
    return {
        "min": round(xs[0], 2),
        "p50": round(statistics.median(xs), 2),
        "p95": round(xs[int(n*0.95)-1], 2),
        "p99": round(xs[int(n*0.99)-1], 2),
        "max": round(xs[-1], 2),
    }

def tcp_connect_ms(host, port=443):
    t = time.perf_counter()
    s = socket.create_connection((host, port), timeout=5); s.close()
    return (time.perf_counter() - t) * 1000

def ttfb_ms(host, path="/"):
    t = time.perf_counter()
    c = http.client.HTTPSConnection(host, 443, timeout=5,
                                    context=ssl.create_default_context())
    c.request("GET", path); r = c.getresponse(); r.read(1); c.close()
    return (time.perf_counter() - t) * 1000

def bench(host, n=200):
    return {
        "tcp_connect": percentiles([tcp_connect_ms(host) for _ in range(n)]),
        "ttfb":        percentiles([ttfb_ms(host) for _ in range(n)]),
    }

import json
print(json.dumps(bench("clob.polymarket.com"), indent=2))

Read p99 and jitter, not just the average

The average is marketing. What kills a trading bot is the p99 — your latency during the volatile windows you actually trade in. Always report min / p50 / p95 / p99 / max. A box with p50=1.2 ms but p99=12 ms is worse than a steady p50=3 ms box.

Check jitter over time, too:

ping -i 0.5 -c 600 clob.polymarket.com | tail -3   # watch min/avg/max/mdev spread

The case study: where is Polymarket's CLOB?

I ran the harness from VPS boxes in five regions:

Region TCP connect p50 TTFB p50
Amsterdam ~1.4 ms ~6 ms
Frankfurt ~9 ms ~16 ms
US-East ~90 ms ~110 ms
Singapore ~168 ms ~195 ms

A ~1.4 ms TCP connect is only possible within ~100 km (fiber does ~200 km/ms RTT). So the endpoint is in Amsterdam — proven by physics, not vibes. (Whether the matching engine is co-located vs behind an edge is a fair inference from the low TTFB, but the hosting decision is the same either way.)

Turning the benchmark into a decision

The whole point of benchmarking is to act on it. For Polymarket, the data says: host in Amsterdam. I moved my bot to an AMS-metro VPS and the connect time went from ~90 ms to ~1.2 ms. The box I use: the Amsterdam box I use
Disclosure: affiliate link — I earn a referral. The numbers above are from this box.

Reusable checklist

  • ✅ Measure TCP connect + TTFB, not just ICMP.
  • ✅ Report percentiles, especially p99.
  • ✅ Test jitter over minutes, at different times of day.
  • ✅ Compare multiple regions with hourly VPS boxes.
  • ✅ Convert sub-2 ms numbers into "same metro" conclusions via the fiber speed limit.

This harness works for any endpoint — exchanges, RPCs, your own APIs. Polymarket just happens to have a satisfying answer: Amsterdam.

Numbers from my own 2026 tests. Not financial advice.