카테고리 없음

부하테스트

자바바라 2024. 11. 1. 23:27

Kubernetes 환경에서 MariaDB Replica와 MaxScale의 부하테스트를 위한 쿼리와 방법은 다음과 같습니다:
sysbench를 사용한 OLTP 부하 테스트:

# sysbench 파드 생성
kubectl run sysbench --image=severalnines/sysbench --rm -it --restart=Never -- bash

# sysbench 파드 내에서 실행
sysbench oltp_read_write \
  --table-size=1000000 \
  --db-driver=mysql \
  --mysql-db=test \
  --mysql-user=your_user \
  --mysql-password=your_password \
  --mysql-host=maxscale-service \
  --threads=16 \
  --time=300 \
  run

 

2. 간단한 select query 부하 테스트:

# MySQL 클라이언트 파드 생성
kubectl run mysql-client --image=mysql:5.7 --rm -it --restart=Never -- bash

# MySQL 클라이언트 파드 내에서 실행
for i in {1..1000}; do
  mysql -h maxscale-service -uroot -p -e "SELECT * FROM your_table LIMIT 1000;"
done

 

3. 읽기/쓰기 분리 테스트:

# 읽기 쿼리
mysql -h maxscale-service -P 3310 -u read_user -pread_password -e "SELECT * FROM your_table LIMIT 1;"
mysql -h maxscale-service -P 3310 -u read_user -pread_password -e "SELECT * FROM your_table WHERE id = FLOOR(RAND() * 1000000);"

# 쓰기 쿼리
mysql -h maxscale-service -P 3309 -u write_user -pwrite_password -e "INSERT INTO your_table (column1, column2) VALUES ('test', 'value');"
mysql -h maxscale-service -P 3309 -u write_user -pwrite_password -e "INSERT INTO your_table (column1, column2, column3) VALUES (FLOOR(RAND() * 1000000), UUID(), NOW());"

# 업데이트 쿼리
mysql -h maxscale-service -P 3309 -u write_user -pwrite_password -e "UPDATE your_table SET column2 = UUID() WHERE id = FLOOR(RAND() * 1000000);"

# 복잡한 조인 쿼리
mysql -h maxscale-service -P 3309 -u write_user -pwrite_password -e "
SELECT t1.*, t2.* 
FROM table1 t1 
JOIN table2 t2 ON t1.id = t2.id 
WHERE t1.column1 > RAND() * 1000 
LIMIT 100;
"

# 집계 함수를 사용한 쿼리
mysql -h maxscale-service -P 3309 -u write_user -pwrite_password -e "
SELECT COUNT(*), AVG(numeric_column), MAX(numeric_column) 
FROM your_table 
GROUP BY category_column;
"

# 서브쿼리를 포함한 쿼리
mysql -h maxscale-service -P 3309 -u write_user -pwrite_password -e "
SELECT * 
FROM table1 
WHERE id IN (
    SELECT table2.id 
    FROM table2 
    JOIN table3 ON table2.id = table3.id 
    WHERE table3.value > 1000
);"


-- 대량 INSERT 테스트
INSERT INTO test_table (col1, col2, col3) VALUES (RAND()*1000, UUID(), NOW());

-- 복잡한 SELECT 쿼리 테스트
SELECT t1.*, t2.* FROM test_table t1 
JOIN another_table t2 ON t1.id = t2.id 
WHERE t1.col1 > 500 AND t2.col2 LIKE 'test%' 
ORDER BY t1.col3 DESC LIMIT 1000;

-- UPDATE 테스트
UPDATE test_table SET col1 = col1 + 1 WHERE id % 2 = 0;

-- DELETE 테스트
DELETE FROM test_table WHERE col1 < 100 LIMIT 1000;

 

4. 트랜잭션 처리 테스트:

mysql -h maxscale-service -u your_user -pyour_password << EOF
START TRANSACTION;
INSERT INTO your_table (column1, column2) VALUES ('test1', 'value1');
INSERT INTO your_table (column1, column2) VALUES ('test2', 'value2');
COMMIT;
EOF

 

5. 연결 풀링 테스트:

for i in {1..100}; do
  mysql -h maxscale-service -u your_user -pyour_password -e "SELECT 1;" &
done

 

테스트 결과 모니터링분석은 grafana 도구 사용

 

6. Maxscale의 readwritesplit 기능을 최적화하여 부하테스트를 수행하는 방법

  • 적절한 파라미터 설정:
    - max_slave_connections: 동시에 사용할 수 있는 최대 replica 연결 수 설정.
MaxScale 구성 파일(maxscale.cnf)에서 Read-Service 섹션에 다음과 같이 설정

[Read-Service]
type=service
router=readconnroute
router_options=slave
servers=replicaDB1, replicaDB2, replicaDB3
user=read
password=your_password
max_slave_connections=100  #동시 사용할 수 있는 최대 slave연결 수


- max_replication_lag: replica의 최대 허용 지연 시간 설정
- transaction_replay: 트랜잭션 재실행 기능을 활성화하여 일관성 보장

  • 서비스 구성 최적화:
services:
  - name: rw-router
    router: readwritesplit
    params:
      transaction_replay: "true"
      transaction_replay_attempts: "10"
      transaction_replay_timeout: "5s"
      max_slave_connections: "255"
      max_replication_lag: "3s"
      master_accept_reads: "true"
  • 모니터링 간격 조정:
모니터링 간격을 조정하여 slave 상태를 더 빠르게 감지

[MariaDB-Monitor]
type=monitor
module=mariadbmon
servers=masterDB, replicaDB1, replicaDB2, replicaDB3
monitor_interval=1s
  • 읽기/쓰기 분리 테스트:
    - 읽기 전용 쿼리는 replica로 라우팅되는지 확인
    - 쓰기 쿼리는 primary로 라우팅되는지 확인
  • 트랜잭션 처리 테스트:
    - 트랜잭션 내의 모든 퀄리가 동일한 서버로 라우팅되는지 확인
  • 부하 분산 확인:
    - 여러 replica 간에 읽기 쿼리가 균등하게 분산되는지 모니터링
  • 장애 조치 시나리오 테스트:
    - primary 노드 장애 시 자동 장애 조치 및 복구 과정 확인
  • 연결 풀링 최적화:
    - max_connections 및 connection_timeout 파리미터 조정
slave 서버에 대해 persistpoolmax 및 persistmaxtime 파라미터를 설정하여 연결 풀링을 최적화

[replicaDB1]
type=server
address=192.168.30.141
port=3306
protocol=MariaDBBackend
persistpoolmax=100
persistmaxtime=3600s
  • 쿼리 캐싱 고려:
    - 반복적인 일기 쿼리에 대해 쿼리 캐시 활성화 검토
  • 로깅 및 모니터링:
    - MaxScale 로그를 분석하여 쿼리 라우팅 패턴 및 성능 병목 지점 식별