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

Refactor/#151/use ehcache to improve performance(swm 426) #152

Merged

Conversation

D-w-nJ
Copy link
Member

@D-w-nJ D-w-nJ commented Feb 29, 2024

Motivation ๐Ÿค”

  • Ehcache๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ค‘๋ณต๋˜์–ด ์‚ฌ์šฉ๋˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์บ์‹œํ•˜์—ฌ ๋ฐฑ์—”๋“œ ๋ฆฌ์†Œ์Šค์™€ latency๋ฅผ ์ค„์ž…๋‹ˆ๋‹ค.

Key changes โœ…

  • ๊ธฐ์กด ์ปจํ…์ธ  ๊ฒ€์ƒ‰์—๋Š” 1์‹œ๊ฐ„ ์ด๋‚ด๋กœ ์—…๋ฐ์ดํŠธ ๋˜์–ด db์— ์ €์žฅ๋œ ์˜์ƒ/์žฌ์ƒ๋ชฉ๋ก ๋ฐ์ดํ„ฐ๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ(๊ฑฐ์˜ 100%) youtube data api๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•„์™”์Šต๋‹ˆ๋‹ค. ์ด๋•Œ ๋น„์Šทํ•œ ํ‚ค์›Œ๋“œ๋กœ ๊ฒ€์ƒ‰ํ•˜์—ฌ ๊ฐ™์€ ์ปจํ…์ธ ๊ฐ€ ํฌํ•จ๋˜๊ฑฐ๋‚˜ ๋‹ค๋ฅธ ๋ฉค๋ฒ„๊ฐ€ ๊ฐ™์€ ํ‚ค์›Œ๋“œ๋กœ ๊ฒ€์ƒ‰ํ•˜๋”๋ผ๋„ ๋ชจ๋“  ์ปจํ…์ธ ์— ๋Œ€ํ•ด ์ค‘๋ณต๋œ 3rd-party API(youtube data api)๊ฐ€ ์‚ฌ์šฉ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
    • Ehcache๋ฅผ ์‚ฌ์šฉํ•ด ๊ฐ™์€ ์˜์ƒ/์žฌ์ƒ๋ชฉ๋ก์ด ์กฐํšŒ๋˜์–ด getRecentVideo(String videoCode), getRecentPlaylist(String playlistCode) ๋ฉ”์„œ๋“œ๊ฐ€ ํ˜ธ์ถœ๋  ๊ฒฝ์šฐ 1์‹œ๊ฐ„๋™์•„ ๋ฉ”๋ชจ๋ฆฌ์— ์ €์žฅ๋˜์–ด ๊ฐ™์€ ์˜์ƒ/์žฌ์ƒ๋ชฉ๋ก์ด ์กฐํšŒ๋  ๊ฒฝ์šฐ ์ด๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

TPS(trasactions per second) ์ธก์ •์ด ๊ฐ€๋Šฅํ•œ ngrinder๋ฅผ ์‚ฌ์šฉํ•ด ํ…Œ์ŠคํŠธ๋ฅผ ๋จผ์ € ์ง„ํ–‰

  • ์„ค์ •
    • ๊ฐ€์ƒ์œ ์ € (Vuser) : 10๋ช…
    • ํ…Œ์ŠคํŠธ ์‹œ๊ฐ„ : 20์ดˆ
    • timeToLiveSeconds (์บ์‹œ๋œ ๋ฐ์ดํ„ฐ๊ฐ€ ๋ฉ”๋ชจ๋ฆฌ์— ๋‚จ์•„์žˆ๋Š” ์‹œ๊ฐ„) : 10์ดˆ
    • ํƒ€๊ฒŸ API : /api/ehcache/video/{videoCode} (์˜์ƒ ์ •๋ณด๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” API, ์บ์‹œ๋˜์ง€ ์•Š์€ ๋ฐ์ดํ„ฐ๋ผ๋ฉด youtube data api์‚ฌ์šฉ ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.)
  • ์ˆ˜ํ–‰ ๊ฒฐ๊ณผ
    image
    • ํ‰๊ท  response time : 1.55ms
      • youtube data api๋ฅผ ์‚ฌ์šฉํ–ˆ์„ ๋•Œ, ํ‰๊ท  latency๊ฐ€ 200ms์ด๋ฏ€๋กœ ์†๋„๊ฐ€ 100๋ฐฐ ๋นจ๋ผ์กŒ๋‹ค (๋ฌผ๋ก  ์บ์‹œ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ ๊ทธ๋Ÿด์ˆ˜๋ฐ–์— ์—†์Šต๋‹ˆ๋‹ค.)
    • 82,000 ๊ฐ€๋Ÿ‰์˜ api ํ˜ธ์ถœ์ด ์žˆ์—ˆ๊ณ , ๊ธฐ์กด ๋ฐฉ์‹์ด๋ผ๋ฉด 82,000๋ฒˆ ๋ชจ๋‘ youtube data api๊ฐ€ ์‚ฌ์šฉ๋˜์—ˆ๊ฒ ์ง€๋งŒ, Ehcache๋ฅผ ํ†ตํ•ด ์ด 11๋ฒˆ์˜ ์™ธ๋ถ€ api ํ˜ธ์ถœ๋กœ ์ค„์ผ ์ˆ˜ ์žˆ์—ˆ๋‹ค (์˜์ƒ ์ •๋ณด๋ฅผ ๋ฐ›์•„์˜ค๊ธฐ๊นŒ์ง€๋Š” ๋ฉ”๋ชจ๋ฆฌ์— ์ €์žฅ๋˜์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค์ˆ˜ ํ˜ธ์ถœ๋˜์—ˆ๊ณ , 10์ดˆํ›„ ๋ฉ”๋ชจ๋ฆฌ์— ํ•ด๋‹น ์ •๋ณด๊ฐ€ ์‚ญ์ œ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค์‹œ 6๋ฒˆ ๊ฐ€๋Ÿ‰ ํ˜ธ์ถœ๋˜์—ˆ๋‹ค)

Sroom์—์„œ์˜ Ehcache ์‚ฌ์šฉ ์ „๋žต

  • ์‚ฌ์šฉ ๋ฉ”์„œ๋“œ : getRecentVideo(String videoCode), getRecentPlaylist(String playlistCode)
    • ์กฐํšŒ๋œ ์˜์ƒ/์žฌ์ƒ๋ชฉ๋ก ์ •๋ณด๋ฅผ ๋˜๋‹ค์‹œ youtube data api๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€
  • maxElementsInMemory : 100,000
    • ๋ฐฑ์—”๋“œ ์ปจํ…Œ์ด๋„ˆ์˜ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ฉ”๋ชจ๋ฆฌ๋Š” 1400 MB
    • ์˜์ƒ 1๊ฐœ์— ์•ฝ 1000byte, ์žฌ์ƒ๋ชฉ๋ก 1๊ฐœ์— ์•ฝ 700byte๋กœ, maxElementsInMemory์„ ๊ฐ๊ฐ 100,000์œผ๋กœ ์„ค์ •ํ•œ๋‹ค๋ฉด ์•ฝ100mb, 60mb ๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋œ๋‹ค.
  • timeToLiveSeconds : 3600 (1์‹œ๊ฐ„)
    • ์Šค๋ฃธ์—์„œ ์„ค์ •ํ•œ ์˜์ƒ/์žฌ์ƒ๋ชฉ๋ก์˜ ์—…๋ฐ์ดํŠธ ์ฃผ๊ธฐ๋Š” 1์‹œ๊ฐ„์ด๋ฏ€๋กœ, ์ด์™€ ๋™์ผํ•˜๊ฒŒ ๊ฐ€์ ธ๊ฐ„๋‹ค.
  • memoryStoreEvictionPolicy : LRU
    • ์•Œ๋ ค์ ธ์žˆ๋Š” LFU(Least Frequently Used) ๋ฅผ ์“ฐ์ง€ ์•Š์€ ์ด์œ  : LFU์˜ ๊ฒฝ์šฐ ๊ฐ€์žฅ ์ตœ๊ทผ์— ๋“ค์–ด๊ฐ„ ์ •๋ณด๊ฐ€ frequency๊ฐ€ ๋‚ฎ๊ธฐ ๋•Œ๋ฌธ์— ๋จผ์ € eviction ๋  ๊ฐ€๋Šฅ์„ฑ์ด ๋†’๋‹ค. ํ•˜์ง€๋งŒ ์˜์ƒ ์ปจํ…์ธ ๋Š” ์ตœ๊ทผ ๊ฒ€์ƒ‰๋ ์ˆ˜๋ก ๋‹ค์‹œ ๊ฒ€์ƒ‰๋  ํ™•๋ฅ ์ด ๋†’๋‹ค๊ณ  ๋ณด๊ธฐ ๋•Œ๋ฌธ์— ์ด ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๋ฐฐ์ œํ•˜์˜€๋‹ค.
  • overflowToDisk : false
    • ๋ฉ”๋ชจ๋ฆฌ ํ•œ๊ณ„๋ฅผ ์ดˆ๊ณผํ•œ๋‹ค๋ฉด eviction ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•˜์—ฌ ์ง€์šฐ๊ณ , ๋””์Šคํฌ์— ์ €์žฅํ•˜์ง€๋Š” ์•Š๋Š”๋‹ค.

์„ฑ๋Šฅ

  • /lectures?keyword=() API(ํ‚ค์›Œ๋“œ ๊ฒ€์ƒ‰) ํ…Œ์ŠคํŠธ
    • ์บ์‹œ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ธฐ์กด ๋ฐฉ์‹์˜ API ํ˜ธ์ถœ latency : 1000~2000 ms (ํ•˜๋‹จ์˜ api ํ˜ธ์ถœ์€ 1600ms๋ฅผ ๋ณด์ž„)
      image
    • ๊ฒ€์ƒ‰๋œ ๋ชจ๋“  ์˜์ƒ/์žฌ์ƒ๋ชฉ๋ก ์ •๋ณด๊ฐ€ ์บ์‹œ๋˜๊ณ , ๋‹ค์‹œ API ๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด latency๊ฐ€ ๊ธฐ์กด์˜ 40%๋กœ ์ค„์–ด๋“  ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Œ (ํ•˜๋‹จ์˜ api ํ˜ธ์ถœ์€ 700ms๋ฅผ ๋ณด์ž„)
      image

To reviewers ๐Ÿ™

  • ์บ์‹œ ์‚ฌ์šฉ์˜ ์‹œ๋‚˜๋ฆฌ์˜ค๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ฐ€๋Šฅํ•˜์‹œ๋ฉด ํ•ด๋‹น ์‹œ๋‚˜๋ฆฌ์˜ค๋Œ€๋กœ ํ…Œ์ŠคํŠธ์„œ๋ฒ„์—์„œ ๊ฒ€์ƒ‰ ๋˜๋Š” ์ƒ์„ธ๊ฒ€์ƒ‰ ํ•ด๋ณด์‹œ๊ณ  ์œ ์˜๋ฏธํ•œ ์„ฑ๋Šฅ ๋ณ€ํ™”๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•ด์ฃผ์„ธ์š”
    • ์‚ฌ์šฉ์ž๊ฐ€ ๋น„์Šทํ•œ ํ‚ค์›Œ๋“œ๋กœ ๋‹ค์ˆ˜ ๊ฒ€์ƒ‰ํ•  ๋•Œ, ์ œ๊ณต๋˜๋Š” ์ปจํ…์ธ  ์ค‘ ์ผ๋ถ€๊ฐ€ ์ค‘๋ณต (์Šคํ”„๋ง๋ถ€ํŠธ ๊ฒ€์ƒ‰ ์ดํ›„ ์ž๋ฐ”์Šคํ”„๋ง ๊ฒ€์ƒ‰)
    • 1์‹œ๊ฐ„ ์ด๋‚ด ๋‹ค๋ฅธ ๋ฉค๋ฒ„๊ฐ€ ๊ฒ€์ƒ‰ํ•œ ํ‚ค์›Œ๋“œ๋ฅผ ๋‹ค๋ฅธ ๋ฉค๋ฒ„๊ฐ€ ๊ฒ€์ƒ‰ํ•˜๋Š” ๊ฒฝ์šฐ
    • ์žฌ์ƒ๋ชฉ๋ก ์ƒ์„ธ์กฐํšŒ๋กœ ์žฌ์ƒ๋ชฉ๋ก์˜ ๋ชจ๋“  ์˜์ƒ ์ •๋ณด๋ฅผ ์กฐํšŒํ•˜๊ณ , ํ•ด๋‹น ์žฌ์ƒ๋ชฉ๋ก ๋˜๋Š” ์œ ํŠœ๋ฒ„๋ฅผ ๊ฒ€์ƒ‰ํ•  ์‹œ ์ œ๊ณต๋˜๋Š” ์˜์ƒ์ •๋ณด๊ฐ€ ์ค‘๋ณต
  • ์บ์‹œ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•œ(ํ•„์š”ํ•œ) ๋ฉ”์„œ๋“œ๋ฅผ ๋ง์”€ํ•ด์ฃผ์„ธ์š” (๋‹ค์Œ์œผ๋กœ ์บ์‹œ๋ฅผ ์‹œ๋„ํ•  ๋ฉ”์„œ๋“œ๋Š” RecommendationService.getGeneralRecommends() ์ž…๋‹ˆ๋‹ค.

@D-w-nJ D-w-nJ linked an issue Feb 29, 2024 that may be closed by this pull request
@D-w-nJ D-w-nJ added enhancement New feature or request refactoring labels Feb 29, 2024
@D-w-nJ D-w-nJ self-assigned this Feb 29, 2024
@D-w-nJ D-w-nJ merged commit a06ab4b into main Mar 4, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SWM-426] Use Ehcache to Improve Performance
1 participant