Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RedisのCPU負荷対策パターン

 RedisのCPU負荷対策パターン

by id:y_uuki

Yuuki Tsubouchi (yuuk1)

August 19, 2017
Tweet

More Decks by Yuuki Tsubouchi (yuuk1)

Other Decks in Programming

Transcript

  1. εέʔϧΞοϓ εέʔϧΞ΢τ CPU1ίΞੑೳ͋͛Δ ਨ௚෼ׂ ࢀর༻εϨʔϒ ਫฏ෼ׂ - ࣗલ ਫฏ෼ׂ -

    Redis Cluster CPUෛՙ࡟ݮ RedisύΠϓϥΠϯ Lua scripting Linux RPS (Redis modules)
  2. εέʔϧΞοϓ • RedisαʔόͷCPUΫϩοΫΛߴ͍΋ͷʹมߋ • EC2ͳΒc4ܥͷΠϯελϯε • ίΞ਺Λ૿΍ͯ͠΋͋·Γҙຯ͸ͳ͍ • CPUར༻཰͕90%͔Β40%ʹͳͬͨ͜ͱ͕͋Δ •

    Xeon E5-2650L v2 @1.70GHz (Ivy Bridge) • Xeon E5-2670 v3 @2.30GHz (Haswell) • CPUΫϩοΫʹରͯ͠ઢܗʹมԽ͢ΔΘ͚Ͱ͸ ͳ͍
  3. CPUෛՙ࡟ݮ - Linux RPS • redisεϨουͱΧʔωϧͷωοτϫʔΫI/Oε ϨουΛผʑͷίΞͰॲཧ͢Δ • RPSͰύέοτॲཧΛCPU0Ͱड͚ͯ •

    redisεϨουͷCPU AffinityͰύέοτॲཧͱผ # echo ‘3’ > /sys/class/net/eth0/queues/rx-0/rps_cpus # taskset -pc 3-4 $(cat /run/redis/redis-server.pid)
  4. CPUෛՙ࡟ݮ - RedisύΠϓϥΠϯ • ΫϥΠΞϯτ͕ϨεϙϯεΛ·ͨͣʹޙଓͷϦΫΤετ Λ౤ೖ͢Δ͜ͱͰɺύέοτԟ෮ճ਺ΛݮΒ͢ • ωοτϫʔΫI/OॲཧΛ·ͱΊ࣮ͯߦͰ͖ΔͷͰɺCPU ॲཧ͕ݮΔ •

    1ճͷread(2)Ͱෳ਺ͷίϚϯυΛಡΈग़ͤΔͷͰɺγ εςϜίʔϧճ਺͕ݮΓίϯςΩετεΠον΋ݮΔ • ਅͷRedisύΠϓϥΠϯ(by id:ichirin2501) https://redis.io/topics/pipelining
  5. CPUෛՙ࡟ݮ - Lua scripting • ͋ΔίϚϯυͷ݁ՌΛ࣍ͷίϚϯυ͕ར༻͠ ͍ͯΔҰ࿈ͷίϚϯυྻ͸ύΠϓϥΠϯ࣮ߦ ෆՄ • Lua

    scriptingͳΒҰ࿈ͷίϚϯυྻΛluaίʔ υͱͯ͠ૹΓࠐΈɺ݁Ռ͚ͩड͚औΕΔ • ύΠϓϥΠϯಉ༷ɺΫϥΠΞϯτͱͷԟ෮ճ ਺͕ݮΓɺI/OγεςϜίʔϧΛ·ͱΊΒΕΔ https://redis.io/commands/eval
  6. εέʔϧΞ΢τ- ਫฏ෼ׂ • γϟʔσΟϯάͱ΋ݺͿ • ಉ͡༻్ͷ֤ΩʔΛෳ਺ͷϚελʔϊʔυʹ෼ࢄ • ΩʔͱϊʔυͷϚοϐϯάΛࣗ෼Ͱ΍Δ • Ϛοϐϯάํ๏͸༷ʑ

    • ϢʔβID xxx ͸ϊʔυYʹϚοϓ • ϢʔβID yyy ͷ৒༨͕ z ͳΒϊʔυXʹϚοϓ • γϟʔυΛ૿ݮͨ͠ͱ͖ͷσʔλ࠶഑ஔ͕೉͢͠ ͗ΔͷͰͱʹ͔͘΍Γͨ͘ͳ͍
  7. εέʔϧΞ΢τ- Redis ClusterʹΑΔਫฏ෼ׂ • ࠷ऴԞٛ • Ωʔͷ෼ࢄ഑ஔͱ࠶഑ஔ/ϑΣΠϧΦʔόʔͳͲα ϙʔτ • redis-tribͱ͍͏ެࣜπʔϧͰࣗಈ࠶഑ஔ΋Ͱ͖Δ

    • ࠷௿6ϊʔυඞཁ • database͕1͔͔ͭ͑͠ͳ͍ • ෳ਺Ωʔʹର͢ΔίϚϯυ࣮ߦʹ஫ҙ • 1000ϊʔυ͙Β͍·Ͱ͸εέʔϧ͢ΔΒ͍͠