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

推荐订阅源

博客园 - 聂微东
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
C
Check Point Blog
M
MIT News - Artificial intelligence
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
DataBreaches.Net
大猫的无限游戏
大猫的无限游戏
D
Docker
Last Week in AI
Last Week in AI
IT之家
IT之家
F
Fortinet All Blogs
A
About on SuperTechFans
P
Proofpoint News Feed
The Cloudflare Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog RSS Feed
博客园_首页
月光博客
月光博客
博客园 - 司徒正美
Y
Y Combinator 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
Tracing a 2s Latency Spike to a Single SQL Query
wheresthelag · 2026-05-06 · via DEV Community

wheresthelag

We received an alert around early morning 4AM indicating that our checkout service latency had jumped from its usual 50ms p99 to over 2 seconds. There were no errors, CPU usage was normal, and the database appeared healthy. Despite everything looking fine in the logs, users were clearly experiencing delays.

Initial Checks
We started with the usual suspects:

  • Application metrics: CPU and memory utilization were stable.
  • Database health: PostgreSQL showed no signs of stress.
  • Slow query logs: No entries, even with the threshold set to 1 second.
  • Redis/cache layer: Operating as expected.

Why Logs Weren’t Enough
Our logs provided detailed information about individual events such as HTTP requests, SQL executions, and service interactions. However, they lacked the context needed to understand how time was spent across the entire request lifecycle. Logs answered what happened, but not where the time went.

Request Trace Overview
Incoming Request (~2.1s total)
├── Auth Service (~120ms)
├── Business Logic (~150ms)
└── Database Call (~35ms execution + ~2.05s data transfer)

To gain better visibility, we examined the transaction trace using opmanager nexus. The trace revealed that while the database executed the query quickly, the application thread spent significant time waiting to read the response from the network buffer (SocketInputStream.read()).

Identifying the Root Cause
The SQL query involved was straightforward:
SELECT * FROM inventory_logs WHERE item_id = ?;

A recent schema update had introduced a JSONB column storing detailed audit information. For frequently updated items, this column had grown to more than 15MB per row. Because of the SELECT * statement, the application fetched this entire payload, leading to significant network transfer and deserialization overhead.

The Fix
We updated the query to retrieve only the necessary columns:

SELECT status, last_updated
FROM inventory_logs
WHERE item_id = ?;

The impact was immediate:

  • Database time: Reduced from ~35ms to ~12ms.
  • Result processing time: Dropped from ~2.05s to a negligible level.
  • End-to-end latency: Improved from ~2.1 seconds to ~12ms.

Key Takeaways

  1. Not all slow requests are caused by slow queries.
  2. Avoid SELECT * in production systems.
  3. Distinguish between query execution and data transfer time.
  4. Logs provide events, not end-to-end context.
  5. Distributed tracing is essential for accurate root cause analysis.

The invisible bottleneck
This incident highlighted how performance bottlenecks can arise from subtle changes in data access patterns. Even well-indexed queries can introduce latency if they return more data than necessary. Differentiating between query execution and data transfer is essential for accurate root cause analysis.