Logo

Personal Ops Runbook

Personal runbook covering infrastructure operations for Cloud, Kubernetes, OpenStack, and Ceph environments. Includes deployment and teardown procedures, node management, cluster monitoring setup, and incident response workflows compiled from day-to-day operational work. Intended strictly for personal reference — configurations and scripts are environment-specific and not guaranteed to work as-is elsewhere.

Benchmark MySQL sử dụng Sysbench

Cài đặt sysbench.

apt update
apt install sysbench -y

Truy cập vào mysql và tạo db tên sysbench

docker exec -it mariadb bash

Example output

shell> mysql -u root -plsMz0cb0eLGAMESg
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.11.10-MariaDB-ubu2204 mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database sysbench;
Query OK, 1 row affected (0.002 sec)

MariaDB [(none)]>

Sau đó, dùng lệnh sau để tạo 1000000 bản ghi. Nhớ thay đổi passwordmysql với password mysql phù hợp.

sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=10.237.7.77 --mysql-port=3306 --mysql-user=root --mysql-password='lsMz0cb0eLGAMESg' --mysql-db=sysbench --db-driver=mysql --tables=2 --table-size=1000000 prepare

Trong đó:

–mysql-user : user sử dụng mysql
–mysql-password : password của user
–tables : Số bảng tạo
–table-size : Số bản ghi trong 1 bảng

Example output

Creating table 'sbtest1'...
Inserting 1000000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
Creating table 'sbtest2'...
Inserting 1000000 records into 'sbtest2'
Creating a secondary index on 'sbtest2'...

Kiểm tra DB vừa tạo:

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| keystone_sw_auth_2 |
| mysql              |
| performance_schema |
| sys                |
| sysbench           |
+--------------------+
6 rows in set (0.001 sec)

MariaDB [(none)]> use sysbench;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [sysbench]> show table status like 'sbtest%' \G;
*************************** 1. row ***************************
            Name: sbtest1
          Engine: InnoDB
         Version: 10
      Row_format: Dynamic
            Rows: 986400
  Avg_row_length: 228
     Data_length: 225132544
 Max_data_length: 0
    Index_length: 16269312
       Data_free: 0
  Auto_increment: 1000001
     Create_time: 2025-01-09 09:13:43
     Update_time: 2025-01-09 09:13:41
      Check_time: NULL
       Collation: utf8mb4_general_ci
        Checksum: NULL
  Create_options:
         Comment:
Max_index_length: 0
       Temporary: N
*************************** 2. row ***************************
            Name: sbtest2
          Engine: InnoDB
         Version: 10
      Row_format: Dynamic
            Rows: 986400
  Avg_row_length: 228
     Data_length: 225132544
 Max_data_length: 0
    Index_length: 16269312
       Data_free: 0
  Auto_increment: 1000001
     Create_time: 2025-01-09 09:14:07
     Update_time: 2025-01-09 09:14:01
      Check_time: NULL
       Collation: utf8mb4_general_ci
        Checksum: NULL
  Create_options:
         Comment:
Max_index_length: 0
       Temporary: N
2 rows in set (0.001 sec)

ERROR: No query specified

MariaDB [sysbench]>

Đẩy tải MySQL.

sysbench /usr/share/sysbench/select_random_points.lua --table-size=2000000 --threads=100 --rand-type=uniform --db-driver=mysql --mysql-db=sysbench --mysql-user=root --mysql-password='lsMz0cb0eLGAMESg' --mysql-host=10.237.7.77 --mysql-port=3306 --time=30 run

Example output

Running the test with following options:
Number of threads: 100
Initializing random number generator from current time
Initializing worker threads...
Threads started!

SQL statistics:
    queries performed:
        read:                            541732
        write:                           0
        other:                           0
        total:                           541732
    transactions:                        541732 (18033.74 per sec.)
    queries:                             541732 (18033.74 per sec.)
    ignored errors:                      0      (0.00 per sec.)
    reconnects:                          0      (0.00 per sec.)

General statistics:
    total time:                          30.0384s
    total number of events:              541732

Latency (ms):
         min:                                    0.14
         avg:                                    5.53
         max:                                  673.29
         95th percentile:                       12.30
         sum:                              2996231.20

Threads fairness:
    events (avg/stddev):           5417.3200/1357.70
    execution time (avg/stddev):   29.9623/0.02
  • Thông tin số lượng request mỗi giây được thể hiện trong phần transactions và queries của báo cáo.
  • Cụ thể:
    • Transactions: 541732 (18033.74 per sec.)
    • Queries: 541732 (18033.74 per sec.)
    • Có nghĩa là trong suốt thời gian chạy benchmark (30 giây), hệ thống đã thực hiện tổng cộng 541732 transactions và 541732 queries, với tốc độ trung bình là 18033.74 giao dịch mỗi giây và 18033.74 truy vấn mỗi giây.
    • Số lượng request mỗi giây: 18033.74 requests per second (rps)

Như vậy với 18033.74 reqs/s và latency trung bình 5.53ms cho thấy hệ thống đang hoạt động với hiệu suất cao khá cao.

Làm sạch DB sau khi test xong:

sysbench /usr/share/sysbench/oltp_read_write.lua --db-driver=mysql --mysql-db=sysbench --mysql-user=root --mysql-password='lsMz0cb0eLGAMESg' --mysql-host=10.237.7.77 --tables=1 cleanup

Example output

sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
Dropping table 'sbtest1'...