Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UNI-255] refactor: 캐시를 활용한 응답 시간 개선 & 직렬화 시간 개선 #197

Merged
merged 18 commits into from
Feb 20, 2025

Conversation

mikekks
Copy link
Collaborator

@mikekks mikekks commented Feb 20, 2025

📝 PR 타입

  • 기능 구현
  • 기능 수정
  • 버그 수정
  • 리팩토링
  • 인프라, 의존성, 환경 변수, 빌드 관련 코드 업데이트

🚀 변경 사항

1. Redis를 활용한 캐시 사용

  • oom 문제를 해결하기 위해 앞선 방법을 통해 메모리 사용량을 줄여 더 많은 사용자의 요청을 처리할 수 있게 됐습니다. 하지만 이로 인해 동시에 처리할 양이 많아졌기에 응답속도가 많이 느려졌습니다. 그래서 캐시를 도입하게 되었습니다.

  • 로컬 캐시를 사용하지 않은 이유
    • 로컬캐시가 속도의 우위가 있기 때문에 로컬캐시 도입을 고민했습니다.
    • 하지만 저희가 메모리 사용량을 줄이기 위해 stream 을 사용했기 때문에 캐싱을 위한 메모리 사용에 부담이 있었습니다.
    • 이를 해결하기 위해 spring 서버는 데이터를 서빙하는 역할을 하며 캐싱 데이터는 서버와 분리한 캐싱 서버에 저장하도록 구현하였습니다.
    • 이를 통해 메모리 총 사용량과 빠른 응답시간 두 마리 토끼를 잡고자 했습니다.

2. Fastjson2를 통한 직렬화 & 역직렬화 속도 개선

  • redis 도입하며 로컬캐시에서는 발생하지 않은 문제가 생겼습니다.
  • 로컬캐시에 비해 redis가 현저히 느렸기 때문입니다.
  • 이를 해결하기 위해 부하테스트 및 관련 로그를 분석해봤습니다.
  • redis 는 논블락킹 I/O를 지원하며 초당 굉장히 많은 TPS 성능이 나오지만 redis 관련된 기능에서 병목이 일어나는 것을 확인했습니다.
  • 이를 위해 로그를 면밀히 분석해봤습니다.

  • 분석 결과
    • 네트워크 시간은 굉장히 작은 시간이었습니다.
    • 하지만 redis에서 서버로 데이터가 도착한 이후에 역직렬화하는데 많은 시간이 소요되었습니다.
    • 이를 위해 사용되는 Jackson의 성능 한계점을 알게 되었습니다.
    • 기존에는 Jackson을 사용하여 직렬화/역직렬화를 수행했으며, 평균 200ms의 시간이 소요되었습니다.
    • 이를 AlibabaFastjson2로 교체하여 직렬화 속도를 평균 20ms 로 90% 개선했습니다.
    • Fastjson2는 최적화된 바이너리 포맷과 성능 개선을 제공하여 Jackson 대비 더 빠른 직렬화/역직렬화가 가능하게 되었습니다.
    • redis 뿐만 아니라 클라이언트에게 데이터를 서빙할 때도 많은 시간을 단축할 수 있었습니다.
스크린샷 2025-02-20 오후 9 35 32

💡 To Reviewer

🧪 테스트 결과

✅ 반영 브랜치

  • feat/

@mikekks mikekks added 💡 refactor 기능 개선 🫀 be 백엔드 task labels Feb 20, 2025
@mikekks mikekks requested a review from thdgustjd1 February 20, 2025 12:36
@mikekks mikekks self-assigned this Feb 20, 2025
Copy link

coderabbitai bot commented Feb 20, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

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.

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


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Collaborator

@thdgustjd1 thdgustjd1 left a comment

Choose a reason for hiding this comment

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

연관된 로직이 많아 선 머지, 후 리뷰 하겠습니다! 고생 많으셨습니다!

@mikekks mikekks merged commit 884e2a7 into be Feb 20, 2025
2 checks passed
@mikekks mikekks deleted the refactor/UNI-255-v2 branch February 20, 2025 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🫀 be 백엔드 task 💡 refactor 기능 개선
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants