Remember once optimized windfall

I. found the following problems in acquiring MySQL connection time

First visit

Second visit

Here is what I do the test code

Two. Cause

  1. first visit to slow, the second fast, it is easy to think of cache, is where we get the code to test the connection, so it should be connected to the cache, we use the connection server monitoring function monitors the MySQL navicat, but the connection the number has been stable at four, did not increase, there is no cache.

  2. cache instead of connecting it possible that in the first query will do some analytical work, learned later, mysql there is a process called reverse analysis, that is, find the domain name through IP, this process can be time consuming, but this is a call associated with the host cache thing, after a reverse lookup to resolve, will host this domain name and IP with an error message being cached, if there is a second visit this cache instructions for the reverse analysis but unfortunately did not, this description is not affected.

  3. Later, the teacher asked, after some checking first thought to be because many of the classes will be loaded into memory, and the second time without loading, this process takes is a few hundred milliseconds, because the method will call the Connect and various initialization involves loading a lot of the underlying class, so it's probably the last call this method in the main method, each consuming the same time, because every time the main method to reload class, thus the reason the bottom, perfect.

Guess you like

Origin www.cnblogs.com/lollong/p/11539954.html