Queries_per_sec (QPS)是數據庫兩個比較重要的性能計數器指標。咱們常常要求開發告知這個參數,以評估數據庫的一個負載狀況。下面的這段代碼連上服務器,作一個簡單的查詢:
數據庫
using (MySqlConnection conn = new MySqlConnection())
{
conn.ConnectionString = "Database=xx;Host=xx;Port=xx;User Id=xx; Password=xx; charset=utf8;pooling=true;";
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = conn;
conn.Open();
cmd.CommandText = " select * from test where ID = 3";
cmd.ExecuteNonQuery();
conn.Close();
}
性能計數器是咱們從show global status採集而來。其中的Questions和Queries定義以下:
服務器
Questions
The number of statements executed by the server. This includes only statements sent to the server by clients and not statements executed within stored programs, unlike the Queries variable. This variable does not count COM_PING, COM_STATISTICS, COM_STMT_PREPARE, COM_STMT_CLOSE, or COM_STMT_RESET commands.
Queries
The number of statements executed by the server. This variable includes statements executed within stored programs, unlike the Questions variable. It does not count COM_PING or COM_STATISTICS commands.
3499308 Init DB testdb
3499308 Query select * from test where ID = 3
3499308 Init DB testdb
3499308 Query select * from test where ID = 3
一、Com_admin_commands
二、Com_change_db
三、Com_select
第二和第三比較好解釋,Com_Change_DB至關於咱們的Init DB, COM_Select就是咱們的SELECT查詢。而第一個Com_admin_commands就比較奇怪了。經查代碼,這是下面的幾計數器的集合。其餘的通常都用不到,能用到的就剩下COM_PING了。
性能
COM_CHANGE_USER
COM_SHUTDOWN
COM_PING
COM_DEBUG
COM_BINLOG_DUMP_GTID
COM_BINLOG_DUMP
Queries_per_sec 比咱們預期的QPS高三倍,是因爲驅動程序對鏈接有Ping的一個檢驗動做。這個動做應該也算做Queries。在Questions裏體現不出來。3d