Skip to content

[Feat] Redis Stream 트리밍 정책 추가#207

Merged
howooyeon merged 2 commits into
developfrom
feat/#206-stream-trimming
Jun 9, 2026
Merged

[Feat] Redis Stream 트리밍 정책 추가#207
howooyeon merged 2 commits into
developfrom
feat/#206-stream-trimming

Conversation

@howooyeon

@howooyeon howooyeon commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🧾 요약

  • Redis Stream 메모리 무한 증가 방지를 위한 XTRIM 스케줄러 추가

🔗 이슈

✨ 변경 내용

  • TrackingPropertiesstreamMaxLen 설정 추가 (기본값 100,000)
  • application.yamlstream-max-len 환경변수 오버라이드 지원
  • RedisStreamConfig에 60초 주기 approximate 트리밍 스케줄러 추가

✅ 확인

  • 빌드 OK
  • 테스트 OK

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: af13a677-6494-482a-afba-db413cb6e96e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/#206-stream-trimming

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, 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

  • Redis Stream 트리밍 스케줄러 추가: Redis Stream의 메모리 무한 증가를 방지하기 위해 60초 주기로 동작하는 approximate 트리밍 스케줄러를 RedisStreamConfig에 추가했습니다.
  • 설정값 관리: TrackingProperties에 streamMaxLen 설정을 추가하고, application.yaml을 통해 환경변수로 오버라이드할 수 있도록 구성했습니다.
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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

[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

Comment on lines +34 to +40
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());
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

[P3] @Configuration 클래스는 빈 등록 및 설정을 담당하는 역할에 집중해야 합니다. @Scheduled를 사용한 주기적인 트리밍 작업(운영/비즈니스 로직)을 @Configuration 클래스 내부에 직접 정의하는 것은 단일 책임 원칙(SRP)에 어긋나며, 클래스의 역할을 모호하게 만듭니다.\n\n이 트리밍 로직은 별도의 @Component 클래스(예: RedisStreamTrimScheduler)로 분리하여 관리하는 것을 권장합니다.\n\n추천하는 개선 방향:\n새로운 컴포넌트 클래스를 생성하여 스케줄러 역할을 위임하세요.

References
  1. Controller, Service, Repository, DTO, Entity 등의 역할 분리를 명확히 해야 하며, 비즈니스/운영 로직은 설정 클래스가 아닌 적절한 서비스나 컴포넌트에 위치해야 합니다. (link)

@howooyeon howooyeon merged commit c1f16f9 into develop Jun 9, 2026
1 check passed
@howooyeon howooyeon self-assigned this Jun 9, 2026
@howooyeon howooyeon deleted the feat/#206-stream-trimming branch June 9, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat] Redis Stream 트리밍 정책 추가

1 participant