CS/DBMS

[PostgreSQL] pgbench 벤치마크 툴 사용방법, 성능 분석

뭉치v 2024. 7. 10.
반응형

pgbench : postgresql 벤치마크 툴

postgresql 설치 시 기본적으로 제공되는 벤치마크 툴로 간단하게 테스트하기 좋다.

간단한 커맨드를 통해 초기 테스트데이터 셋팅과 테스트를 진행해 TPS를 뽑아 볼 수 있다.

문서 : https://www.postgresql.org/docs/current/pgbench.html

 

pgbench

pgbench pgbench — run a benchmark test on PostgreSQL Synopsis pgbench -i [option...] [dbname] pgbench [option...] [dbname] Description pgbench is …

www.postgresql.org

 

pgbench 성능분석

테스트 데이터 생성

  1. 테스트용 Database 생성
  2. pgbench로 테스트 데이터 생성 `$ pgbench -i [database_name]`
# 테스트용 DB 생성
postgres# create database pgbench owner postgres;

# 10만 row 데이터 생성(default 10만)
[postgres@test01 ~]$ pgbench -i pgbench
dropping old tables...
NOTICE:  table "pgbench_accounts" does not exist, skipping
NOTICE:  table "pgbench_branches" does not exist, skipping
NOTICE:  table "pgbench_history" does not exist, skipping
NOTICE:  table "pgbench_tellers" does not exist, skipping
creating tables...
generating data (client-side)...
100000 of 100000 tuples (100%) done (elapsed 0.01 s, remaining 0.00 s)
vacuuming...
creating primary keys...
done in 0.21 s (drop tables 0.00 s, create tables 0.00 s, client-side generate 0.13 s, vacuum 0.04 s, primary keys 0.04 s).
table                   # of rows
---------------------------------
pgbench_branches        1
pgbench_tellers         10
pgbench_accounts        100000
pgbench_history         0

 

`$ pgbench -i pgbench` default로 생성하면 10만건의 데이터와 거기에 조인이 걸리는 테이블들 데이터들이 셋팅된다.

추가로, `$ pgbench -i -s 10 pgbench`  처럼 -s(scale) 값을 주면 초기데이터를 10만* 10배수로 설정 할 수 있다.

# 10만 * n row 데이터 생성
$ pgbench -i -s n pgbench

 

10만* 10개 데이터셋 생성하기

postgres=# drop database pgbench;

[postgres@test01 ~]$ pgbench -i -s 10 pgbench
dropping old tables...
NOTICE:  table "pgbench_accounts" does not exist, skipping
NOTICE:  table "pgbench_branches" does not exist, skipping
NOTICE:  table "pgbench_history" does not exist, skipping
NOTICE:  table "pgbench_tellers" does not exist, skipping
creating tables...
generating data (client-side)...
1000000 of 1000000 tuples (100%) done (elapsed 0.72 s, remaining 0.00 s)
vacuuming...
creating primary keys...
done in 1.42 s (drop tables 0.00 s, create tables 0.00 s, client-side generate 0.99 s, vacuum 0.12 s, primary keys 0.30 s).

pgbench=# \dt+                                         
List of relations
 Schema |       Name       | Type  |  Owner   | Persistence | Access method |  Size   | Description
--------+------------------+-------+----------+-------------+---------------+---------+-------------
 public | pgbench_accounts | table | postgres | permanent   | heap          | 128 MB  |
 public | pgbench_branches | table | postgres | permanent   | heap          | 40 kB   |
 public | pgbench_history  | table | postgres | permanent   | heap          | 0 bytes |
 public | pgbench_tellers  | table | postgres | permanent   | heap          | 40 kB   |
(4 rows)

 

 

벤치마크 테스트 진행하기

초기 데이터 셋팅을 끝냈으면 이제 벤치마크 테스트를 진행해보자.

주요 옵션들을 살펴보자.

    • -c : DB에 접속하는 가상의 client의 수를 설정
    • -j : -c에서 설정한 client를 몇 개의 thread에 걸쳐 동작시킬 것인지 설정.  (-c > -j 여야함), cpu thread 수로 설정
    • -t : 테스트 transaction의 수
    • -n : 테스트 시작 전 vacuum 미진행
    • -S : select-only transaction 만 수행
    • -p : port 지정
    • -C : 각 트랜잭션마다 새로운 커넥션을 열기
    • -T : 테스트를 얼마나 오래 지속할지 (초단위)
    • -t : 처리할 트랜잭션 수

ex) 32개의 Client 에서 10,000회의 Transaction이 있을 때를 가정(pgbench는 8쓰레드로 진행)

`$ pgbench -c 32 -j 8 -t 10000 pgbench`

 

ex) 32개의 Client 에서 10분 동안 처리하는 Transaction 측정(pgbench는 8쓰레드로 진행)

`$ pgbench -c 32 -j 8 -T 600 pgbench`

 

공식문서에 나와있는 팁

  1. -t, -T 옵션을 이용해 최소 수분 이상 수행 되도록해서 평균 노이즈값을 얻어라.
  2. 초기 테스트 데이터를 만들때 -s(scale) 로 설정한 배수는 테스트 시 동시 커넥션 수인 -c 값과 비슷해야한다.
    • `pgbench_branches` 테이블 -s 값 만큼 레코드가 생성되는데, -c에 지정된 커넥션들이 동시에 DML하기 때문에 lock 이슈로 테스트가 부정확 할 수 있다.
  3. -c에 높은 값으로 클라이언트 세션을 테스트 할때 pgbench 자체로 OS단에서 병목이 걸릴 수 있다. 네트워크 지연시간이 적은 다른 서버에서 원격 접속으로 테스트하면 완화 된다.

 

맺음말

 다른 환경끼리 테스트 할때 공식문서 1번처럼 충분히 오랜 시간 벤치마크를 진행해 적절한 평균 값을 얻는게 중요해보입니다.(-T 로 시간 베이스 측정 등) 또 여기서 언급한 옵션 말고도 여러 옵션들이 있으니 공식문서를 한번 살펴 보고 테스트를 진행하면 좋을 것 같습니다.

 

 

반응형

댓글

💲 추천 글