[Performance] Sysbench 설치 및 사용방법

■ SysBench 히스토리 아키텍처

sysbench 2004 Peter Zaitsev 의해 만들어졌고 Alexey Kopytov 개발을 인수했습니다. 버전 0.4.12에서 개발이 중단되었습니다. Alexey 2016년에 다시 작업하기 시작했습니다. LUA 기반 스크립트를 사용하도록 OLTP 벤치 마크를 다시 작성하여 버전 0.5 릴리스되었습니다. 그런 다음 2017 년에 SysBench 1.0 릴리스되었습니다. 이것은 0.4.12 이전 버전과는 비교할 없을 정도로 훌륭하게 만들어졌습니다. 하드코딩된 스크립트 대신 LUA 사용하여 벤치마크를 사용자가 원하는 방법으로 정의하여 테스트할 있습니다. 이것은 굉장히 유연하게 테스트 있는 방법을 제공합니다.

 

SysBench LUA 스크립트를 사용하여 벤치 마크를 실행하는 C 바이너리입니다. sysbench는 다음과 같은 테스트 방식을 모두 수용합니다.

1. 명령 매개 변수의 입력 처리

2. 벤치 마크가 사용해야하는 모든 모드 정의 (준비, 실행, 정리)

3. 모든 데이터를 준비

4. 벤치 마크 실행 방법 정의 (쿼리 모양 )

스크립트는 데이터베이스에 대한 여러 연결을 활용할 있으며, 쿼리가 이전 쿼리의 결과 집합에 의존하는 복잡한 벤치 마크를 생성하려는 경우 결과를 처리 수도 있습니다. SysBench 1.0 사용하면 대기 시간 히스토그램을 생성 있습니다. LUA 스크립트가 오류 후크를 통해 오류를 포착하고 처리 수도 있습니다. LUA 스크립트에는 병렬화가 지원되며, 여러 쿼리를 병렬로 실행할 수 있어 훨씬 빠르게 프로비저닝 있습니다. 마지막으로 여러 출력 형식이 지원됩니다. SysBench 이전엔 사람이 읽을 수있는 출력만 생성했습니다. 이제 CSV 또는 JSON으로 생성 있으므로 gnuplot 사용하거나 Prometheus, Graphite 또는 유사한 데이터 저장소에 데이터를 공급하는 사후 처리를 수행하고 그래프를 훨씬 쉽게 생성 있습니다.

 

공식사이트 원래 이곳이었습니다. 현재는 중단된것으로 보입니다. 2016 자료가 마지막으로 되어 있습니다.

https://launchpad.net/sysbench 

 

추후 이곳으로 옮겨집니다.

https://github.com/akopytov/sysbench

 

sysbench 소스 설치에 필요한 패키지

yum install make automake libtool pkgconfig libaio-devel openssl-devel

MySQL 혹은 MariaDB rpm으로 설치되어 있을 경우 다음 패키지를 설치

MySQL : mysql-devel

MariaDB : mariadb-devel

 

■ 설치 방법

MySQL 서버를 소스로 설치했을 경우 --with-mysql-includes 경로와 --with-mysql-libs 경로를 입력합니다.
MySQL 설치경로가 /usr/local/mysql이라는 가정하에 설치를 진행합니다.
기본 설치 경로는 /usr/local/sysbench인데 이 디렉토리 외에 다른곳에 설치하고 싶다면 --prefix를 정의하고 설치합니다.
* 압축 해제 및 컴파일 환경 설정
shell> wget https://github.com/akopytov/sysbench/archive/1.0.20.tar.gz
shell> tar -zxvf 1.0.20.tar.gz
shell> cd sysbench-1.0.xx
shell> ./autogen.sh
* MySQL 전용
./configure --prefix=/usr/local/sysbench --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib
* MySQL, PostgreSQL 같이 설치되어 있는경우
./configure --prefix=/usr/local/sysbench --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib --with-pgsql --with-pgsql-includes=/usr/local/pgsql/include --with-pgsql-libs=/usr/local/pgsql/lib
make -j
make install

■ 환경설정
MySQL을 소스로 컴파일하여 설치했을 시 Library를 로드해 주어야 합니다. 만약 환경설정 없어 Sysbench를 수행할 시 다음과 같은 에러를 만나게 됩니다.
/usr/local/sysbench/bin/sysbench: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
▶︎ 설정방법 - CentOS 기준.
-  다음 디렉토리로 이동합니다.
shell> cd /etc/ld.so.conf.d
▶︎ MySQL Shared Libaray 추가
- 다음 파일을 작성합니다.
shell> vi mysql.conf
/usr/local/mysql/lib
저장하고 나옵니다.
▶︎ PostgreSQL Shared Libaray 추가
shell> vi /etc/ld.so.conf.d/postgresql.conf
/usr/local/pgsql/lib
저장하고 나옵니다.
▶︎ 라이브러리를 재로딩 합니다. root로 수행합니다.
shell> ldconfig

 

실행방법

./sysbench --help : 도움말 보기

Usage:
  sysbench [options]... [testname] [command]

Commands implemented by most tests: prepare run cleanup 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]
  --warmup-time=N                 execute events for this many seconds with statistics disabled before the actual benchmark run with statistics enabled [0]
  --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]
  --thread-init-timeout=N         wait time in seconds for worker threads to initialize [30]
  --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
  --luajit-cmd=STRING             perform LuaJIT control command. This option is equivalent to 'luajit -j'. See LuaJIT documentation for more information

Pseudo-Random Numbers Generator options:
1.1 이상.
  --rand-type=STRING   random numbers distribution {uniform, gaussian, pareto, zipfian} to use by default [uniform]
  --rand-seed=N        seed for random number generator. When 0, the current time is used as an RNG seed. [0]
  --rand-pareto-h=N    shape parameter for the Pareto distribution [0.2]
  --rand-zipfian-exp=N shape parameter (exponent, theta) for the Zipfian distribution [0.8]

1.1 이하
  --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-key=STRING           path name of the client private key file
  --mysql-ssl-ca=STRING            path name of the CA file
  --mysql-ssl-cert=STRING          path name of the client public key certificate file
  --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

See 'sysbench <testname> help' for a list of options for each test.

여러가지 옵션들이 나옵니다. 위의 옵션들에 대해 알아보겠습니다.

 

 

 

 실제 실행 명령어

Commands implemented by most tests: prepare run cleanup help
prepare : 테스트 준비(데이터 베이스 벤치마크 수행시 테스트 데이터 준비)
run : 실제 테스트 수행.
cleanup : 테스트 데이터 삭제
help : 도움말 보기

• General options:벤치마크를 수행할 일반적인 옵션들을 나타낸다. 옵션들을 조합해서 부하 테스트를 한다.

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

SysBench 생성 동시성 종류를 정의 있습니다. MySQL 모든 소프트웨어와 마찬가지로 일부 확장 제한이 있으며 성능은 일정 수준의 동시성에서 정점에 도달합니다. 설정은 주어진 워크로드에 대해 서로 다른 동시성을 시뮬레이트하고 이미 스위트 스팟을 통과했는지 확인하는 도움이됩니다.

 

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

요청 수에 대한 제한. 0(기본값) 제한이 없음을 의미

 

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

실행 시간 제한(). 0 제한이 없음을 의미

설정은 SysBench 계속 실행되는 시간을 제어합니다. 개의 쿼리를 실행하거나 미리 정의 시간 동안 계속 실행할 있습니다.

 

--warmup-time=N                 execute events for this many seconds with statistics disabled before the actual benchmark run with statistics enabled [0]

벤치마킹을 실행 초기 시간을 통계에서 빼기 원할때 유용, 구동된 시스템을 벤치 마크할때 CPU / 데이터베이스 / 페이지 기타 캐시가 초기값에 가까울때 캐시를 채우고, 사용율을 예열 하는데 사용

SysBench 테스트에서 통계 결과를 생성하며 MySQL 콜드 상태 경우 해당 결과에 영향을 있습니다. 예열은 미리 정의 시간 동안 벤치 마크를 실행하여 캐시, 버퍼 등을 예열 수있게하여 "일반적인"처리량을 식별하는 도움이됩니다.

 

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

강제 종료 전에 --time 옵션 제한시간 이후 대기하는 시간 ()

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

쓰레드의 스택 크기

  --thread-init-timeout=N         wait time in seconds for worker threads to initialize [30]

작업자 스레드가 초기화 때까지의 대기 시간 ()

 

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

모든 스레드가 평균적으로 초당 수행해야하는 이벤트 (트랜잭션) 수를 지정합니다. 0 (기본값) 무제한 비율을 의미

 

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

기본적으로 SysBench 실행이 완료된 보고서를 생성하며 벤치 마크가 실행되는 동안 진행률이보고되지 않습니다. 옵션을 사용하면 벤치 마크가 계속 실행되는 동안 SysBench 자세하게 만들 있습니다. 지정해놓은 초마다 리포트를 보여줍니다. -report-interval=10 -> 10초마다 리포트 생성.

 

• Pseudo-Random Numbers Generator options: 의사 난수 생성기 옵션

  --rand-type=STRING   random numbers distribution {uniform, gaussian, pareto, zipfian} to use by default [uniform]

실제 데이터 생성에 있어서 패턴을 만들어 내는 방법. 기본값은 special

자세한 내용은 다음 URL 참고 : https://www.percona.com/blog/2020/03/26/sysbench-and-the-random-distribution-effect/

SysBench 사용하면 다양한 유형의 데이터 배포를 생성 있습니다. 그들 모두는 자신의 목적을 가질 있습니다. 기본 옵션 특별 데이터에서 가지 (구성 가능) 핫스팟을 정의하며 이는 애플리케이션에서 매우 일반적입니다. 데이터가 다른 방식으로 동작하는 경우 다른 분포를 사용할 수도 있습니다. 여기서 다른 선택을함으로써 데이터베이스에 스트레스를받는 방식을 변경할 수도 있습니다. 예를 들어, 모든 행이 액세스 가능성이 동일한 균일 분포는 훨씬 많은 메모리를 사용하는 작업입니다. 많은 버퍼 풀을 사용하여 모든 데이터를 저장하며 데이터 세트가 메모리에 맞지 않으면 디스크를 훨씬 많이 사용하게됩니다. 반면에, 스폿이 개인 특수 분배는 행이 버퍼 풀에 보관 가능성이 높고 디스크에 저장된 행에 대한 액세스가 훨씬 적기 때문에 디스크에 대한 스트레스를 줄입니다. 일부 데이터 배포 유형의 경우 SysBench 많은 조정을 제공합니다. 정보는 'sysbench --help'출력에서 찾을 있습니다.

uniform : 이름에서 있듯이 Uniform 사용하면 모든 값이 ID 사용되며 분포는… Uniform입니다.

gaussian : 가우시안 분포 (또는 정규 분포) 알려져 있고 친숙하며 (https://en.wikipedia.org/wiki/Normal_distribution 참조) 주로 중심 요인에 대한 통계 예측에 사용됩니다. 경우 사용 ID 중간 값에서 시작하여 커브로 분산되고 가장자리쪽으로 천천히 감소합니다.

special : 기본값은 Special이므로 사용할 임의 유형을 지정하지 않으면 sysbench special 사용합니다. 특별한 것은 쿼리 작업에 매우 제한된 수의 ID 사용하는 것입니다. 여기서 우리는 주로 ID 50-51 사용하고 매우 산발적으로 44-56 사이의 세트를 사용하고 다른 것들은 실제로 관련이 없다고 말할 있습니다. 선택한 값은 사용 가능한 세트 1-100 중간 범위에 있습니다.

경우 스파이크는 샘플의 2 % 나타내는 개의 ID 집중됩니다. 레코드 수를 백만으로 늘리더라도 여전히 스파이크가 존재하며 샘플의 0.74 % 7493 중점을 둡니다. 제한적이기 때문에 페이지 수는 아마 이상일 것입니다.

pareto : 80-20 규칙 (https://en.wikipedia.org/wiki/Pareto_distribution 참조) 적용하는 Pareto 사용하면 사용할 ID 훨씬 적게 분산되고 소규모 세그먼트에 집중됩니다. 사용 모든 ID 52 % 숫자 1 사용하는 반면, 사용 ID 73 % 처음 10 개의 숫자에있었습니다.

zipfian : Zipta 분포 (제타 분포라고도 ) 언어, 보험 희귀 사건 모델링에 일반적으로 사용되는 불연속 분포입니다. 경우, sysbench 낮은 (1)부터 시작하여 수를 향해 이동하면서 주파수를 매우 빠르게 줄입니다.

  --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 an RNG seed. [0]

난수 생성기의 시드. 0이면 현재 시간이 RNG 시드로 사용됩니다.

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

파레토 분포의 형상 모수

  --rand-zipfian-exp=N shape parameter (exponent, theta) for the Zipfian distribution [0.8]

Zipfian 분포에 대한 형상 모수 (지수, 세타)

 

• 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]

대기 시간 통계 (1-100) 계산하기위한 백분위 . 백분위 계산을 비활성화하려면 특수 0 사용합니다.sysbench는 처리 된 모든 요청의 실행 시간을 측정하여 최소, 평균 및 최대 실행 시간과 같은 통계 정보를 표시. 대부분의 벤치 마크에서 일부 백분위 수와 일치하는 요청 실행 시간 값을 아는 것이 유용합니다. (예 : 95 % 백분위 수는 가장 긴 요청의 5 %를 삭제하고 나머지 요청에서 최대 값을 선택해야 함을 의미 함). 이 옵션을 사용하면 백분위 수의 쿼리 실행 시간을 계산할 수 있습니다.

  --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]

데이터베이스 드라이버. 기본값은 mysql

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

설정을 사용하면 SysBench 준비된 명령문을 사용해야하는지 (주어진 데이터 저장소에서 사용할 수있는 -MySQL 경우 기본적으로 PS 활성화됨을 의미) 여부를 결정할 있습니다. ProxySQL 또는 MaxScale 같은 프록시로 작업하는 동안 차이가 생길 있습니다. 이들은 준비된 명령문을 특별한 방식으로 처리해야하며 모든 호스트를 하나의 호스트로 라우팅하여 프록시의 확장 성을 테스트 없도록해야합니다.

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

데이터베이스에 대한 디버그 정보를 보여줍니다.

 

Compiled-in database drivers: 컴파일된 데이터베이스 드라이버

  mysql - MySQL driver

 

• mysql options : mysql 접속 옵션들.

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

MySQL 서버 호스트. 아이피나 도메인입력.

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

MySQL Port 번호

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

MySQL 소켓파일 위치

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

MySQL 접속 유저.

--mysql-password=STRING          MySQL password []

MySQL 접속 암호.

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

MySQL 데이터베이스 이름.

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

MySQL SSL 사용여부

--mysql-ssl-key=STRING           path name of the client private key file

MySQL 개인키 파일

--mysql-ssl-ca=STRING            path name of the CA file

MySQL SSL CA인증서 파일

--mysql-ssl-cert=STRING          path name of the client public key certificate file

MySQL SSL 공개피 파일.

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

MySQL SSL cipher사용여부

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

MySQL 압축 사용여부.

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

MySQL 디버그 모드 사용여부

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

MySQL 에러무시 번호. 특정 에러가 발생하면 무시한다.

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

드라이런. MySQL API Call 접속을 테스트해본다.

 

 

 

• Compiled-in tests: 수행 가능한 테스트.

fileio - File I/O test : file io 성능 테스트.

cpu - CPU performance test : CPU 성능 테스트.

memory - Memory functions speed test : 메모리 성능 테스트

threads - Threads subsystem performance test : 스레드 서브 시스템 성능 테스트.

mutex - Mutex performance test : 뮤텍스 성능 테스트

 

 참고

어떤 버전부터인지는 모르겠지만 1.0.19 버전 상위부터는 테스트명을 붙이지 않는다.

보통 sysbench --test=테스트명, 위에 나온 cpu, memory, fileio등으로 입력했는데 이젠 --test 붙이지 않고 바로 테스트명으로 시작한다. 그리고 테스트에 붙여지는 옵션들도 약간씩 틀려졌다. 기존방식으로 테스트할 경우 경고(Warning) 떨어진다. 그러나 수행은 된다.

기존방식 : shell> sysbench --test=cpu --cpu-max-prime=20000  --num-threads=2 run

새로운 방식 : shell> sysbench cpu --threads=2 --cpu-max-prime=20000 run

 

테스트 방법

▶︎ CPU 테스트 

shell> sysbench cpu help

sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

 

• cpu options:

--cpu-max-prime=N upper limit for primes generator [10000]

소숫점 계산값.  지정된 값까지 소수 계산. 보통 20000으로 설정함.

 

• General options : 일반옵션을 몇개 조합해서 테스트 가능.

--threads : 스레드 갯수 지정. CPU 코어수만큼 설정. 코어에 하이퍼 스레딩이 이루어진다면 X2 계산.

 

실행방법 :

shell> sysbench cpu --threads=2 --cpu-max-prime=20000 run

 

▶︎ Memory test

shell> sysbench memory help

sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

 

memory options:

--memory-block-size=SIZE    size of memory block for test [1K]

--memory-total-size=SIZE    total size of data to transfer [100G]

--memory-scope=STRING       memory access scope {global,local} [global]

--memory-hugetlb[=on|off]   allocate memory from HugeTLB pool [off]

--memory-oper=STRING        type of memory operations {read, write, none} [write]

--memory-access-mode=STRING memory access mode {seq,rnd} [seq]

 

특정 옵션을 지정하지 않으면 맨뒤에 []표시 안에 들어간 값이 자동적으로 할당됩니다.

 

• General options : 일반옵션을 몇개 조합해서 테스트 가능.

--threads : 스레드 갯수 지정. CPU 코어수만큼 설정. 코어에 하이퍼 스레딩이 이루어진다면 X2 계산.

 

실행방법

shell> sysbench memory --threads=4 --memory-block-size=64K --memory-scope=global --memory-total-size=4G --memory-oper=read run
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:
Number of threads: 4
Initializing random number generator from current time



Running memory speed test with the following options:
  block size: 64KiB
  total size: 4096MiB
  operation: read
  scope: global


Initializing worker threads...

Threads started!

Total operations: 65536 (587388.01 per second)

4096.00 MiB transferred (36711.75 MiB/sec)


General statistics:
    total time:                          0.1099s
    total number of events:              65536

Latency (ms):
         min:                                    0.00
         avg:                                    0.00
         max:                                   21.08
         95th percentile:                        0.00
         sum:                                  319.24

Threads fairness:
    events (avg/stddev):           16384.0000/0.00
    execution time (avg/stddev):   0.0798/0.02

 

 

▶︎ fileio 테스트

shell> sysbench fileio help  

sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

 

fileio options:

  --file-num=N                  number of files to create [128]

  --file-block-size=N           block size to use in all IO operations [16384]

  --file-total-size=SIZE        total size of files to create [2G]

  --file-test-mode=STRING       test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}

  --file-io-mode=STRING         file operations mode {sync,async,mmap} [sync]

  --file-async-backlog=N        number of asynchronous operatons to queue per thread [128]

  --file-extra-flags=[LIST,...] list of additional flags to use to open files {sync,dsync,direct} []

  --file-fsync-freq=N           do fsync() after this number of requests (0 - don't use fsync()) [100]

  --file-fsync-all[=on|off]     do fsync() after each write operation [off]

  --file-fsync-end[=on|off]     do fsync() at the end of test [on]

  --file-fsync-mode=STRING      which method to use for synchronization {fsync, fdatasync} [fsync]

  --file-merged-requests=N      merge at most this number of IO requests if possible (0 - don't merge) [0]

  --file-rw-ratio=N             reads/writes ratio for combined test [1.5]

 

file-test-mode종류

- seqwr

    sequential write(순차적 쓰기)

- seqrewr

    sequential rewrite(순차적 재쓰기)

- seqrd

    sequential read (순차적 읽기)

- rndrd

    random read (무작위 읽기)

- rndwr

    random write (무작위 쓰기)

- rndrw

    combined random read/write (동시 무작위 일기/쓰기)

 

• General options : 일반옵션을 몇개 조합해서 테스트 가능.

--threads : 스레드 갯수 지정. CPU 코어수만큼 설정. 코어에 하이퍼 스레딩이 이루어진다면 X2 계산.

 

실행방법

shell> sysbench fileio --threads=16 --file-total-size=2G --file-test-mode=rndrw prepare
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)


128 files, 16384Kb each, 2048Mb total
Creating files for the test...
Extra file open flags: (none)
Creating file test_file.0
Creating file test_file.1
Creating file test_file.2
Creating file test_file.3
Creating file test_file.4
Creating file test_file.5
....
....
Creating file test_file.125
Creating file test_file.126
Creating file test_file.127
2147483648 bytes written in 4.46 seconds (459.32 MiB/sec).

shell> sysbench fileio --threads=16 --file-total-size=2G --file-test-mode=rndrw run
WARNING: --num-threads is deprecated, use --threads instead
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:
Number of threads: 16
Initializing random number generator from current time



Extra file open flags: (none)
128 files, 16MiB each
2GiB total file size
Block size 16KiB
Number of IO requests: 0
Read/Write ratio for combined random IO test: 1.50
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Initializing worker threads...

Threads started!



File operations:
    reads/s:                      19356.40
    writes/s:                     12904.27
    fsyncs/s:                     41486.65

Throughput:
    read, MiB/s:                  302.44
    written, MiB/s:               201.63

General statistics:
    total time:                          10.0198s
    total number of events:              737010

Latency (ms):
         min:                                    0.00
         avg:                                    0.22
         max:                                   15.92
         95th percentile:                        1.04
         sum:                               159361.67

Threads fairness:
    events (avg/stddev):           46063.1250/732.90
    execution time (avg/stddev):   9.9601/0.00

shell> sysbench fileio --threads=16 --file-total-size=2G --file-test-mode=rndrw cleanup
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

Removing test files...

 

▶︎ thread test

shell> sysbench threads help

sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

 

threads options:

--thread-yields=N number of yields to do per request [1000]

--thread-locks=N  number of locks per thread [8]

 

• General options : 일반옵션을 몇개 조합해서 테스트 가능.

--threads : 스레드 갯수 지정. CPU 코어수만큼 설정. 코어에 하이퍼 스레딩이 이루어진다면 X2 계산.

 

실행방법

shell> sysbench threads --threads=16 --thread-yields=1000 --thread-locks=8 run
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:
Number of threads: 16
Initializing random number generator from current time



Initializing worker threads...

Threads started!



General statistics:
    total time:                          10.0096s
    total number of events:              13627

Latency (ms):
         min:                                    0.52
         avg:                                   11.75
         max:                                  247.69
         95th percentile:                       41.85
         sum:                               160066.52

Threads fairness:
    events (avg/stddev):           851.6875/25.86
    execution time (avg/stddev):   10.0042/0.00

 

▶︎ mutex test

shell> sysbench mutex help

sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

 

mutex options:

  --mutex-num=N   total size of mutex array [4096]

  --mutex-locks=N number of mutex locks to do per thread [50000]

  --mutex-loops=N number of empty loops to do outside mutex lock [10000]

 

• General options : 일반옵션을 몇개 조합해서 테스트 가능.

--threads : 스레드 갯수 지정. CPU 코어수만큼 설정. 코어에 하이퍼 스레딩이 이루어진다면 X2 계산.

 

실행방법

shell> sysbench mutex --threads=100 --mutex-num=4096 \
--mutex-locks=5000 --mutex-loops=10000 run
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:
Number of threads: 100
Initializing random number generator from current time



Initializing worker threads...

Threads started!



General statistics:
    total time:                          0.8336s
    total number of events:              100

Latency (ms):
         min:                                   15.79
         avg:                                   72.35
         max:                                  190.95
         95th percentile:                      167.44
         sum:                                 7235.01

Threads fairness:
    events (avg/stddev):           1.0000/0.00
    execution time (avg/stddev):   0.0724/0.05

 

 

 

▶︎ Database OLTP 테스트

/usr/local/share/sysbench 디렉토리 이동후 파일을 확인해보면 테스트 가능한 파일들이 나옵니다. lua라는 확장자를 가지는 테스트 스크립트인데 파일 이름을 보면 어떤 테스트 용인지 유추해 있습니다. oltp, bulk insert, select등의 테스트를 해볼 있습니다.

 

테스트 lua스크립트 종류

oltp_delete.lua

oltp_point_select.lua

oltp_read_write.lua

oltp_update_non_index.lua

oltp_common.lua

oltp_insert.lua

oltp_read_only.lua

oltp_update_index.lua

oltp_write_only.lua

select_random_ranges.lua

select_random_points.lua

bulk_insert.lua

 

도움말 확인.

스크립트 파일별로 도움말이 조금씩 다르다. 대부분의 내용은 비슷하지만 세세한 내용은 틀리니 반드시 확인하여야 합니다.

ex) sysbench <lua script> help

shell> /usr/local/sysbench/bin/sysbench /usr/local/sysbench/share/sysbench/oltp_read_write.lua help
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

oltp_read_only.lua options:
  --auto_inc[=on|off]           Use AUTO_INCREMENT column as Primary Key (for MySQL), or its alternatives in other DBMS. When disabled, use client-generated IDs [on]
  --create_secondary[=on|off]   Create a secondary index in addition to the PRIMARY KEY [on]
  --delete_inserts=N            Number of DELETE/INSERT combinations per transaction [1]
  --distinct_ranges=N           Number of SELECT DISTINCT queries per transaction [1]
  --index_updates=N             Number of UPDATE index queries per transaction [1]
  --mysql_storage_engine=STRING Storage engine, if MySQL is used [innodb]
  --non_index_updates=N         Number of UPDATE non-index queries per transaction [1]
  --order_ranges=N              Number of SELECT ORDER BY queries per transaction [1]
  --pgsql_variant=STRING        Use this PostgreSQL variant when running with the PostgreSQL driver. The only currently supported variant is 'redshift'. When enabled, create_secondary is automatically disabled, and delete_inserts is set to 0
  --point_selects=N             Number of point SELECT queries per transaction [10]
  --range_selects[=on|off]      Enable/disable all range SELECT queries [on]
  --range_size=N                Range size for range SELECT queries [100]
  --secondary[=on|off]          Use a secondary index in place of the PRIMARY KEY [off]
  --simple_ranges=N             Number of simple range SELECT queries per transaction [1]
  --skip_trx[=on|off]           Don't start explicit transactions and execute all queries in the AUTOCOMMIT mode [off]
  --sum_ranges=N                Number of SELECT SUM() queries per transaction [1]
  --table_size=N                Number of rows per table [10000]
  --tables=N                    Number of tables [1]

 

추가 옵션(테스트시 중요한 옵션임)

--rand-type : 실제 데이터 생성에 있어서 패턴을 만들어 내는 방법. 기본값은 special

자세한 내용은 위에 참고

 

* 테스트 준비작업

shell> /usr/local/sysbench/bin/sysbench \
/usr/local/sysbench/share/sysbench/oltp_read_write.lua \
--mysql-host='localhost' --mysql-port=3306 \
--mysql-user=root --mysql-password='admin1234' \
--mysql-db=sbtest --db-driver=mysql --tables=10 \
--table-size=100000 prepare

주요 옵션 설명 :
--tables=10
테이블 10개 생성
--table-size=100000
테이블 Row 100000개 생성(그러나 100000Row가 생기진 않습니다. 대부분 부족하게 생성됩니다.)

출력 내용 :
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

Initializing worker threads...

Creating table 'sbtest1'...
Creating table 'sbtest9'...
Creating table 'sbtest3'...
Creating table 'sbtest4'...
Creating table 'sbtest10'...
Creating table 'sbtest6'...
Creating table 'sbtest8'...
Creating table 'sbtest2'...
Creating table 'sbtest5'...
Inserting 100000 records into 'sbtest10'
Creating table 'sbtest7'...
Inserting 100000 records into 'sbtest9'
Inserting 100000 records into 'sbtest1'
Inserting 100000 records into 'sbtest2'
Inserting 100000 records into 'sbtest8'
Inserting 100000 records into 'sbtest3'
Inserting 100000 records into 'sbtest4'
Inserting 100000 records into 'sbtest6'
Inserting 100000 records into 'sbtest5'
Inserting 100000 records into 'sbtest7'
Creating a secondary index on 'sbtest1'...
Creating a secondary index on 'sbtest8'...
Creating a secondary index on 'sbtest4'...
Creating a secondary index on 'sbtest10'...
Creating a secondary index on 'sbtest2'...
Creating a secondary index on 'sbtest7'...
Creating a secondary index on 'sbtest9'...
Creating a secondary index on 'sbtest6'...
Creating a secondary index on 'sbtest3'...
Creating a secondary index on 'sbtest5'...

 

* 실 테스트

shell> /usr/local/sysbench/bin/sysbench \
/usr/local/sysbench/share/sysbench/oltp_read_write.lua \
--mysql-host='localhost' --mysql-port=3306 --mysql-user=root \
--mysql-password='admin1234' --mysql-db=sbtest \
--db-driver=mysql --tables=10 --table-size=100000 \
--delete_inserts=10 --index_updates=10 \
--non_index_updates=10 --report-interval=10 --threads=30 --time=60 run

주요 옵션 설명 :
--tables=10
--table-size=100000
위에서 준비 작업에서 사용했던 옵션을 그대로 사용합니다.

--delete_inserts=10 --index_updates=10 --non_index_updates=10
트랜잭션당 사용할 쿼리의 수 입니다. help 옵션을 확인해보면 상세히 설명되어 있습니다.

--threads=30
동시접속 클라이언트 수입니다.

sysbench 1.1.0 (using bundled LuaJIT 2.1.0-beta3)

Running the test with following options:
Number of threads: 128
Report intermediate results every 10 second(s)
Initializing random number generator from current time


Initializing worker threads...

Threads started!

[ 10s ] thds: 128 tps: 122.17 qps: 7034.25 (r/w/o: 1822.85/4954.27/257.14) lat (ms,95%): 1903.57 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 128 tps: 120.80 qps: 6928.62 (r/w/o: 1736.96/4950.07/241.59) lat (ms,95%): 1739.68 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 128 tps: 125.31 qps: 6996.30 (r/w/o: 1752.78/4992.90/250.63) lat (ms,95%): 2045.74 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 128 tps: 135.30 qps: 7495.04 (r/w/o: 1866.31/5358.13/270.60) lat (ms,95%): 1803.47 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 128 tps: 127.90 qps: 7160.72 (r/w/o: 1803.38/5101.54/255.80) lat (ms,95%): 1903.57 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 128 tps: 126.60 qps: 7157.73 (r/w/o: 1785.48/5119.05/253.20) lat (ms,95%): 1803.47 err/s: 0.00 reconn/s: 0.00
SQL statistics:
    queries performed:
        read:                            107926
        write:                           308360
        other:                           15418
        total:                           431704
    transactions:                        7709   (127.10 per sec.)
    queries:                             431704 (7117.42 per sec.)
    ignored errors:                      0      (0.00 per sec.)
    reconnects:                          0      (0.00 per sec.)

Throughput:
    events/s (eps):                      127.0968
    time elapsed:                        60.6546s
    total number of events:              7709

Latency (ms):
         min:                                   35.45
         avg:                                 1002.10
         max:                                 3609.88
         95th percentile:                     1869.60
         sum:                              7725213.37

Threads fairness:
    events (avg/stddev):           60.2266/4.39
    execution time (avg/stddev):   60.3532/0.17

 

참조사이트 : 

https://www.percona.com/blog/2020/03/26/sysbench-and-the-random-distribution-effect/

https://minervadb.com/index.php/2018/03/13/benchmarking-mysql-using-sysbench-1-1/

https://rastalion.me/sysbench%EB%A5%BC-%EC%9D%B4%EC%9A%A9%ED%95%9C-mariadb-%EB%B2%A4%EC%B9%98%EB%A7%88%ED%81%AC/

https://severalnines.com/database-blog/how-benchmark-performance-mysql-mariadb-using-sysbench

 

 

도움이 되셨다면 광고클릭 한번 부탁드립니다.※

Designed by JB FACTORY