Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> MySQL

คำสั่งตรวจสอบ Read/Write Ratio ใน MySQL ด้วย SHOW STATUS

ใช้ SHOW STATUS และ SHOW GLOBAL STATUS เพื่อดูสถิติการอ่าน/เขียน

กรณีที่ 1: ดูคำสั่งทั้งหมด (Com_%)

SHOW STATUS LIKE 'Com_%';

กรณีที่ 2: ดูเฉพาะ Insert, Select, Update, Delete

SHOW GLOBAL STATUS WHERE Variable_name IN ('Com_insert','Com_select','Com_update','Com_delete');

ตัวอย่างผลลัพธ์

+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Com_delete    | 5     |
| Com_insert    | 340   |
| Com_select    | 286   |
| Com_update    | 13    |
+---------------+-------+

อัตราส่วน Read/Write ประมาณ: Read (Select) = 286, Write (Insert+Update+Delete) = 358

ผลลัพธ์เต็ม (SHOW STATUS LIKE 'Com_%')

แสดงตัวนับทุกคำสั่ง: Com_select, Com_insert, Com_update, Com_delete, Com_commit, Com_rollback, Com_create_table, ฯลฯ

การคำนวณ Ratio

Read Ratio  = Com_select / (Com_select + Com_insert + Com_update + Com_delete)
Write Ratio = (Com_insert + Com_update + Com_delete) / Total

หมายเหตุ: ค่าเป็นสะสมนับตั้งแต่ Server Start ต้อง Reset หรือคำนวณ Delta ระหว่างช่วงเวลา