-
Notifications
You must be signed in to change notification settings - Fork 0
[UNI-377] refactor: 로컬캐시 도입 & 비동기 로깅 & Fastjson HTTP response 적용 #242
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
Changes from 10 commits
aedbbee
492685a
bb823e5
7195ff6
17bb575
d6f8eb9
8a9c226
2fb3d89
3da7a06
4f9437c
76f2031
cf65e08
521e7d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.softeer5.uniro_backend.common.config; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import org.springframework.cache.CacheManager; | ||
| import org.springframework.cache.annotation.EnableCaching; | ||
| import org.springframework.cache.caffeine.CaffeineCacheManager; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| import com.github.benmanes.caffeine.cache.Caffeine; | ||
|
|
||
| @Configuration | ||
| @EnableCaching | ||
| public class CaffeineConfig { | ||
| @Bean | ||
| public CacheManager cacheManager() { | ||
| CaffeineCacheManager cacheManager = new CaffeineCacheManager("lightRoutes", "tmp"); // 여러 개의 캐시 네임 설정 가능 | ||
| cacheManager.setCaffeine(caffeineConfig()); | ||
| return cacheManager; | ||
| } | ||
|
|
||
| public Caffeine<Object, Object> caffeineConfig() { | ||
| return Caffeine.newBuilder() | ||
| .expireAfterWrite(12, TimeUnit.HOURS) // 12시간 후 캐시 만료 | ||
mikekks marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .maximumSize(3000) // 최대 3000개 저장 | ||
| .recordStats(); // 캐시 통계 활성화 | ||
|
Comment on lines
+23
to
+27
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기서 최대 3000개란 이중에 무엇을 의미하는지 궁금합니다!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3번을 의미합니다 ! 이 부분도 어떻게 생각하시는지 궁금합니다 !
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 최대 2500 * 3000 = 750만 개의 데이터는 1GB 이하니깐 메모리 관점에서는 괜찮다고 생각합니다. (현재 8GB 서버 기준) 그런데 전국 약 300개 대학의 길 데이터를 모두 합쳐도 750만개가 안될것 같습니다.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 음 안그래도 저도 며칠전부터 그런 의문이 있었어서 공감이 되네요! 그래서 관련 자료들을 찾아봤는데여! 설득력이 있던 얘기는 "불필요한 데이터가 메모리에 너무 많이 올라가 있다." 였습니다. 정말 많은 사용자가 들어오게 된다면, 그에 따라 많은 메모리 공간이 필요하게 됩니다. 만약 1달 전에 사용했던 데이터도 로컬캐시에 올라와있으면 기본적으로 메모리 사용량이 높아져 TPS가 떨어지거나 OOM 발생 확률이 높아진다고 생각했습니다. Redis 와 같은 리모트 캐시에도 유효하다고 생각했습니다. 비슷한 이유로 필요없는 데이터가 메모리에 항상 올라와있다는 것이 불필요하고, 시스템의 여러 매트릭을 불필요하게 높이는 요인이라고 생각했습니다! 반대로 TTL를 도입하면 이게 참 애매한게 실제 사용자 트래픽이 있다면, 그 트래픽을 기준으로 의사결정을 할 수 있을 것 같은데 그러지 못하는게 아쉽네요.. 안그래도 해당 내용으로 얘기를 하고 싶었는데 좋은 질문 감사드리고, 현성님 의견이 궁금하네요..ㅎ
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 말씀해주신대로 확실히 TTL없이 할 경우 메모리낭비가 될 수 있을것 같습니다. 그렇다면 TTL을 적절하게 설정하는게 좋을 것 같네요! 아직 트래픽이 있지 않아서 정확하진 않지만, 서비스 특성상 오전8시-오후6시 사이에 호출량이 많을것으로 예상됩니다. (이 오전8시-오후6시를 피크타임이라고 하겠습니다.) TTL이 12시간일 경우 오늘 캐시에 올라간 데이터는 밤-새벽 사이에 만료되어 다음날 피크타임에 호출할 땐 다시 DB접근이 이루어질 것 같습니다. (핫 키도 밤-새벽 사이에 만료됨) 이러한 상황에서는 TTL을 36시간 이상으로 늘리거나, TTL 없이 최근 며칠간 접근되지 않은것을 지우거나 하는 방향으로 가면 좋을 것 같습니다!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그럼 일단 TTL을 36시간으로 설정하고, 추후에는 핫키에 대해서 동적으로 TTL을 갱신해보는 것을 고민해보겠습니다! 좋은 의견 감사합니다 :) |
||
| } | ||
| } | ||
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.