전체 글
-
Spring Boot Graceful shutdown 동작과정Spring Framework 2023. 11. 3. 20:22
개요 Spring Boot Application에서 Controller가 요청을 처리하고 응답이 되지 않았는데 종료요청이 도달하면 어떻게 될까요? Client는 응답을 받지 못하고 timeout이 발생합니다. Spring Boot 2.3에서 제공하는 graceful shutdown에 대해 알아보고, Spring Boot Application이 종료되는 과정을 분석해 보겠습니다. Shutdown public enum Shutdown { //요청들이 완료될때 까지 기다렸다가 종료 GRACEFUL, //즉시 종료 IMMEDIATE; } shutdown 전략에는 IMMEDIATE와 GRACEFUL이 존재합니다. 기본값은 IMMEDIATE로 설정되어 있고, GRACEFUL으로 설정할 시에는 새로운 요청을 거부하고..
-
kafka의 graceful shutdown프로젝트/kafka 2023. 11. 2. 00:01
개요Spring Kafka의 Consumer를 활용하다가 graceful shtudown을 어떻게 지원하는지 궁금해졌습니다.만약 offset을 commit 하기 전에 SIGTERM, SIGINT와 같은 종료 요청이 오면 어떻게 될까요? Shutdown SignalSIGKILL (9): SIGKILL signal 은 프로세스를 즉각 종료할 때 사용한다.SIGINT(2): 사용자의 요청으로 중단이 될 때 사용한다. (e.g., Ctrl+C).SIGTERM(15): SIGTERM signal 종료 요청을 보낸다, 요청을 보낼 뿐 SIGKILL은 아니다. kafka의 immediate-stop 옵션Container가 stop 되었을 때 현재 record를 처리하고 종료할지, 이전에 poll 한 모든 메시지를 처..
-
Deferred Join이란? - 실습편CS/데이터베이스 2023. 11. 1. 00:01
개요 Deferred Join이란?-이론 편에 이어 직접 데이터를 세팅하고 성능이 얼마나 개선되는지 확인하는 실습을 진행해보고자 합니다. Spring Boot를 활용한 50만건의 데이터 세팅 @Component class SettingData( private val memberJpaRepository: MemberJpaRepository, ): ApplicationRunner{ override fun run(args: ApplicationArguments) { repeat(500_000){ memberJpaRepository.save(MemberEntity(name = "test$it")) } } } 어떤 방식으로 데이터를 적재하던 상관없습니다. 쿼리문에 따른 실행계획과 성능을 살펴보기 위해 50만 건의..
-
데이터 정합성을 지키기 위한 다양한 노력들카테고리 없음 2023. 10. 31. 00:01
개요 사내 기술블로그에 글을 작성하기 전 초안을 미리 개인블로그에 작성해보고자 합니다. 자기소개 독자에게 글의 주제와 내용을 간략하게 소개하여 흥미유발 본문 결론 자기소개 아이들나라 플랫폼팀 Backend팀의 김준우입니다. "신입 개발자의 달리는 마차에 바뀌 갈아끼기" 라는 주제로 포스팅을 수행했던 적이 있으며, 그 이후로도 지속적으로 회원, 구독 서비스를 운영 개선하고 신규 서비스인 상품, 배송, 주문을 개발하고 있습니다. 해당글에서는 팀원분들이 작성해 주신 "아이들나라 통합 회원 시스템 소개", "실시간 회원 시스템 마이그레이션 구축"에 이어 서비스를 구현할 때 데이터 정합성을 지키기 위해 고려했던 내용들을 공유해보고자 합니다. 데이터 정합성과 무결성 우선 간단한 예시를 통해 데이터 무결성과 정합성에..
-
Spring @Transactional의 rollback 동작과정 디버깅Spring Framework 2023. 10. 30. 00:01
개요 결론적으로는 이번 디버깅을 통해 rollback의 동작과정을 알아보며 runtimeException & Error에만 롤백이 발생하는 이유와 Database 트랜잭션과 관련 없는 로직들이 Rollback 되지 않는 이유에 대해서 이해하였습니다. 의도적으로 예외 발생시키기 @Transactional fun `의도적으로 예외를 발생시키기`() { testRepository.save(TestEntity(name = "firstSave")) throw RuntimeException("의도적으로 runtime Exception을 던지면 rollback이 떻게 발생할까?") } 디버깅을 걸고 추적을 시작합니다. AopUtils invokeJoinpointUsingReflection는 AOP 메서드 호출의 일부..
-
Spring Boot + Redis 대기열 시스템 만들어보기 - 이론편프로젝트/선착순 쿠폰 발급 시스템 2023. 10. 29. 00:01
개요 이전부터 만들어보고 싶었던 대기열 시스템을 만들어보고자 합니다! 일시적으로 많은 트래픽이 발생하는 경우에 과도한 트래픽의 유입을 방지해 주는 대기열 시스템입니다. 특정 이벤트가 있을 때 예측된 트래픽을 대비하여 Scale out 할 수 있지만 폭주하는 짧은 기간이 지나가면 대부분의 자원들은 낭비됩니다. 이런 상황일 때 대기열 시스템을 도입할 수 있습니다. Redis 활용 이유 redis의 자료구조 중 sorted set을 활용하게되면 rdb를 활용하는 것보다 성능적인 면에서 우수합니다. Redis는 In-memory 저장소로 높은 처리량을 가지고 있기 때문에 많은 트래픽을 잘 버틸 수 있습니다. 많은 트래픽이 한번에 DB로 부하가 가지 않게 됩니다. Redis Sorted Set이란? score에 ..
-
Deferred Join이란? - 이론편CS/데이터베이스 2023. 10. 28. 00:01
Deferred Join을 활용하면 쿼리 속도를 2배 이상 높일 수 있다고 합니다. Deffered Join이란? deferred는 지연된 연기된 이라는 사전적 의미를 가집니다. pagination을 수행할 때 전체 테이블이 아닌 데이터의 하위 집합에서 pagination을 수행합니다. 이 집합은 subquery에 의해 생성되며 나중에 원래 테이블과 join 됩니다. pagination이 될 때 까지 join 작업이 연기되기 때문에 deffered join이라 불립니다. 전통적인 Pagination SELECT * FROM people ORDER BY birthday, id LIMIT 20 OFFSET 450000; people이라는 테이블이 존재하고 생일, ID별로 정렬된 결과를 표기하고 싶습니다. 이..
-
Redis를 통해 분산락 구현하기 - 실전편프로젝트/redis 2023. 10. 27. 00:01
Redis를 통해 분산락 구현하기 - 이론 편에 이어 실제로 구현을 해봅니다. 100장의 티켓을 구매하는 여러 스레드의 요청에도 분산락을 통해 예상한 대로 매진 시 0건 이하가 발생하지 않거나 50건의 요청이 있었다면 티켓 50장이 남아있는지 시나리오를 통해 동시성이 잘 제어되는지 확인해보려 합니다. 개발 환경 Spring Boot 3.1 Java 17 Redisson 의존성 추가 implementation ("org.redisson:redisson-spring-boot-starter:3.18.0") RedissonConfig 설정 @Configuration class RedissonConfig { @Value("\${spring.data.redis.host}") private val redisHost:..