|
| 1 | +--- |
| 2 | +title: Benchmark MySQL with mysqlslap |
| 3 | +weight: 7 |
| 4 | + |
| 5 | +### FIXED, DO NOT MODIFY |
| 6 | +layout: learningpathall |
| 7 | +--- |
| 8 | + |
| 9 | +## Benchmark MySQL on Azure Cobalt 100 Arm-based instances and x86_64 instances |
| 10 | + |
| 11 | +`mysqlslap` is the official MySQL benchmarking tool used to simulate multiple client connections and measure query performance. It helps evaluate **read/write throughput, query response times**, and overall MySQL server performance under different workloads, making it ideal for baseline testing and optimization. |
| 12 | + |
| 13 | +## Steps for MySQL Benchmarking with mysqlslap |
| 14 | + |
| 15 | +1. Connect to MySQL and Create a Database |
| 16 | + |
| 17 | +To access the MySQL server, use the following command based on your `admin` user password: |
| 18 | + |
| 19 | +```console |
| 20 | +mysql -u admin -p |
| 21 | +``` |
| 22 | +Once logged in, you can create a benchmark_db using SQL commands like: |
| 23 | + |
| 24 | +```sql |
| 25 | +CREATE DATABASE benchmark_db; |
| 26 | +USE benchmark_db; |
| 27 | +``` |
| 28 | + |
| 29 | +3. Create a Table and Populate Data |
| 30 | + |
| 31 | +After logging into MySQL, you can create a table to store benchmark data. Here’s a simple example: |
| 32 | + |
| 33 | +```sql |
| 34 | +CREATE TABLE benchmark_table ( |
| 35 | + record_id INT AUTO_INCREMENT PRIMARY KEY, |
| 36 | + username VARCHAR(50), |
| 37 | + score INT |
| 38 | +); |
| 39 | +``` |
| 40 | +Insert some sample rows manually: |
| 41 | + |
| 42 | +```sql |
| 43 | +INSERT INTO benchmark_table (username,score) VALUES |
| 44 | +('John',100),('Jane',200),('Mike',300); |
| 45 | +``` |
| 46 | + |
| 47 | +Or populate automatically with 1000 rows: |
| 48 | + |
| 49 | +```sql |
| 50 | +DELIMITER // |
| 51 | +CREATE PROCEDURE populate_benchmark_data() |
| 52 | +BEGIN |
| 53 | + DECLARE i INT DEFAULT 1; |
| 54 | + WHILE i <= 1000 DO |
| 55 | + INSERT INTO benchmark_table (username, score) |
| 56 | + VALUES (CONCAT('Player', i), i*10); |
| 57 | + SET i = i + 1; |
| 58 | + END WHILE; |
| 59 | +END // |
| 60 | +DELIMITER ; |
| 61 | + |
| 62 | +CALL populate_benchmark_data(); |
| 63 | +DROP PROCEDURE populate_benchmark_data; |
| 64 | +``` |
| 65 | +- The table `benchmark_table` has three columns: `record_id` (primary key), `username`, and `score`. |
| 66 | +- You can insert a few rows manually for testing or use a procedure to generate **1000 rows automatically** for more realistic benchmarking |
| 67 | + |
| 68 | +## Run a Simple Read/Write Benchmark |
| 69 | + |
| 70 | +Once your table is ready, you can use `mysqlslap` to simulate multiple clients performing queries. This helps test MySQL’s performance under load. |
| 71 | + |
| 72 | +```console |
| 73 | +mysqlslap --user=admin --password="MyStrongPassword!" --host=127.0.0.1 --concurrency=10 --iterations=5 --query="INSERT INTO benchmark_db.benchmark_table (username,score) VALUES('TestUser',123);" --create-schema=benchmark_db |
| 74 | +``` |
| 75 | +- **--user / --password:** MySQL login credentials. |
| 76 | +- **--host:** MySQL server address (127.0.0.1 for local). |
| 77 | +- **--concurrency:** Number of simultaneous clients (here, 10). |
| 78 | +- **--iterations:** How many times to repeat the test (here, 5). |
| 79 | +- **--query:** The SQL statement to run repeatedly. |
| 80 | +- **--create-schema:** The database in which to run the query. |
| 81 | + |
| 82 | +You should see output similar to the following: |
| 83 | + |
| 84 | +```output |
| 85 | +Benchmark |
| 86 | + Average number of seconds to run all queries: 0.267 seconds |
| 87 | + Minimum number of seconds to run all queries: 0.265 seconds |
| 88 | + Maximum number of seconds to run all queries: 0.271 seconds |
| 89 | + Number of clients running queries: 10 |
| 90 | + Average number of queries per client: 1 |
| 91 | +``` |
| 92 | + |
| 93 | +Below command runs a **read benchmark** on your MySQL database using `mysqlslap`. It simulates multiple clients querying the table at the same time and records the results. |
| 94 | + |
| 95 | +```console |
| 96 | +mysqlslap --user=admin --password="MyStrongPassword!" --host=127.0.0.1 --concurrency=10 --iterations=5 --query="SELECT * FROM benchmark_db.benchmark_table WHERE record_id < 500;" --create-schema=benchmark_db --verbose | tee -a /tmp/mysqlslap_benchmark.log |
| 97 | +``` |
| 98 | + |
| 99 | +You should see output similar to the following: |
| 100 | + |
| 101 | +```output |
| 102 | +Benchmark |
| 103 | + Average number of seconds to run all queries: 0.263 seconds |
| 104 | + Minimum number of seconds to run all queries: 0.261 seconds |
| 105 | + Maximum number of seconds to run all queries: 0.264 seconds |
| 106 | + Number of clients running queries: 10 |
| 107 | + Average number of queries per client: 1 |
| 108 | +``` |
| 109 | + |
| 110 | +## Benchmark Results Table Explained: |
| 111 | + |
| 112 | +- **Average number of seconds to run all queries:** This is the average time it took for all the queries in one iteration to complete across all clients. It gives you a quick sense of overall performance. |
| 113 | +- **Minimum number of seconds to run all queries:** This is the fastest time any iteration of queries took. |
| 114 | +- **Maximum number of seconds to run all queries:** This is the slowest time any iteration of queries took. The closer this is to the average, the more consistent your performance is. |
| 115 | +- **Number of clients running queries:** Indicates how many simulated users (or connections) ran queries simultaneously during the test. |
| 116 | +- **Average number of queries per client:** Shows the average number of queries each client executed in the benchmark iteration. |
| 117 | + |
| 118 | +## Benchmark summary on Arm64: |
| 119 | +Here is a summary of benchmark results collected on an Arm64 **D4ps_v6 Ubuntu Pro 24.04 LTS virtual machine**. |
| 120 | + |
| 121 | +| Query Type | Average Time (s) | Minimum Time (s) | Maximum Time (s) | Clients | Avg Queries per Client | |
| 122 | +|------------|-----------------|-----------------|-----------------|--------|----------------------| |
| 123 | +| INSERT | 0.267 | 0.265 | 0.271 | 10 | 1 | |
| 124 | +| SELECT | 0.263 | 0.261 | 0.264 | 10 | 1 | |
| 125 | + |
| 126 | +## Benchmark summary on x86_64: |
| 127 | +Here is a summary of the benchmark results collected on x86_64 **D4s_v6 Ubuntu Pro 24.04 LTS virtual machine**. |
| 128 | + |
| 129 | +| Query Type | Average Time (s) | Minimum Time (s) | Maximum Time (s) | Clients | Avg Queries per Client | |
| 130 | +|------------|-----------------|-----------------|-----------------|--------|----------------------| |
| 131 | +| INSERT | 0.243 | 0.231 | 0.273 | 10 | 1 | |
| 132 | +| SELECT | 0.222 | 0.214 | 0.233 | 10 | 1 | |
| 133 | + |
| 134 | +## Insights from Benchmark Results |
| 135 | + |
| 136 | +The benchmark results on the Arm64 virtual machine show: |
| 137 | + |
| 138 | +- **Balanced Performance for Read and Write Queries:** Both `INSERT` and `SELECT` queries performed consistently, with average times of **0.267s** and **0.263s**, respectively. |
| 139 | +- **Low Variability Across Iterations:** The difference between the minimum and maximum times was very small for both query types, indicating stable and predictable behavior under load. |
| 140 | +- **Moderate Workload Handling:** With **10 clients** and an average of **1 query per client**, the system handled concurrent operations efficiently without significant delays. |
| 141 | +- **Key Takeaway:** The MySQL setup on Arm64 provides reliable and steady performance for both data insertion and retrieval tasks, making it a solid choice for applications requiring dependable database operations. |
| 142 | + |
| 143 | +You have now benchmarked MySql on an Azure Cobalt 100 Arm64 virtual machine and compared results with x86_64. |
0 commit comments