작업 단위의 복잡성:
측정 범위:
활용 목적:
일반적으로 하나의 트랜잭션은 여러 개의 요청으로 구성될 수 있기 때문에 TPS 값은 보통 RPS보다 낮은 경향이 있습니다.
-- 단일 테이블 조회
SELECT * FROM users WHERE user_id = 123;
BEGIN;
UPDATE products SET price = 29.99 WHERE product_id = 456;
COMMIT;
BEGIN;
-- 주문 정보 저장
INSERT INTO orders (user_id, order_date, total_amount) VALUES (123, NOW(), 129.99);
SET @order_id = LAST_INSERT_ID();
-- 주문 상품 항목 저장
INSERT INTO order_items (order_id, product_id, quantity, price) VALUES (@order_id, 456, 2, 49.99);
INSERT INTO order_items (order_id, product_id, quantity, price) VALUES (@order_id, 789, 1, 30.01);
-- 재고 업데이트
UPDATE inventory SET stock_quantity = stock_quantity - 2 WHERE product_id = 456;
UPDATE inventory SET stock_quantity = stock_quantity - 1 WHERE product_id = 789;
-- 사용자 포인트 사용 처리
UPDATE users SET reward_points = reward_points - 500 WHERE user_id = 123;
-- 결제 처리 기록
INSERT INTO payments (order_id, payment_method, amount, status) VALUES (@order_id, 'credit_card', 129.99, 'completed');
COMMIT;
BEGIN;
-- 출금 계좌 잔액 확인
SELECT balance INTO @current_balance FROM accounts WHERE account_id = 1001 FOR UPDATE;
-- 잔액 검증
IF @current_balance < 1000 THEN
ROLLBACK;
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Insufficient funds';
END IF;
-- 출금 계좌에서 금액 차감
UPDATE accounts SET balance = balance - 1000 WHERE account_id = 1001;
-- 입금 계좌에 금액 추가
UPDATE accounts SET balance = balance + 1000 WHERE account_id = 2001;
-- 거래 기록 저장
INSERT INTO transactions (from_account, to_account, amount, transaction_date)
VALUES (1001, 2001, 1000, NOW());
-- 알림 메시지 저장
INSERT INTO notifications (user_id, message, created_at)
VALUES (
(SELECT user_id FROM accounts WHERE account_id = 1001),
'Transfer of $1000 to account #2001 completed',
NOW()
);
COMMIT;
클라이언트 -> API 게이트웨이 -> 여러 마이크로서비스
플로우:
RPS와 TPS 관계: 1 RPS : 4 TPS
특징: 분산 트랜잭션으로, 각 서비스마다 독립적인 DB 트랜잭션 발생
이처럼 단일 트랜잭션과 복잡한 트랜잭션의 차이는 작업의 복잡도와 관련 데이터베이스 작업의 수에 있습니다. 복잡한 비즈니스 로직이나 분산 환경에서는 하나의 요청이 여러 트랜잭션을 발생시켜 RPS와 TPS 간의 차이가 더 명확하게 나타납니다.