關於MySQL DNS解析探究之二:unauthenticated user

把這篇沒寫完的文章寫完,2015年的事就不留到2016了java

開啓DNS解析

mysql> show variables like 'skip_name_resolve';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| skip_name_resolve | OFF   |
+-------------------+-------+

經過代碼模擬用戶查詢請求,不斷的創建鏈接執行sql查詢,而後經過show processlist命令查看鏈接狀況:mysql

JAVA代碼一sql

/**
 *  MySQL Problem DNS lead to 'unauthenticated  user'
 */
public class MysqlDNSUnauthUser {

    public static final Logger LOG = LoggerFactory
            .getLogger(MysqlDNSUnauthUser.class);
    /**
     * 執行查詢操做
     * @return
     */
    public static long query() {

        long start = System.currentTimeMillis();
        Connection conn = null;
        Statement stmt = null;

        String sql = "select 1";
        try {
            // 建立新的鏈接
            conn = DBUtils.getConnection();
            stmt = conn.createStatement();
            stmt.executeQuery(sql);

        } catch (SQLException e) {
            LOG.error(e.getMessage(), e);
        } finally {
            DBUtils.close(conn, stmt);
        }

        long end = System.currentTimeMillis();
        return end - start;
    }

    public static void main(String[] args) {

        // 描述統計
        DescriptiveStatistics stats = new DescriptiveStatistics();
        int n = 0;
        while(true) {
            n++;
            long time = query();
            stats.addValue(time);
            if(n == 1000) break;
        }

        LOG.info(stats.toString());
    }
}

打印結果以下:bash

n: 1000
min: 10.0
max: 421.0
mean: 14.202000000000002
std dev: 16.242444797905648
median: 12.0
skewness: 20.270437547223214
kurtosis: 463.94461541900915

發現最大值421ms性能

mysql> show processlist;
+------+----------------------+-------------------+------+---------+------+-------+------------------+
| Id   | User                 | Host              | db   | Command | Time | State | Info             |
+------+----------------------+-------------------+------+---------+------+-------+------------------+
|    7 | root                 | localhost         | test | Query   |    0 | NULL  | show processlist |
| 2763 | unauthenticated user | 192.168.4.2:54804 | NULL | Connect | NULL | login | NULL             |
+------+----------------------+-------------------+------+---------+------+-------+------------------+

能夠發現其中出現unauthenticated user的用戶code

關閉DNS解析

/etc/my.cnf中的[mysqld]節點增長skip_name_resolve,重啓mysqld服務ip

mysql> show variables like 'skip_name_resolve';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| skip_name_resolve | ON    |
+-------------------+-------+

再次執行JAVA代碼一,結果以下:ssl

n: 1000
min: 7.0
max: 413.0
mean: 10.306999999999988
std dev: 16.131117877070835
median: 9.0
skewness: 20.655330340756084
kurtosis: 471.9124123214076

對比上一次開啓DNS解析,此次的結果性能有所提升,上一次的均值是14ms,此次爲10msget

mysql> show processlist;
+------+----------------------+-------------------+------+---------+------+-------+------------------+
| Id   | User                 | Host              | db   | Command | Time | State | Info             |
+------+----------------------+-------------------+------+---------+------+-------+------------------+
|    2 | root                 | localhost         | NULL | Query   |    0 | NULL  | show processlist |
| 3891 | unauthenticated user | 192.168.4.2:59502 | NULL | Connect | NULL | login | NULL             |
+------+----------------------+-------------------+------+---------+------+-------+------------------+

能夠發現仍然出現了unauthenticated user的用戶io

目前可得出以下結論:

DNS解析確實會影響鏈接創建的性能,可是DNS解析開啓與否,與出現unauthenticated user沒有關係

猜測unauthenticated user的出現應該是鏈接在創建的過程當中出現的臨時狀態

相關文章
相關標籤/搜索