Then the last time the network bandwidth continued to say that the network bandwidth problem is solved, but user feedback is still very slow, sometimes good and sometimes bad, what should I do?
As a developer, the most taboo is to answer something like this: I have no problem. Look at the service log, P99 is all 10ms, and it is very healthy. It must be a problem with the client. Go to them.
Developers should have the feelings of Barrels stop here, it is your problem to solve it, not your problem to give you the best solution
The first step is to go to the user to reproduce the problem
The user will not complain for no reason (unless he wants to find something), since he is slow, there may be something wrong. Circle a few suspicion points first (delineation of suspicion points may require experience, and no experience can analyze the data), the client sends a request to get the data but only a few steps, local request preparation, connection establishment, preparation for transmission, transmission, server reception When it comes to request processing request, return, presentation, each link will do a time-consuming analysis to see where it takes more time, introduce a tool, curl, the installation method under ubuntu: sudo apt-get install curl
This is a very powerful command, with many parameters, you can learn by yourself, only the ones you need to solve the problem:
curl -o/dev/null -s -w %{time_connect},%{time_namelookup},%{time_connect},%{time_pretransfer},%{time_starttransfer},%{time_total} http://yourdomain/api/xxx
time_connect: Time to establish a connection
time_namelookup: DNS resolution time
time_pretransfer: the time from the establishment of the connection to the beginning of the file transfer
time_starttransfer: time when the first byte is received
time_total: the entire request time
Note that the unit is seconds
If the data is collected continuously, the analysis can be similar to the following figure:
Then the problem is obvious
Note: Some students may ask, how can I go to the user to reproduce, provide two ideas, use proxy (the command itself can support) or client upload log
The second step, how to solve
We know that the advantage of using a domain name is the readability and IP address change. I changed a new server (for example, I changed the machine and the IP corresponding to the domain name changed), which is transparent to the client, but increased the domain name to IP Resolution time
Change the DNS cache policy of the client, the default is 30 seconds (it seems to be in memory)
Insufficient: For example, change to 30 minutes, but if the IP changes, the update will be a bit slow
Manage domain names in your own APP-IP change strategy
Start to update the IP (background) for the first time, then use the IP to access, and then periodically update the background
The starting point of this case is a global service, and optimization is much more complicated than this. It involves multiple problems in multi-country computer rooms, but the idea of solving the problems is roughly the same.
The above example is HTTP, other protocols have similar ideas
Domestic qq, weixin, etc. all use IP to bypass domain names. The demand for performance needs to give up easy things, do it yourself, and customize