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