如何加速 SELECT BENCHMARK(1000000,ENCODE('hello',RAND()));

如何加速 SELECT BENCHMARK(1000000,ENCODE('hello',RAND()));

我想获得一些加快以下查询速度的想法:

SELECT BENCHMARK(1000000,ENCODE('hello',RAND()));

目前,我一直在尝试使用 my.cnf 选项,我可以在 9.5 秒内执行它...但是,有什么方法可以让它更快吗?

哪些变量与此查询更相关?更快的 CPU 会产生更好的结果吗?是否需要更快的磁盘,或者是否需要更多/更快的 RAM?

我正在使用一个 50Gb 的持久 SSD 磁盘,它应该能给我 1500 iops(我知道这不是最快的......但这对这次测试重要吗?)

这是全新安装的 Percona Server for MySQL,没有任何数据库。

mysql  Ver 14.14 Distrib 5.7.18-15, for debian-linux-gnu (x86_64) using  6.3

系统是 Google Cloud 上的 2 个 Skylake CPU 核心,配备 6 GB RAM。

cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 85
model name      : Intel(R) Xeon(R) CPU
stepping        : 3
microcode       : 0x1
cpu MHz         : 2000.064
cache size      : 56320 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 1
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms rtm avx512f avx512dq rdseed adx clflushopt clwb avx512cd avx512bw avx512vl xsaveopt
bugs            :
bogomips        : 4000.12
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 85
model name      : Intel(R) Xeon(R) CPU
stepping        : 3
microcode       : 0x1
cpu MHz         : 2000.064
cache size      : 56320 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 1
apicid          : 1
initial apicid  : 1
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms rtm avx512f avx512dq rdseed adx clflushopt clwb avx512cd avx512bw avx512vl xsaveopt
bugs            :
bogomips        : 4000.12
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

这是我当前的测试配置:

[mysql]

# CLIENT #
port                           = 3306
socket                         = /var/run/mysql/mysql.sock

[mysqld]

# GENERAL #
user                           = mysql
default-storage-engine         = InnoDB
socket                         = /var/run/mysql/mysql.sock
pid-file                       = /var/run/mysql/mysql.pid

# MyISAM #
key-buffer-size                = 32M
myisam-recover                 = FORCE,BACKUP

# SAFETY #
max-allowed-packet             = 1G
max-connect-errors             = 1000000
skip-name-resolve
sql-mode                       = STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY
sysdate-is-now                 = 1
innodb                         = FORCE

# CACHES AND LIMITS #
tmp-table-size                 = 32M
max-heap-table-size            = 32M
query-cache-type               = 0
query-cache-size               = 0
max-connections                = 128
thread-cache-size              = 100
open-files-limit               = 65535
table-definition-cache         = 4096
table-open-cache               = 2000
join-buffer-size               = 512K
sort-buffer-size               = 512K

# LOGGING #
log-error                      = /var/log/mysql/mysql-error.log
log-queries-not-using-indexes  = 0
slow-query-log                 = 0
slow-query-log-file            = /var/log/mysql/mysql-slow.log

# INNODB #
innodb-flush-method            = O_DIRECT
innodb-log-files-in-group      = 2
innodb-log-file-size           = 64M
innodb-flush-log-at-trx-commit = 2
innodb-file-per-table          = 1
innodb-buffer-pool-size        = 512M

# extra
innodb_doublewrite = 0
innodb_log_buffer_size = 64M

答案1

实际上,在测试了几个服务器之后,出现了一种模式。

此查询依赖于快速的 CPU,因此当我使用专用 CPU 实例而不是我们在云服务上看到的共享核心时,查询速度就会加快。

因此,它是 CPU 受限的。

相关内容