[Feat] Redis Stream 트리밍 정책 추가#207
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 본 PR은 Redis Stream의 데이터가 무한히 쌓여 메모리 사용량이 증가하는 문제를 해결하기 위해 도입되었습니다. 주기적인 트리밍 정책을 적용하여 스트림의 크기를 일정 수준으로 유지함으로써 시스템 안정성을 확보하는 것을 목적으로 합니다. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a scheduled task (trimStream) to periodically trim the Redis stream to a configured maximum length. The review feedback suggests configuring a multi-threaded task scheduler (spring.task.scheduling.pool.size) to prevent execution bottlenecks across multiple scheduled tasks, and refactoring the scheduling logic out of the @Configuration class into a dedicated @Component to adhere to the Single Responsibility Principle.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| } | ||
| } | ||
|
|
||
| @Scheduled(fixedDelay = 60_000L) |
There was a problem hiding this comment.
[P2] Spring Boot의 기본 TaskScheduler는 단일 스레드(poolSize = 1)로 동작합니다.\n현재 프로젝트에는 10초 주기로 DB에 GPS 데이터를 플러시하는 TrackingStreamConsumer.flushAll()과 60초 주기로 Redis Stream을 트리밍하는 trimStream() 등 여러 스케줄러 작업이 존재합니다.\nDB I/O가 발생하는 플러시 작업이 지연될 경우, 동일한 스레드를 공유하는 트리밍 작업이나 다른 스케줄러 작업들이 제때 실행되지 못하고 대기하는 병목 현상이 발생할 수 있습니다.\n\n따라서 스케줄러가 멀티 스레드로 동작할 수 있도록 spring.task.scheduling.pool.size 설정을 application.yaml에 추가하는 것을 권장합니다.\n\n추천 설정 (application.yaml):\nyaml\nspring:\n task:\n scheduling:\n pool:\n size: 5\n
| public void trimStream() { | ||
| Long trimmed = redisTemplate.opsForStream() | ||
| .trim(trackingProperties.getStreamKey(), trackingProperties.getStreamMaxLen(), true); | ||
| if (trimmed != null && trimmed > 0) { | ||
| log.info("[STREAM] 트리밍 완료 | {}건 제거 | maxLen={}", trimmed, trackingProperties.getStreamMaxLen()); | ||
| } | ||
| } |
There was a problem hiding this comment.
[P3] @Configuration 클래스는 빈 등록 및 설정을 담당하는 역할에 집중해야 합니다. @Scheduled를 사용한 주기적인 트리밍 작업(운영/비즈니스 로직)을 @Configuration 클래스 내부에 직접 정의하는 것은 단일 책임 원칙(SRP)에 어긋나며, 클래스의 역할을 모호하게 만듭니다.\n\n이 트리밍 로직은 별도의 @Component 클래스(예: RedisStreamTrimScheduler)로 분리하여 관리하는 것을 권장합니다.\n\n추천하는 개선 방향:\n새로운 컴포넌트 클래스를 생성하여 스케줄러 역할을 위임하세요.
References
- Controller, Service, Repository, DTO, Entity 등의 역할 분리를 명확히 해야 하며, 비즈니스/운영 로직은 설정 클래스가 아닌 적절한 서비스나 컴포넌트에 위치해야 합니다. (link)
🧾 요약
🔗 이슈
✨ 변경 내용
TrackingProperties에streamMaxLen설정 추가 (기본값 100,000)application.yaml에stream-max-len환경변수 오버라이드 지원RedisStreamConfig에 60초 주기 approximate 트리밍 스케줄러 추가✅ 확인