전체 글
-
spring kafka auto-commit 동작원리 : 데이터 유실과 중복처리프로젝트/kafka 2024. 10. 13. 14:52
대상 독자spring kafka의 auto-commit 동작원리를 알고 싶으신 분들 auto-commit을 활용할 때 데이터 유실과 중복처리를 제어할 수 있는 방법을 알고 싶으신 분들 개요많은 블로그들을 살펴보면 kafka consumer의 옵션 중 하나인 auto-commit은 일정주기로 commit을 수행하기 때문에 메시지의 중복 및 유실이 발생할 수 있다고 설명합니다. 일정주기로 자동으로 commit을 수행한다는 것은 메시지가 처리되는 중간에도 commit이 일어날 수 있을 것 같습니다. 만약 auto-commit을 활성화한다면 내부적으로는 어떤 일이 일어날까요? 이번 글에서는 spring kafka에서 auto-commit이 어떻게 동작하는지 알아보고 이 과정에서 데이터 유실과 중복처리를 어떻게..
-
spin lock은 cpu에 얼마나 부하를 줄까?성능테스트 2024. 10. 7. 01:00
대상 독자spin lock에 대해서 알고 싶으신 분들 spin lock이 실제 cpu에 얼마나 부하를 주는지 궁금하신 분들 개요소프트웨어를 개발하거나, 외부 라이브러리들을 활용하다 보면 종종 spin lock으로 구현되어 있는 경우를 발견할 수 있습니다. 이런 경우 while 등의 반복문을 활용해서 매번 체크하는 로직이 포함되는데 spin lock은 cpu에 부하를 주지 않을까? 라는 궁금즘이 생겼습니다. 만약 spin lock 방식을 소프트웨어에 활용하면 cpu에 얼마나 부하를 줄게 될까요? Spin Lock이란 무엇인가?fun getLock() { while(true){ if(락 획득) return else 반복하면서 락 획득 시도 }} spin lock은 임..
-
kotlin enum 상태 관리 구현하기Kotlin/Kotlin 2024. 9. 27. 21:20
개요 소프트웨어를 개발하다 보면 내부적인 상태를 관리해야 합니다. 이때 상태는 5가지 이내로 간단하게 표현될 수도 있고 50가지 혹은 그 이상으로 표현될 수도 있습니다. 어떻게 하면 수많은 상태가 존재할 때 안정적으로 상태를 관리하고 가독성 및 유지보수성을 챙길 수 있을까요? 유한상태기계(Finite State Machine)상태에 대해 공부하다 보면 유한상태기계 (FSM)이라는 개념이 종종 보입니다. 유한상태기계란 결국 한정되어 있는 개수의 복잡한 상태를 설계하는 데 사용하는 수학적 기법입니다. 이러한 기계는 한 번에 오로지 하나의 상태만을 가지게 됩니다. 이러한 기계는 어떠한 사건(Event)에 의해 한 상태에서 다른 상태로 변화할 수 있으며, 이를 전이(Transition)이라 합니다. 결국 중요..
-
Redis Cluster + Spring Boot + Lettuce client 이론과 세팅프로젝트/redis 2024. 8. 5. 00:00
Redis Sentinel이란? Redis Cluster를 알아보기 전에 간략하게 Redis Sentinel에 대해서도 알아보겠습니다.만약 Redis Cluster를 활용하지 않는다면 대안으로 자동으로 failover를 지원하는 Redis Sentinel을 활용해 볼 수 있습니다.마스터가 더 이상 사용할 수 없다는 사실에 여러 Sentinel이 합의하여 Slave 중 하나를 Master로 승격시키고 기존의 Master는 Slave로 강등시킵니다. 단순히 하나의 Sentinel에서 네트워크 문제로 Master와 연결되지 않을 수 있으므로 특정 quorum 이상에서 다운되었다고 인지한 경우 장애 조치를 진행합니다. Redis Cluster란 무엇일까?Redis Cluster는 N개의 마스터 노드를 활용하여 ..
-
분산락을 위한 Redis RedLock 톺아보기프로젝트/redis 2024. 7. 20. 20:42
분산락이란?분산락은 여러 개의 분산된 서버가 존재할 때 동일한 데이터에 대한 동기화를 보장하기 위해 사용하는 락의 종류 중 하나입니다. 분산락을 활용하면 서로 다른 서버들이 critical section 실행을 동시에 하지 못하도록 방지할 수 있습니다. 이때 MySQL의 네임드락, Zookeeper 등을 활용해서 분산락을 구현할 수 있는데 Redis의 RedLock 알고리즘을 활용하여 분산락을 구현할 수 있습니다. Redis가 다운되는 경우?단일 인스턴스를 활용하여 분산락을 구현할 수 있지만 이는 단일 실패점이 될 수 있습니다. 단일 실패점을 극복하기 위해서는 Master - Slave구조를 선택할 수 있습니다. 하지만 Slave로의 복제는 비동기이므로 아래와 같은 상황에서 race condition이..
-
Spring Boot Distributed SchedulingSpring Framework 2024. 6. 30. 21:25
개요최근에 Spring Batch 대신 @Scheduled 활용해 보기라는 주제로 글을 작성했던 적이 있는데 비슷한 주제로 Spring I/O 유튜브에 Spring Boot Distributed Scheduling 주제가 올라와서 이를 정리해보고자 합니다. Spring의 @Schedueld대부분의 software의 문제는 매 1분마다 실행되는 job을 통해 해결할 수 있습니다.Spring에서는 특정 주기로 반복되는 작업을 실행하기 위해 @Scheduled 어노테이션을 지원합니다. 하지만 서버 한대가 아니라 여러대에서 구동되는 환경이라면 각 서버에서 반복되는 작업이 개별적으로 수행되어 Race Condition이 발생할 수 있습니다. 위의 그림처럼 우리는 각 자원이 이상적으로 분배될 것이라고 기대되지만 여..
-
easyRandom으로 테스트코드를 편하게 작성하기테스트코드(Test Code) 2024. 6. 6. 17:55
테스트 코드를 작성할 때 불편한 것들테스트 코드를 작성할 때 흔히 겪는 불편함은 무엇일까요?의존성을 mocking 하거나 stubbing 하는 작업, 테스트 데이터 관리는 항상 골치 아픈 부분입니다.이러한 작업은 실제 테스트를 수행하기 위해 많은 시간과 노력을 요구합니다. 예시 - Request의 필드가 100개라면data class TooManyField( val col1: String, val col2: String, val col3: String, // ... val col100: String,)1. 100개의 필드를 일일이 작성하고 관리하는 것은 번거롭고 시간이 많이 걸립니다.2. 테스트 코드의 가독성이 떨어져 이해하기 어려워집니다. ..
-
프로젝트에 Feature Flag 적용하기Spring Framework 2024. 6. 1. 15:40
Feature Flag란 무엇인가? (Feature Toggle)Feature Flag란 특정 기능을 동적으로 활성화 혹은 비활성화하기 위해 사용되는 조건부 코드 실행 메커니즘입니다.런타임 환경에서 특정 조건에 따라 코드 특정 부분을 스위치 하여 실제 사용자에게 제공되는 서비스 기능을 다르게 제어할 수 있습니다.특히 이러한 제어를 위해서 매번 코드를 수정해서 배포할 필요가 없다는 특징이 있습니다. Feature Toggle이라고도 불리며 기능을 ON / OFF 할 수 있는 게 특징입니다. 매우 다양한 활용도특정 기능을 ON / OFF 할 수 있는 만큼 매우 다양하게 활용해 볼 수 있습니다. 예를 들면 아래와 같은 활용을 수행해 볼 수 있습니다.서킷브레이커 ON/OFFA/B 테스트카나리 배포Trunked..