causes

When using Google Chrome to connect to the interface, I found that one interface occasionally took tens of seconds to respond, but most of the time it was normal and could complete the response in 500 milliseconds, so I traced the problem back.

Problem analysis

  • Check the corresponding waterfall information of this interface and analyze which part is using too long time. The waterfall information is shown below.

  • It can be seen from the figure that the Waiting(TTFB) part of the interface is 312ms, indicating that the response time of the back end is completely normal and the problem is not at the back end.

  • With a staggering 31.51 seconds of its own cost, it was clear that the problem lay in its extraordinary cost.

What does time cost me

Cost of hour is the time an interface waits to be transmitted. We all know that Chrome has a limit on the number of TCP connections that can be maintained in the same domain. Chrome can currently be considered six. If we make more than six requests to a domain name at a time, the additional requests are queued until the previous connections are released.

Cause of unusually long cost – hour

I checked all the requests and found out that some image server was suspended, which caused some image requests to remain pending. Resulting in a long wait for subsequent requests.

The solution

  • The key point is that the picture server does not immediately return when I request the picture. Since I am in the test server, I did not pay much attention to the picture server hanging, which caused the problem. Repairing the picture server can solve the problem.

conclusion

  • It is important to place image resources in the CDN to prevent blocking resource loading.
  • Obtaining non-existent resources or suspending services also occupies network resources and should be avoided.