我的虚拟机是 Ubuntu 18.04,我安装了 2 个 MySQL 5.7 实例。
第一个安装在 localhost(端口 3306)中,第二个通过 docker-compose 安装(端口 57306)。配置 cnf(来自 localhost 版本的默认安装)都是相同的。
Docker 版本只有1700 个事务,而 localhost 版本只有 4100 个事务。
我的问题是,为什么 docker 版本慢很多,配置都一样,可能是什么问题?
我通过以下命令使用 sysbench 测试本地主机(端口 3306):
# prepare
sysbench --table_size=1000000 --db-driver=mysql --mysql-db=sysbench --mysql-user=root --mysql-password=<pass> /usr/share/sysbench/oltp_read_only.lua prepare
# run
sysbench --table_size=1000000 --db-driver=mysql --mysql-db=sysbench --mysql-user=root --mysql-password=<pass> --time=60 --max-requests=0 --threads=8 /usr/share/sysbench/oltp_read_only.lua run
我得到了4100 笔交易
SQL statistics:
queries performed:
read: 3444602
write: 0
other: 492086
total: 3936688
transactions: 246043 (4100.43 per sec.)
queries: 3936688 (65606.81 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 60.0025s
total number of events: 246043
Latency (ms):
min: 0.88
avg: 1.95
max: 19.27
95th percentile: 3.13
sum: 479541.05
Threads fairness:
events (avg/stddev): 30755.3750/971.95
execution time (avg/stddev): 59.9426/0.00
接下来,我docker-compose.yml
在端口 57306 中使用此文件部署 docker 版本
version: "3"
services:
mysql57:
build: ./bin/mysql57
container_name: 'mysql-5.7'
restart: 'unless-stopped'
ports:
- "57306:3306"
volumes:
- ./config/mysql57:/etc/mysql
- ./data/mysql57:/var/lib/mysql
- ./logs/mysql57:/var/log/mysql
environment:
MYSQL_ROOT_PASSWORD: <pass>
entrypoint: ""
command: bash -c "chown -R mysql:mysql /var/log/mysql && exec /entrypoint.sh mysqld"
该文件夹./config/mysql57
是从 localhost 配置中复制的(/etc/mysql)
然后我使用这个 sysbench 命令
#prepare
sysbench --table_size=1000000 --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=57306 --mysql-db=sysbench --mysql-user=root --mysql-password=<pass> /usr/share/sysbench/oltp_read_only.lua prepare
#run
sysbench --table_size=1000000 --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=57306 --mysql-db=sysbench --mysql-user=root --mysql-password=<pass> --time=60 --max-requests=0 --threads=8 /usr/share/sysbench/oltp_read_only.lua run
我预计至少交易像上面一样接近 4100,但这里只有 1700
SQL statistics:
queries performed:
read: 1431402
write: 0
other: 204486
total: 1635888
transactions: 102243 (1703.87 per sec.)
queries: 1635888 (27261.87 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 60.0047s
total number of events: 102243
Latency (ms):
min: 3.01
avg: 4.69
max: 14.64
95th percentile: 5.99
sum: 479794.64
Threads fairness:
events (avg/stddev): 12780.3750/11.56
execution time (avg/stddev): 59.9743/0.00