pgbench 란
PostgreSQL이 기본적으로 제공하는 Benchmark Tool, 일정 패턴의 SQL 구문들을 반복 수행하여
이를 통해 얻어지는 초 당 Transaction 횟수로 성능을 평가합니다.
- 스크립트 파일 수정을 통해 트랜잭션의 커스터마이징이 가능합니다.
- 테스트 환경
- OS : CentOS Linux 7.9
- Memory : 2.4G
- CPU : 2 Core
- PostgreSQL Versioin : 14.5
- postgres.conf : 기본값
② 생성한 데이터베이스의 table 및 row 수 설정 후 생성
[postgres@localhost bin]$ pgbench -U [User Name] -i -s 10 [DB Name];
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 1.08 s, remaining 0.00 s)
vacuuming...
creating primary keys...
done in 1.84 s (drop tables 0.00 s, create tables 0.02 s, client-side generate 1.17 s, vacuum 0.34 s, primary keys 0.31 s).
- -i = create table option
- -s [N] = N의 배수만큼 tuple 생성 ( 기본 100,000 개 )
- 약 100만 row Data 를 가지고 있는 128MB 크기에 대한 테이블을 대상으로 테스트 진행함.
max_connections = 50
shared_buffers = 1024MB
wal_buffers = 32MB
maintenance_work_mem = 256MB
⑤ option(pgbench --help)를 통한 파라미터 설정 전/후 성능 개선 test
[postgres@localhost data]$ pgbench -c 32 -j 8 -t 5000 [DB Name] ( 설정 전 )
pgbench (14.5)
starting vacuum...end.
transaction type: <builtin: TPC-B (sort of)>
scaling factor: 10
query mode: simple .
number of clients: 32 .
number of threads: 8 .
number of transactions per client: 5000
number of transactions actually processed: 160000/160000
latency average = 19.950 ms
initial connection time = 42.443 ms
tps = 1603.977238 (without initial connection time)
initial connection time = 36.732 ms
tps = 2246.693142 (without initial ...)
- -c = DB에 접속하는 가상 Client 수
- -j = 동작 시킬 가상 thread 수
- -t = 가상 transaction 수
성능 개선이 미미하지만, 실제 운영DB과 유사한 환경에서 test 진행 시 개선 폭이 클 것으로 예상
다른 option ( --foreign-key , --index-tablespace ... ) 을 사용해 실제 DB 환경과 유사하게 test 가능
기본 내장된 벤치마크 툴이기때문에 사용법이 간편하고 빠르게 test 가능
다만, DB와 연동하는 Application들 의 특성 등은 고려하지 않는 단점이 있습니다.
'PostgreSQL' 카테고리의 다른 글
[PostgreSQL] tablespace 란? 생성법과 개념 정리 (0) | 2023.03.21 |
---|---|
[Postgresql] general_series 함수를 이용한 더미데이터 생성 (0) | 2023.03.20 |
[PostgreSQL] 편리한 psql 명령어 정리 (0) | 2023.03.11 |
[PostgreSQL] kill -9 session(PID) 세션 죽이기 (0) | 2023.03.09 |
repmgr (0) | 2023.02.27 |