Database/monogodb

[MongoDB] Read Preference ์˜๋ฏธ์™€ ์ข…๋ฅ˜

yuri lee 2022. 11. 16. 23:04
๋ฐ˜์‘ํ˜•

Intro

mongodb์˜ read preference์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. 

 

Read Preference?

read preference๋ž€ mongo db์—์„œ replica set ์„ค์ • ์‹œ primary, secondary์— ๋Œ€ํ•œ ์„ค์ •์ž…๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด mongo db๋Š” 5๊ฐ€์ง€ ๋ฐฉ๋ฒ•์„ ์ง€์›ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. 

 

Read Preference ModeDescription

Default mode. All operations read from the current replica set primary.
Multi-document transactions that contain read operations must use read preference primary. All operations in a given transaction must route to the same member.
In most situations, operations read from the primary but if it is unavailable, operations read from secondary members.
Starting in version 4.4, primaryPreferred supports hedged reads on sharded clusters.
All operations read from the secondary members of the replica set.
Starting in version 4.4, secondary supports hedged reads on sharded clusters.
In most situations, operations read from secondary members but if no secondary members are available, operations read from the primary on sharded clusters.
Starting in version 4.4, secondaryPreferred supports hedged reads on sharded clusters.
Operations read from a random eligible replica set member, irrespective of whether that member is a primary or secondary, based on a specified latency threshold. The operation considers the following when calculating latency:
Starting in version 4.4, nearest supports hedged reads on sharded clusters and enables the hedged read option by default.
  • primary : ๋ชจ๋“  ๋ช…๋ น์ด primary์—์„œ๋งŒ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค. 
  • primaryPreferred : primary๊ฐ€ unavilable ํ•  ๊ฒฝ์šฐ, read operation์„ secondary๋กœ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค. 
  • secondary : ๋ชจ๋“  read ๋ช…๋ น์„ secondary๋กœ ๋ณด๋‚ด ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค. 
  • secondaryPreferred : secondary members ๋ชจ๋‘ unavilable ํ•œ ๊ฒฝ์šฐ read ๋ช…๋ น์„ primary๋กœ ๋„˜๊ฒจ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค. 
  • nearest : primary, secondary ์ƒ๊ด€์—†์ด latency threshold๊ฐ€ ๊ฐ€์ž‘ ์ ์€ ์ธ์Šคํ„ด์Šค๋กœ ๋ณด๋‚ด ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

https://www.mongodb.com/docs/manual/core/read-preference/

๋ฐ˜์‘ํ˜•