본문 바로가기

Tech/Tips

Sysbench를 활용한 mariaDB 벤치마크

반응형

이미지 출처 : Pixabay

마리아db 벤치마킹을 위한 툴을 찾아보다 sysbench를 처음 접하게 되었습니다.

예전부터 사용되던 유서깊은 벤치마킹 툴인데, 한동안 업데이트되지 않았다가 다시 활발히 업데이트가 진행되고 있습니다.

git : https://github.com/akopytov/sysbench

 

akopytov/sysbench

Scriptable database and system performance benchmark - akopytov/sysbench

github.com

 

맥에서는 homebrew를 통해 관련 디펜던시까지 한번에 설치해 줄 수 있습니다 : 

brew install sysbench

Sysbench에서 지정해 줄 수 있는 대표적인 옵션들은 다음과 같습니다 : 

General options 설명 기본값
--threads=N 사용할 스레드의 갯수를 지정합니다. 1
--events=N 총 이벤트 횟수를 지정합니다. 0 (0은 무제한)
--time=N 실행 시간을 제한합니다. 10 (sec)
--rate=N tps를 제한합니다. 0 (0은 최대 tps로 전송)
--report-interval=N 주기보고 간격을 지정합니다. 0 (0은 주기보고를 비활성화함)

mysql 벤치마크 옵션은 다음과 같습니다 : 

mysql options 설명 기본값
--mysql-host mysql DB 서버 호스트명 localhost
--mysql-port mysql Db 서버 포트  3306
--mysql-socket mysql DB 서버 소켓  
--mysql-user mysql DB 서버 사용자 비밀번호 sbtest
--mysql-password 위에서 지정한 mysql DB 서버 사용자 비밀번호  
--mysql-db mysql DB 명 sbtest

모든 옵션들은 다음과 같습니다 (sysbench --help)

General options:

  --threads=N                     number of threads to use [1]

  --events=N                      limit for total number of events [0]

  --time=N                        limit for total execution time in seconds [10]

  --forced-shutdown=STRING        number of seconds to wait after the --time limit before forcing shutdown, or 'off' to disable [off]

  --thread-stack-size=SIZE        size of stack per thread [64K]

  --rate=N                        average transactions rate. 0 for unlimited rate [0]

  --report-interval=N             periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0]

  --report-checkpoints=[LIST,...] dump full statistics and reset all counters at specified points in time. The argument is a list of comma-separated values representing the amount of time in seconds elapsed from start of test when report checkpoint(s) must be performed. Report checkpoints are off by default. []

  --debug[=on|off]                print more debugging info [off]

  --validate[=on|off]             perform validation checks where possible [off]

  --help[=on|off]                 print help and exit [off]

  --version[=on|off]              print version and exit [off]

  --config-file=FILENAME          File containing command line options

  --tx-rate=N                     deprecated alias for --rate [0]

  --max-requests=N                deprecated alias for --events [0]

  --max-time=N                    deprecated alias for --time [0]

  --num-threads=N                 deprecated alias for --threads [1]

 

Pseudo-Random Numbers Generator options:

  --rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [special]

  --rand-spec-iter=N number of iterations used for numbers generation [12]

  --rand-spec-pct=N  percentage of values to be treated as 'special' (for special distribution) [1]

  --rand-spec-res=N  percentage of 'special' values to use (for special distribution) [75]

  --rand-seed=N      seed for random number generator. When 0, the current time is used as a RNG seed. [0]

  --rand-pareto-h=N  parameter h for pareto distribution [0.2]

 

Log options:

  --verbosity=N verbosity level {5 - debug, 0 - only critical messages} [3]

 

  --percentile=N       percentile to calculate in latency statistics (1-100). Use the special value of 0 to disable percentile calculations [95]

  --histogram[=on|off] print latency histogram in report [off]

 

General database options:

 

  --db-driver=STRING  specifies database driver to use ('help' to get list of available drivers) [mysql]

  --db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]

  --db-debug[=on|off] print database-specific debug information [off]

 

 

Compiled-in database drivers:

  mysql - MySQL driver

 

mysql options:

  --mysql-host=[LIST,...]          MySQL server host [localhost]

  --mysql-port=[LIST,...]          MySQL server port [3306]

  --mysql-socket=[LIST,...]        MySQL socket

  --mysql-user=STRING              MySQL user [sbtest]

  --mysql-password=STRING          MySQL password []

  --mysql-db=STRING                MySQL database name [sbtest]

  --mysql-ssl[=on|off]             use SSL connections, if available in the client library [off]

  --mysql-ssl-cipher=STRING        use specific cipher for SSL connections []

  --mysql-compression[=on|off]     use compression, if available in the client library [off]

  --mysql-debug[=on|off]           trace all client library calls [off]

  --mysql-ignore-errors=[LIST,...] list of errors to ignore, or "all" [1213,1020,1205]

  --mysql-dry-run[=on|off]         Dry run, pretend that all MySQL client API calls are successful without executing them [off]

 

Compiled-in tests:

  fileio - File I/O test

  cpu - CPU performance test

  memory - Memory functions speed test

  threads - Threads subsystem performance test

  mutex - Mutex performance test

 

이제 sysbench를 실제로 활용해 보기 위해 mariaDB에 테스트용 DB와 계정을 만들어 줍니다.

CREATE DATABASE sbtest;
CREATE USER 'sbtest'@'%' IDENTIFIED BY 'sbtest1234';
GRANT ALL PRIVILEGES ON sbtest.* TO 'sbtest'@'%';
FLUSH PRIVILEGES;

 

테스트용 DB 생성

위에 있는 옵션들과 아래 옵션을 사용하여 테스트 옵션을 작성합니다.

mysql table options 설명 기본값
--table-size 시작시 테이블 사이즈를 지정합니다. 10000
--tables DB 내 테스트 할 테이블의 갯수를 지정합니다. 1

mariadb 테스트를 위한 스크립트는 homebrew로 설치한 경우 /usr/local/Cellar/sysbench/1.0.20/share/sysbench 경로에 위치하고 있습니다. 각 스크립트는 제목과 같이 특정 테스트를 위하여 구분되어 있으며, 본 글에서는 oltp_read_write.lua 스크립트를 사용하여 벤치마킹을 진행하도록 하겠습니다.

/usr/local/Cellar/sysbench/1.0.20/share/sysbench

테스트 실행 전 준비작업을 진행합니다.

sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=sbtest --mysql-password=sbtest1234 --mysql-db=sbtest --table-size=10000 --tables=5 /usr/local/Cellar/sysbench/1.0.20/share/sysbench/oltp_read_write.lua prepare

테스트 전 준비작업

테스트는 시간 또는 이벤트 수를 기반으로 진행할 수 있습니다.

 

1. 5초마다 보고, 총 이벤트 횟수 = 10000회

sysbench --threads=8 --events=10000 --report-interval=5 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=sbtest --mysql-password=sbtest1234 --mysql-db=sbtest --table-size=10000 --tables=5 /usr/local/Cellar/sysbench/1.0.20/share/sysbench/oltp_read_write.lua run

첫 번째 벤치마크 실행 결과

2. 5초마다 보고, 총 실행시간 = 20초

sysbench --threads=8 --time=20 --report-interval=5 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=sbtest --mysql-password=sbtest1234 --mysql-db=sbtest --table-size=10000 --tables=5 /usr/local/Cellar/sysbench/1.0.20/share/sysbench/oltp_read_write.lua run

두 번째 벤치마크 실행 결과

벤치마크가 끝난 이후에는 cleanup 명령어를 사용하여 생성된 테스트 데이터를 삭제할 수 있습니다.

sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=sbtest --mysql-password=sbtest1234 --mysql-db=sbtest --table-size=10000 --tables=5 /usr/local/Cellar/sysbench/1.0.20/share/sysbench/oltp_read_write.lua cleanup

테스트 데이터 삭제

즉, prepare를 통해 벤치마크 실행 전 테스트 데이터를 생성하고, run을 통해 벤치마크를 실시하고, cleanup을 통해 테스트 데이터를 삭제할 수 있습니다.

반응형