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

速さは機能!Eightを支えるパフォーマンス・チューニング! / Performance is...

Sansan
November 27, 2019

速さは機能!Eightを支えるパフォーマンス・チューニング! / Performance is a Feature!

■イベント
Observability Meetup #2
https://newrelic.co.jp/events/meetup/observability-meetup-2

■登壇概要
タイトル:
速さは機能!Eightを支えるパフォーマンス・チューニング!

登壇者:
Eight事業部 Engineering Manager 藤井洋太郎

▼Sansan Builders Box
https://buildersbox.corp-sansan.com/

Sansan

November 27, 2019
Tweet

More Decks by Sansan

Other Decks in Technology

Transcript

  1. - ౻Ҫ༸ଠ࿠ (Fujii Yotaro) - ɹɹɹɹɹ (ݸਓ޲໊͚ࢗΞϓϦ) - 2014೥4݄ʹ৽ଔͱͯ͠ೖࣾ -

    Platform Unit(ج൫νʔϜ) - Unit Leader ݉ Engineering Manager - ΞʔΩςΫνϟ࡮৽΍ηΩϡϦςΟରԠɺ ύϑΥʔϚϯεվળ౳Λ୲౰ ࣗݾ঺հ
  2. Ϋϥ΢υ͸AWS ϚωʔδυαʔϏεΛϑϧ׆༻֤͠छػೳΛఏڙ    =.'4)> =.*, =.'4 KPI 7+'4

    7+0< />! />! '481   !  ! % 35)>  "  35/> " />  ;( $ %  *, 26 #81  9&:- =.'49&:- Recommendation Feed XPSLF S
  3. EightͰओʹར༻͍ͯ͠Δ New Relic αʔϏε ΞϓϦέʔγϣϯੑೳͷৗற؂ࢹ APIར༻ঢ়گͷ֬ೝ / چAPIΛఀࢭ͢Δࡍʹ΋ར༻ ΞϓϦέʔγϣϯΤϥʔऩू ύϑΥʔϚϯεվળ

    APM(Application Performance Monitoring) ϑϩϯτΤϯυͷ ϨϯμϦϯάύϑΥʔϚϯε JSΤϥʔͷऩू Browser ΞϓϦͷCPU/ϝϞϦ࢖༻ྔ ୺຤/ར༻ࠃຖͷ௨৴؀ڥ Τϥʔ෼ੳ Mobile ֤छRelicαʔϏεͱ࿈ܞ ੑೳྼԽݕ஌ & Slack௨஌ Alerts ࠓ೔ͷ࿩ͷϝΠϯ
  4. - ઃఆϑΝΠϧͰͷϑϥάมߋ͚ͩͰɺ؆୯ʹNew Relic AgentΛಋೖͰ͖Δɻ Ϛγϯʹ༨ܭͳϛυϧ΢ΣΞΛೖΕΔඞཁ͕ͳ͍ͱ͜Ζ΋ັྗ - ແྉ൛Ͱ΋(ࠓͷॴ)୆਺੍ݶແ͘ಋೖͰ͖Δʂ New Relic APMͷಛ௃

    Eight Ͱͷಋೖྫ Staging؀ڥ Production؀ڥ ϓϥϯ New Relic Lite(ແঈ൛) New Relic Pro(༗ঈ൛) ద༻୆਺ શ୆ Availability Zoneຖʹ1୆ͣͭ σʔλอ࣋ظؒ 1೔ 90೔ؒ ػೳ ΞϓϦέʔγϣϯશମͷঢ়گ/ ֓ཁ͸े෼೺ѲՄೳ ֤τϥϯβΫγϣϯ΍SQL౳ͷৄࡉ Λ೺Ѳ͢ΔͨΊʹ͸ඞਢ
  5. Ϧʔδϣϯ͕ҟͳΔͱɺωοτϫʔΫύϑΥʔϚϯεʹ΋͕ࠩग़Δ Availability Zone 1 Availability Zone 2 Aurora Elasticsearch Service

    ElastiCache CloudSearch ಉҰϦʔδϣϯ΍ɺ͍ۙڑ཭ʹ͋ΔαʔϏεͷ΄͏͕౰વύϑΥʔϚϯε͕Α͘ͳΔ App App ͍ۙ ԕ͍
  6. Eightͷ ຊ൪؀ڥͰ͸ Multi-AZ ຖʹ1୆ͣͭAgentΛ༗ޮԽ Availability Zone 2 Availability Zone 1

    Load Balancer ʮϦΫΤετ਺ʯ × ʮϨεϙϯελΠϜʯͰΦʔτεέʔϦϯά͞ΕΔ
  7. DynamoDBΛར༻͠ɺAgent༗ޮԽ͢ΔΠϯελϯεΛ੍ݶ Availability Zone 1 Auto Scaling Group Name Availability Zone

    Instance ID Auto Scaling Group1 Availability Zone 1 instance-1 Scaling Group1 Availability Zone 2 instance-4 … Availability Zone 2 Auto Scaling Group1 instance-1 instance-2 instance-3 instance-4 Auto Scaling Group1 Availability Zone 2 instance-4 ΠϯελϯεՔಇ࣌ʹ ʮಉҰεέʔϦϯάάϧʔϓ × AZʯͷItemΛ֬ೝ ແ͚Ε͹ɺઃఆϑΝΠϧ Λॻ͖׵্͑ͨͰΞϓϦ έʔγϣϯՔಇ Insert(Lock) Πϯελϯεୀ໾࣌ʹࣗ਎ͷInstance IDʹඥͮ͘ItemΛ࡟আ͢Δ͜ͱͰɺ্ཱ͕࣍ͪΔΠϯελϯεͰ༗ޮԽ
  8. - ϔϏʔϢʔβ޲͚ͷମݧ޲্Λ͠΍͍͢ - ਺ઍຕʙ1ສຕ໊ࢗΛ͍࣋ͬͯΔϢʔβ΋ଟ͘ଘࡏ - σʔλͷಉظॲཧɺݕࡧॲཧɺιʔτॲཧͳͲ - Α͘࢖͍ͬͯͩͬͯ͘͞ΔϢʔβ͞Μ΄Ͳɺ஗͍ମݧʹͳͬͯ͠·͏ɻͱ͍͏ ͜ͱ͸ආ͚͍ͨɻ -

    ؅ཧऀػೳͳͲɺීஈ࢖͍Ͱ͸ؾ͖ͮʹ͍͘ػೳ΋վળͰ͖Δ - ϨεϙϯελΠϜ͚ͩʹϑΥʔΧε͢Δ͜ͱͰɺ ར༻཰͸ߴ͘ͳ͍͕ॏཁͳػೳʹ΋ϑΥʔΧεΛ౰ͯΒΕΔɻ ظ଴͞ΕΔޮՌ
  9. - ஗͍ݪҼͱͳΔݪҼ͸༷ʑ - ॲཧ಺༰͕ଟ͍ - DBʹର͢ΔΫΤϦ͕஗͍ - ֎෦αʔϏεར༻ʹ͓͚Δͱͷ௨৴͕஗͍ - etc..

    - ͕ͩɺΞϓϦέʔγϣϯίʔυͷมߋ͚ͩͰվળͰ͖Δέʔε͸ݶΒΕΔɻ ϘτϧωοΫΛ୳͢
  10. - RDBΛѻ͏ͱ͖͕ɺ࠷΋ N+1 ͕ൃੜ͠΍͍͢ ςʔϒϧઃܭͰஸೡʹਖ਼نԽ͢Ε͹͢Δ΄ͲɺN+1໰୊Λҙࣝ͢Δඞཁ͕͋Δ RDB ᶃϦετऔಘ ᶄৄࡉऔಘ ɹ× Ϧετऔಘ෼

    ộ employees ςʔϒϧ business_cards ςʔϒϧ ྫ) ࣾһͱڞ༗͍ͯ͠Δ໊ࢗΛ ͢΂ͯऔಘ͍ͨ͠ ࣾһ͕100ਓ͍Δ৔߹ɺ101ճͷSQL͕ൃߦ͞Εͯ͠·͏..!!!
  11. - ϑϨʔϜϫʔΫ͕ఏڙ͍ͯ͠Δ ORM Λͦͷ··ҙࣝͤͣʹ࢖͏ͱɺN+1ʹͳͬͯ͠·͏ɻ - جຊతʹ Eager Loading ͷ࢓૊Έ͕༻ҙ͞Ε͍ͯΔ͸ͣͳͷͰɺNewRelicͷtransaction৘ ใΛࢀߟʹ͠ͳ͕Βɺνϡʔχϯά͍ͯ͘͠

    RDB Employee.includes(:business_cards).where(company_name: ‘Sansanגࣜձࣾ’) RailsͷActiveRecordͰ͋Ε͹ɺ ্هͷΑ͏ʹɺҰׅઌಡΈ͢ΔࢦఆΛ͢Δ͜ͱͰɺ ൃߦ͢ΔSQLΛ1ճ͋Δ͍͸ 2(1+1)ճ·ͰݮΒ͢͜ͱ͕Ͱ͖Δ✨ ࢀߟ) Rails Guide : ؔ࿈෇͚ΛҰׅಡΈࠐΈ͢Δ
  12. - ΩϟογϡΞΫηεͷվળ͸ҙ֎ͱ໡఺ʹͳΔ͜ͱ͕ଟ͍ ΩϟογϡΛಋೖ͢Δ͜ͱࣗମ͕ߴ଎Խʹͭͳ͕ΔͷͰɺෳ਺ճΞΫηε͍ͯ͠Δ͜ͱΛݟಀ͕ͪ͠ɻ ΩϟογϡετΞ(Memcached/ Redis) Redis Memcached Ϛελʔσʔλ - Memcached/Redis

    ڞʹҰׅऔಘ/ߋ৽༻ΠϯλʔϑΣʔε͕ఏڙ͞Ε͍ͯΔ - Memcached : Multi-GET / Multi-SET - Redis : MGET / MSET - ·ͨίωΫγϣϯϓʔϦϯάΛར༻͠ɺ઀ଓ࣌ͷΦʔόϔουΛഉআ͢Δ޻෉΋ॏཁ
  13. - ֤ݴޠɾϑϨʔϜϫʔΫ΍ΫϥΠΞϯτϥΠϒϥϦʹ͸ Multi ॲཧ͢Δ I/F ͸جຊతʹ༻ҙ͞Ε͍ͯΔɻ(͸ͣ) - Rails Ͱ͸ *_multi

    ϝιουΛར༻͢Δ͜ͱͰҰׅऔಘ/ߋ৽͕Ͱ͖Δɻ ΩϟογϡετΞ(Memcached/ Redis) Rails.cache ॲཧ಺༰ Rails.cache.read_multi ҰׅಡΈࠐΈ Rails.cache.write_multi Ұׅॻ͖ࠐΈ Rails.cache.fetch_multi ҰׅಡΈࠐΈɺΩϟογϡ͕ͳ͚Ε͹ॻ͖ࠐΈ
  14. ݕࡧΤϯδϯ/Elasticsearch Elasticsearch Service Aurora - ໊ࢗͷશจݕࡧͰར༻͍ͯ͠Δ Elasticsearch ʹରͯ͠΋ෳ਺ճߋ৽…. ɾESʹ͸ɺҰׅͰૢ࡞ՄೳͳBulk API

    ͕ఏڙ͞Ε͍ͯΔ ɾRubyͰ͸ elastic/elasticsearch-ruby gem ౳͔Β ɹBulk APIΛ؆୯ʹར༻Մೳʂ (Indexing͸ಉظͰ͸ͳ͘ɺόοΫάϥ΢ϯυॲཧʹճ͢ͷ͕Ұ൪)
  15. - ಈ͍͍ͯΔ͔Βେৎ෉ɺͰ͸࠷ߴͷαʔϏεʹ͸ͳΒͳ͍ɻ - զʑͷΑ͏ͳ SRE(Site Reliability Engineering) Λ୲౰͢ΔνʔϜͦ͜ɺ ʮ߈ΊʯͷύϑΥʔϚϯεվળΛ͍ͯ͘͠΂͖ɻ -

    දʹ͸Θ͔Γ΍͘͢ݱΕͳ͍Α͏ͳɺʮ଎͞ʯʮ҆ఆੑʯΛ௥ٻ͢Δ͜ͱ ͰαʔϏεϨϕϧΛҰஈɺೋஈҾ্͖͛Δ͜ͱ͕Ͱ͖Δɻ ଎͍ɺ͸ɺ఻ΘΔ ଎͞ɺ͸ͦΕ͚ͩͰػೳͨΓಘΔ