SShortSingh.
Back to feed

Python's Per-Call TLS Handshake, Not Slow APIs, Caused False Latency Readings

0
·75 views

A developer spent 48 hours investigating an apparent performance gap between curl and a Python probe hitting the same local health endpoint. While curl reused a single TCP and TLS connection across its run, the Python loop using urllib.request.urlopen() opened and closed a fresh connection on every iteration, adding handshake overhead each time. The discrepancy had nothing to do with the network, DNS, proxies, or the upstream API — all of which returned consistent HTTP 200 responses throughout. The root cause was a measurement design flaw: connection setup costs were being recorded as origin latency. The fix is to reuse connections via a persistent session object, which avoids repeated TLS handshakes and produces accurate timing data.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingHacker News ·

Netherlands Reportedly Negotiating Dismantling of the International Criminal Court

A report from Rights Forum cites diplomatic sources claiming the Netherlands is negotiating the dismantling of the International Criminal Court. The claim comes from anonymous sources and has not been confirmed by official statements in the available material. The item was shared on Hacker News, where it drew modest attention with 51 points and 2 comments. The available text does not detail the specific proposals, timeline, or reasons behind the reported negotiations. Readers should treat the claim as unverified until corroborated by official or independent reporting.

0
ProgrammingDEV Community ·

Centralized Command-Sourced Document Design Avoids CRDTs, Trading Convergence for Strict Ordering

A developer write-up argues for a centralized, command-sourced collaborative document system that drops conflict-free replicated data types in favor of a single authority enforcing transactional ordering. It warns that treating multiple windows of one document as independent file writers causes OS file-lock contention, write failures, and journal corruption. The recommended fix is a master-sidecar design where one local authority process owns the journal and other windows connect as zero-write IPC clients. To avoid slow late-joiner synchronization from replaying an unbounded journal, the author proposes periodic snapshot checkpoints that truncate the log. The article also cautions that naive client-side rebase rules break down for hierarchical document structures.

0
ProgrammingDEV Community ·

nRouter releases SDKs across multiple languages sharing one API key and endpoint

nRouter has published official software development kits for Python, TypeScript, Go, Rust, Java/Kotlin, Swift, Dart and R, each installable through its ecosystem's package registry. All of them read the same NROUTER_API_KEY environment variable and connect to one endpoint, so access can be issued, rotated and revoked from a single place. The company's pitch is that cost tracking, guardrails and fallback routing run on the server side, keeping behavior consistent across languages. Existing OpenAI and Anthropic clients can also be pointed at the gateway through a configuration change. The author, who works at nRouter and disclosed AI assistance in drafting the post, invited readers to share how they manage credentials across polyglot stacks.

0
ProgrammingDEV Community ·

FreeLLMAPI Pools Free Tiers of 34 AI Providers Behind One Self-Hosted Endpoint

FreeLLMAPI is a self-hosted router that combines the free tiers of 34 AI providers behind a single OpenAI-compatible endpoint, which the project says adds up to roughly 7.4 billion tokens per month. It automatically selects the best available model for each request and fails over to another provider when one is rate-limited or returns an error. The tool tracks per-key rate limits to stay within each provider's free-tier caps and supports a range of API surfaces, including chat, image, audio, embeddings, Anthropic and Gemini formats. Developers can connect coding assistants such as Claude Code and Codex CLI through a single setup command. The project is written in TypeScript, released under the MIT license, and has around 50,000 GitHub stars.