Diagnosing Slow Page Load: HAProxy, TCP Dump, and MySQL Connection Analysis
This article walks through a systematic investigation of a web page that takes 2‑2.4 seconds to load, covering HAProxy configuration checks, network latency tests, TCP three‑handshake and packet‑capture analysis, and finally pinpointing MySQL connection handling as the root cause.
After deploying a new server and migrating a project, a single page took 2.2‑2.4 seconds to load, far exceeding the 300 ms threshold for user perception.
Investigation dimensions included checking HAProxy, the business server, and the database server.
1. HAProxy configuration – a simple IP‑to‑single‑machine load‑balancing rule was examined and ruled out as a source of delay.
2. Network latency – ping tests showed minimal round‑trip times, indicating that network overhead was not responsible for the slowdown.
3. TCP handshake and packet capture – using tcpdump , the author captured the three‑way handshake and subsequent data exchange, noting that the handshake itself only consumed ~43 ms, while a later packet exchange introduced a >2 s gap on the server side.
4. Database request analysis – initial hypotheses (heavy logic, I/O, high load, third‑party services) were eliminated via top and direct MySQL queries, leaving the database interaction as the suspect.
Further inspection revealed that the application opened many short‑lived MySQL connections instead of using persistent (long) connections, causing repeated connection overhead. The netstat output showed all MySQL sockets in TIME_WAIT state, confirming the lack of long connections.
Recommendations :
Enable MySQL persistent connections.
Batch multiple SQL statements into a single request and process results in PHP to reduce round‑trips.
By applying these fixes, the page load time can be reduced dramatically, turning a 2‑second delay into a sub‑200 ms response.
Xueersi Online School Tech Team
The Xueersi Online School Tech Team, dedicated to innovating and promoting internet education technology.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.