官术网_书友最值得收藏!

  • MariaDB High Performance
  • Pierre MAVRO
  • 486字
  • 2021-08-05 18:03:18

Profiling

Profiling permits you to benchmark information that indicates resource usages during a session. This is used when we want to get information on a specified query. Here are the types of information:

  • Block I/O
  • Context switches
  • CPU
  • IPC
  • Memory
  • Page faults
  • Source
  • Swaps
  • All

First of all, you need to know that profiling on a production server is not recommended because of the performance degradation it can cause.

To enable profiling, use the following command:

MariaDB [none]> SET PROFILING=1;

Perform all the query tasks you want to profile and then list them:

MariaDB [none]> SHOW PROFILES;
+----------+------------+-------------------------+
| Query_ID | Duration | Query |
+----------+------------+-------------------------+
| 1 | 0.30798532 | select * from s_explain |
| 2 | 0.25341312 | select * from s_explain |
+----------+------------+-------------------------+

In the preceding command-line output, you can see that we've two query IDs. To get information related to the first Query_ID, with extra columns for the CPU, use the following command:

MariaDB [none]> SHOW PROFILE CPU FOR QUERY 1;
+--------------------------------+----------+----------+------------+
| Status | Duration | CPU_user | CPU_system |
+--------------------------------+----------+----------+------------+
| starting | 0.000034 | 0.000000 | 0.000000 |
| Waiting for query cache lock | 0.000009 | 0.000000 | 0.000000 |
| init | 0.000008 | 0.000000 | 0.000000 |
[...]
| init | 0.000016 | 0.000000 | 0.000000 |
| optimizing | 0.000011 | 0.000000 | 0.000000 |
| statistics | 0.000050 | 0.000000 | 0.000000 |
| preparing | 0.000017 | 0.000000 | 0.000000 |
| executing | 0.000008 | 0.000000 | 0.000000 |
| Sending data | 0.007369 | 0.004001 | 0.000000 |
| Waiting for query cache lock | 0.000020 | 0.000000 | 0.000000 |
| Sending data | 0.003420 | 0.004000 | 0.000000 |
[...]
| Sending data | 0.271156 | 0.272017 | 0.000000 |
| end | 0.000020 | 0.000000 | 0.000000 |
| query end | 0.000010 | 0.000000 | 0.000000 |
| closing tables | 0.000015 | 0.000000 | 0.000000 |
| freeing items | 0.000009 | 0.000000 | 0.000000 |
| updating status | 0.000041 | 0.000000 | 0.000000 |
| cleaning up | 0.000029 | 0.000000 | 0.000000 |
+--------------------------------+----------+----------+------------+

You will find a lot of interesting information in the preceding command-line output. Here is an overview:

  • init: This gives information of the starting process for the storage engine
  • optimizing: This gives the query plan information as given in the slow query logs
  • statistics: This shows the engine locking and optimization
  • executing: This shows the execution time (as in Query_plan)

In the preceding command line, we've just specified the CPU type and got all the extra columns related to it. If we want maximum information, replace CPU with ALL.

So, now you're able to compare multiple requests, see their evolution, and track the used resources with them.

主站蜘蛛池模板: 广丰县| 合肥市| 舞阳县| 达日县| 屏边| 通化市| 玉龙| 北流市| 罗江县| 罗江县| 安达市| 兴和县| 莫力| 九龙坡区| 芜湖市| 中山市| 苍南县| 榆林市| 隆回县| 夏河县| 蒙阴县| 泰宁县| 隆德县| 调兵山市| 万州区| 台北县| 安远县| 犍为县| 民勤县| 响水县| 县级市| 康马县| 大埔区| 宝清县| 抚松县| 乌拉特中旗| 柞水县| 湘乡市| 清远市| 彭泽县| 全椒县|