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

実践サーバーレスパフォーマンスチューニング ~その実力に迫る~ / Practical ...

実践サーバーレスパフォーマンスチューニング ~その実力に迫る~ / Practical Serverless Performance Tuning ~A Close Look at its Power~

JAWS FESTA 2024 in 広島
https://jawsfesta2024.jaws-ug.jp

shiro seike

October 12, 2024
Tweet

More Decks by shiro seike

Other Decks in Programming

Transcript

  1. ©Fusic Co., Ltd.  1 ࣮ફαʔ バ ʔϨε パ ϑΥʔϚϯενϡʔχϯ

    グ ~ͦͷ࣮ྗʹഭΔ~ 2024.10.12 @seike460 JAWS FESTA 2024 in ޿ౡ
  2. ©Fusic Co., Ltd. 2 ਗ਼Ո ࢙࿠ @seike460 AWS Community Builder

    Serverless BacklogWorld2024 ࣮ߦҕһ௕ 12/14@ԣ඿ ίϛϡχςΟ JAWS-UG Fukuoka Serverless Meetup Fukuoka Cloudflare Meetup Fukuoka JBUG Fukuoka JP_Stripes Fukuoka Fukuoka.php Fukuoka.go ࣗݾ঺հ ͸͡Ίʹ גࣜձࣾFusicʢ෱Ԭʣ ϓϦϯγύϧΤϯδχΞ/ΤόϯδΣϦετ
  3. ©Fusic Co., Ltd. 3 CONTENTS ໨࣍ 1. αʔόʔϨεͱύϑΥʔϚϯε 2. ϘτϧωοΫͷ୳ࡧͱՄࢹԽ

    3. ϘτϧωοΫݪҼͷߟ࡯ 4. ϘτϧωοΫ΁ͷΞϓϩʔν 5. ·ͱΊ
  4. ©Fusic Co., Ltd. 5 αʔόʔϨεͱύϑΥʔϚϯε αʔόʔϨεΞʔΩςΫνϟ͸جຊϚωʔδυαʔϏε͕લఏ - Πϯϑϥ؅ཧෆཁ - ࣗಈεέʔϦϯά

    ͦͷજࡏೳྗͷߴ͔͞ΒʮͳΜͱͳ͘ʯߏஙͯ͠΋ ߴ͍ύϑΥʔϚϯε͕ग़Δ͜ͱ͕ଟ͍Ͱ͢ ҰํͰԿ΋ߟ͑ͳ͍ͱαʔόʔϨεͷ࣮ྗΛൃش͠੾Δ͜ͱ͸Ͱ͖·ͤΜ
  5. ©Fusic Co., Ltd. 7 The Serverless ArchitectureͳΑ͋͘Δߏ੒ - Amazon API

    Gateway - RESTful APIͷΤϯυϙΠϯτΛఏڙ - AWS Lambda - ϏδωεϩδοΫΛ࣮૷ ࠓճ͸Python - Amazon DynamoDB - σʔλετΞͱͯ͠ར༻ - AWS SAM - Serverless༻ͷIaC
  6. ©Fusic Co., Ltd. 11 ࠓԿ͕ى͍ͬͯ͜Δ͔Θ͔Βͳ͍ গ͠஫ҙਂ͘ݟͯ΋… - Handlerʹ༷ʑͳॲཧ͕ - Ͳ͔͔͜ΒUserͷ৘ใऔಘ͕

    - Կ΍ΒN+1͕ - Ͳ͔͜ʹAPIΞΫηεͯ͠Δʁ ୹͍ॲཧͷதʹ৭ʑͳ໰୊͕ ೖ͍ͬͯͦ͏
  7. ©Fusic Co., Ltd. 13 AWS X-Ray ͷ࢓૊Έ - τϨʔγϯάσʔλͷऩू -

    ࠷ॳʹτϨʔε IDΛੜ੒ͯ͠ɺ֤छαʔϏεʹ࿈ܞ - τϨʔεηάϝϯτΛར༻ͯ͠ՄࢹԽ͢Δ - LambdaɺAPI GatewayɺDynamoDB ͳͲͷαʔϏε - ೚ҙͷαϒηάϝϯτͷ֓೦΋ಋೖՄೳ - τϨʔεͷྲྀΕ - ϦΫΤετ͕ͲͷαʔϏεΛ௨ա͢Δ͔ΛՄࢹԽ Ͳ͜Ͱ஗͍͔ɺΤϥʔ͕ൃੜ͍ͯ͠ͳ͍͔֬ೝՄೳ
  8. ©Fusic Co., Ltd. 14 AWS X-Ray ͷಋೖɿtemplate.yaml AWS SAM Template.yaml

    Tracing: Active Λهड़͢Δ τϨʔεID͕ੜ੒͞ΕΔ Α͏ʹͳΔ
  9. ©Fusic Co., Ltd. 15 AWS X-Ray ͷಋೖɿιʔείʔυ requirements.txt౳Λར༻͠ pip install

    ͦͷޙpatch_all()Λ࣮ߦ͢Δ ֤छAWSαʔϏεͷ τϨʔε͕ߦΘΕͯɺ τϨʔεϚοϓ͕࡞੒͞ΕΔ
  10. ©Fusic Co., Ltd. 34 Lambda Insights Performanceϩά ColdStart͍ͯ͠Δ͔΍ɺColdStartͷ࣌ؒͳͲ΋දࣔ ϝϞϦ࢖༻ྔ΋೺ѲͰ͖ΔͷͰ ࣮ࡍͷLambdaͷϝϞϦαΠζΛܾΊΔ࣌ͷ

    ඇৗʹࢀߟʹͳΓ·͢ ࠓճ͸ϝϞϦ΋90%Ҏ্࢖͍ͬͯ·͢͠ CPUύϫʔΛ্͍͛ͨͷͰϝϞϦΛ1024MB·Ͱ্͛·͢ ※AWS Lambda ͷCPU਺͸ϝϞϦґଘ ߋʹ͜ͷιʔείʔυΛཧղ͢ΔͨΊʹ೺ѲΛਐΊΔ
  11. ©Fusic Co., Ltd. 41 ରॲ಺༰ͷߟ࡯ - CPUό΢ϯυͳܭࢉॲཧ͕େ͖͘Өڹ - CPUΛ্͛ΔͨΊʹɺϝϞϦαΠζΛ্͛ΔͱΑͦ͞͏ -

    DynamoDBͷσʔλऔಘॲཬࣗମʹ໰୊͕͋Γͦ͏ - औಘؔ਺ͷॲཬݟ௚͕͠ඞཁͦ͏ - DynamoDBʹର͢ΔN+1໰୊͕ൃੜ͍ͯͦ͠͏ - DynamoDBͷઃܭݟ௚͠ͰରԠग़དྷͳ͍͔ - ֎෦API΁ͷΞΫηε͕ͦͷ··஗͘ͳΔ - ֎෦API΁ͷରॲ͸ग़དྷͳ͍ͷͰඇಉظʹॲཧͰ͖ͳ͍͔ ※ࠓճ͸ඇಉظॲཧͯ͠ྑ͍΋ͷͱ͢Δ
  12. ©Fusic Co., Ltd. 44 ϝϞϦαΠζΞοϓ ·ͣ͸୯७ʹϝϞϦαΠζΛ্͛ͯΈΔ 128 MB -> 1024MB

    ߹ΘͤͯArchitecture΋arm64ʹͨ͠΄͏͕ ૣ͘ͳΓ·͢ CPUό΢ϯυͳcomplex_logic͕ ͔͋Β͞·ʹૣ͘ͳΔͷ͕Θ͔Δ
  13. ©Fusic Co., Ltd. 54 ·ͱΊ αʔόʔϨεΞʔΩςΫνϟ͸εέʔϧΛલఏͱ͍ͯ͠Δ͕ɺॲཧΛݟ௚͢͜ͱͰਅͷ࣮ྗΛൃش Point 01 ·ͣ͸ঢ়گͷ೺Ѳ͕େࣄɺAWS X-rayɺLambda

    InsightsɺϓϩϑΝΠϥʔΛۦ࢖ͯ͠ܭଌͱ೺Ѳ Point 02 ঢ়گͷ೺Ѳ͕ग़དྷͨΒɺࠓ·Ͱͷ஌ࣝΛۦ࢖ͯ͠ҰͭҰ࣮ͭ֬ʹରॲɺܭଌΛ܁Γฦͯ͠վળ Point 03 ܭଌɺߟ࡯ɺ࣮ߦͷαΠΫϧΛճͯ͠ɺServerlessͷਅͷՁ஋ʹ͖ۙͮ·͠ΐ͏ʂ Point 04