Skip to content

๐Ÿณ ํ…Œ์ด๋ธ” ํ’€์Šค์บ”๊ณผ ๋น„๋™๊ธฐ/๋ฉ€ํ‹ฐ ์“ฐ๋ ˆ๋“œ๋ฅผ ํ™œ์šฉํ•œ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ.

Notifications You must be signed in to change notification settings

jun-labs/async-parallel-scan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Full Table Scan with Async & Parallel

๋น„๋™๊ธฐ๋ฅผ ํ™œ์šฉํ•œ ํ…Œ์ด๋ธ” ํ’€ ์Šค์บ” ์„ฑ๋Šฅ ํ…Œ์ŠคํŠธ.

ํ…Œ์ด๋ธ” ํ’€ ์Šค์บ”์€ ํ…Œ์ด๋ธ”์˜ ๋ชจ๋“  row๋ฅผ ์กฐํšŒํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ๋ฐ์ดํ„ฐ๊ฐ€ ๋งŽ์„ ๊ฒฝ์šฐ ์ผ๋ฐ˜์ ์œผ๋กœ ๊ถŒ์žฅ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ๋ฐ์ดํ„ฐ๊ฐ€ ๋งŽ๋”๋ผ๋„ ๋ถ„ํ• ๊ณผ ๋น„๋™๊ธฐ๋ฅผ ํ™œ์šฉํ•œ ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๋ฉด ํŠน์ • ์ƒํ™ฉ์—์„œ๋Š” ๊ฝค ์ข‹์€ ์„ฑ๋Šฅ์„ ๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.





1. ์š”๊ตฌ ์‚ฌํ•ญ

์ด๋ฒคํŠธ ํ”Œ๋กœ์šฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์•Œ๋ฆผ ์†ก์‹ ์€ ๋ณ„๋„์˜ ์‹œ์Šคํ…œ์ด ํ•„์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ณ ๋ คํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

  1. ์•Œ๋ฆผ ๋ฉ”์‹œ์ง€๋ฅผ ์ „์†กํ•œ๋‹ค.
  2. ์ „์ฒด ์‚ฌ์šฉ์ž๋Š” 2,000 ๋งŒ ๋ช…์ด๋ฉฐ, ์•Œ๋ฆผ ์ˆ˜์‹ ์— ๋™์˜ํ•œ ์‚ฌ์šฉ์ž์—๊ฒŒ๋งŒ ์•Œ๋ฆผ์„ ์ „์†กํ•œ๋‹ค.
  3. ๋‹จ์ผ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜/๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.





Step1. ๋น„๋™๊ธฐ๋ฅผ ํ™œ์šฉํ•ด ์•Œ๋ฆผ์„ ์ „์†กํ•œ๋‹ค.

๋ฐ์ดํ„ฐ๊ฐ€ ๋งŽ์„ ๊ฒฝ์šฐ, ํ…Œ์ด๋ธ” ํ’€ ์Šค์บ”์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ชจ๋“  row๋ฅผ ์ฝ๊ธฐ ๋•Œ๋ฌธ์— ์‹œ๊ฐ„์ด ์˜ค๋ž˜ ๊ฑธ๋ฆด ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ, ๋น„๋™๊ธฐ๋ฅผ ํ™œ์šฉํ•ด ์ด๋ฅผ ๊ฐœ์„ ํ•œ๋‹ค.

  1. ๋น„๋™๊ธฐ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•œ๋‹ค.
  2. ๋ชจ๋‹ˆํ„ฐ๋ง์„ ํ†ตํ•ด ์ž์› ์‚ฌ์šฉ๋ฅ ์„ ์ฒดํฌํ•œ๋‹ค.




Step2. ํƒœ์Šคํฌ ์œ ์‹ค์„ ๋Œ€๋น„ํ•œ๋‹ค.

๋ฉ”์„ธ์ง€ ํ(Message Queue)๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ, ์˜๋„์น˜ ์•Š๊ฒŒ ํƒœ์Šคํฌ๊ฐ€ ์œ ์‹ค๋˜๋Š” ๊ฒฝ์šฐ ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค. ๋ฉ”์‹œ์ง€๊ฐ€ ์œ ์‹ค๋  ๊ฒฝ์šฐ, ์ด๋ฅผ ๋Œ€๋น„ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค.

  1. ๋ฉ”์‹œ์ง€ ์œ ์‹ค์„ ๋Œ€๋น„ํ•œ๋‹ค.
  2. ๋ฉ”์‹œ์ง€ ํ๋Š” ์–ด๋–ค ๊ฒƒ์„ ์‚ฌ์šฉํ•ด๋„ ์ƒ๊ด€์—†๋‹ค.
  3. ์™ธ๋ถ€ ๋ฉ”์‹œ์ง• ์‹œ์Šคํ…œ์„ ๋„์ž…ํ–ˆ์„ ์‹œ, ์„ฑ๋Šฅ ๋ณ€ํ™”๋ฅผ ์ธก์ •ํ•œ๋‹ค.







2. ์•„์ด๋””์–ด

์•„์ด๋””์–ด๋Š” ๋ถ„ํ• ๊ณผ ๋น„๋™๊ธฐ๋ฅผ ํ™œ์šฉํ•œ ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ ์ž…๋‹ˆ๋‹ค.

  • ๋ถ„ํ• 
  • ๋น„๋™๊ธฐ๋ฅผ ํ™œ์šฉํ•œ ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ





๋จผ์ € ํ•˜๋‚˜์˜ ํฐ ํƒœ์Šคํฌ๋ฅผ ์ ์ ˆํ•œ ๋‹จ์œ„(chunk)๋กœ ๋ถ„ํ• ํ•ฉ๋‹ˆ๋‹ค.

image







๊ฐ ํƒœ์Šคํฌ๋Š” ์ž์‹ ์ด ์ฒ˜๋ฆฌํ•  ์ž‘์—…์˜ ์‹œ์ž‘/๋์ ์„ ์•Œ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ์ค‘๋ณต ์ฒ˜๋ฆฌ๋ฅผ ๋ฐฉ์ง€ํ•˜๋ฉฐ, ์ธ๋ฑ์Šค(Index)๋ฅผ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

image







์ดํ›„ ๊ฐ ํƒœ์Šคํฌ๋ฅผ ๋น„๋™๊ธฐ๋ฅผ ํ†ตํ•œ ๋ณ‘๋ ฌ๋กœ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

image







3. ๊ฒฐ๊ณผ

2,000๋งŒ ๊ฑด ์ฒ˜๋ฆฌ ์‹œ 1๋ถ„ ~ 1๋ถ„ 45์ดˆ.

# ์•ฝ, 1๋ถ„ 31์ดˆ(91.16)
127.0.0.1:6379> get time::string::startTime
"1710619193857"
127.0.0.1:6379> get time::string::endTime
"1710619285018"
# ์•ฝ 1๋ถ„ 26์ดˆ(86.45)
127.0.0.1:6379> get time::string::startTime
"1710619455453"
127.0.0.1:6379> get time::string::endTime
"1710619541899"
# ์•ฝ 1๋ถ„ 38์ดˆ(98.73)
127.0.0.1:6379> get time::string::startTime
"1710619665364"
127.0.0.1:6379> get time::string::endTime
"1710619764089"







4. ํ•œ๊ณ„

ํƒœ์Šคํฌ ์‹คํ–‰ ์ค‘ ์ƒˆ๋กœ์šด ๋ฐ์ดํ„ฐ๊ฐ€ ์ถ”๊ฐ€ ๋์„ ๋•Œ, ์ด๋ฅผ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ์•ˆ์ด ์—†์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, 2,000๋งŒ ์‚ฌ์šฉ์ž์—๊ฒŒ ์•Œ๋ฆผ์„ ๋ฐœ์†กํ•˜๋Š” ๋„์ค‘ ์ƒˆ๋กœ์šด ์‚ฌ์šฉ์ž๊ฐ€ ๊ฐ€์ž…์„ ํ•œ๋‹ค๋ฉด ์ด๋ฅผ ๋Œ€์ฒ˜ํ•  ๋ฐฉ๋ฒ•์ด ์—†์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋ชจ๋“  ๋กœ์ง์ด ๋๋‚œ ํ›„, ์ƒˆ๋กœ ์ถ”๊ฐ€๋œ ์‚ฌ์šฉ์ž๋“ค์€ ๋ณ„๋„์˜ ๋กœ์ง์œผ๋กœ ์ฒ˜๋ฆฌํ•ด์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค.

interface UserRepository : JpaRepository<User, Long> {
    @Query("SELECT u FROM user u WHERE u.id > maxUserId")
    fun findByIdOver(maxUserId: Long): List<User>
}

๋˜ํ•œ ์ด ์™ธ์—๋„ ์“ฐ๋ ˆ๋“œ ํ’€ ๊ฐœ์ˆ˜ ์„ค์ •, ์ปค๋„ฅ์…˜ ๊ด€๋ฆฌ, ๋ชจ๋‹ˆํ„ฐ๋ง ๋“ฑ์˜ ์ถ”๊ฐ€ ์ด์Šˆ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์ƒ์„ธ ๋‚ด์šฉ์€ ๋ธ”๋กœ๊ทธ๋ฅผ ์ฐธ์กฐํ•ด์ฃผ์„ธ์š”.

About

๐Ÿณ ํ…Œ์ด๋ธ” ํ’€์Šค์บ”๊ณผ ๋น„๋™๊ธฐ/๋ฉ€ํ‹ฐ ์“ฐ๋ ˆ๋“œ๋ฅผ ํ™œ์šฉํ•œ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages