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

ISUCON運営を支えるAmazon ECSとAurora Serverless v2 / A...

FUJIWARA Shunichiro
November 10, 2022
1.4k

ISUCON運営を支えるAmazon ECSとAurora Serverless v2 / AWS Dev Day 2022 Japan

FUJIWARA Shunichiro

November 10, 2022
Tweet

More Decks by FUJIWARA Shunichiro

Transcript

  1. @fujiwara SREνʔϜ ISUCON 1,2,5,11 ! ༏উ4ճ ISUCON 3,8,12 ӡӦ(ग़୊)3ճ github.com/kayac/ecspresso

    Amazon ECS σϓϩΠπʔϧ github.com/fujiwara/lambroll AWS Lambda σϓϩΠπʔϧ
  2. ISUCON12֓ཁ ΦϯϥΠϯ༧બ 2022-07-23(౔) 10:00-18:00 ࢀՃνʔϜ਺ 698૊ʢֶੜ 98૊ʣ ࢀՃऀ߹ܭ 1657໊ʢֶੜ 246໊ʣ

    ΦϯϥΠϯຊબ 2022-08-27೔(౔) 10:00-18:00 ࢀՃνʔϜ਺ 30૊ʢֶੜ 8૊ʣ ࢀՃऀ߹ܭ 84໊ʢֶੜ 22໊ʣ
  3. ISUCON12ϙʔλϧͷߏ੒ Rails + Shoryuken (SQS job worker) ɹSPAʹ͍ۙߏ੒ ɹReact +

    REST API (Protobuf) ɹDiscord, GitHub࿈ܞͳͲ͸ඇಉظjobͰ࣮ߦ ɹDiscord bot ϕϯνϚʔΧʔ ɹϙʔλϧAPI͔ΒjobΛऔಘ (Rust੡daemon) ɹ→ ର৅ΠϯελϯεʹϕϯνϚʔΫ࣮ߦ (Go੡CLI) ɹϕϯνϚʔΫ݁ՌΛϙʔλϧAPIʹૹ৴
  4. ISUCON12ϙʔλϧ͸AWS্ʹσϓϩΠ Amazon CloudFront Application Load Balancer (ALB) Amazon Simple Queue

    Service (SQS) Amazon ElastiCache Redis Amazon ECS Fargate Aurora MySQL Serverless v2 [New!] ɹ2022-04 GA ɹͪΐ͏Ͳ࢖ͬͯΈ͔ͨͬͨʂ
  5. ISUCON11→12Ͱͷ͓΋ͳมߋ఺ • ϕϯνϚʔΧʔ͕ EC2 → ECS Fargate ʹ • ISUCON11

    νʔϜ͝ͱʹ1୆ͷ EC2 Λ੩తׂΓ౰ͯ • ISUCON12 700νʔϜʹରͯ͠ Fargate 200 λεΫΛڞ༗ • RDS ͕ Aurora Serverless v2 ʹʂ
  6. ISUCONϙʔλϧʹ͸Aurora Serverless v2͕࠷ద? ΞΫηεͷ૿ݮ͕ۃΊͯݦஶ ΞΫηε͕ଟ͍ظؒ͸ಛʹ୹͍(਺෼ʙ਺࣌ؒ) 3ϲ݄ͷӡӦظؒதɺ΄ͱΜͲ͸Ջ ࠷খ Aurora Capacity Unit(ACU)

    0.5Ͱे෼ ΞΫηε͕૿ݮ͢ΔλΠϛϯά͸ಡΊΔɺ͕… աڈͷܦݧ͕ͳ͍ͨΊ૿Ճ཰͕ಡΈͮΒ͍ ݟੵ΋ΓΛޡΔͱ଍Γͳ͍ = ো֐ͷՄೳੑ͕͋Δ
  7. ࣮ࡍͷར༻ঢ়گΛϝτϦΫεͰಡΈղ͘ υΩϡϝϯτ Aurora Serverless v2ͷॏཁͳAmazon CloudWatchϝτϦΫε3 ͔Β ServerlessDatabaseCapacity ʹ஫໨ ʼ

    ΠϯελϯεϨϕϧͷϝτϦΫεͱͯ͠ɺݱࡏͷDBΠϯελϯεͷ༰ྔͰ ද͞ΕΔ ACU ஋Λใࠂ͠·͢ 3 https://docs.aws.amazon.com/ja_jp/AmazonRDS/latest/AuroraUserGuide/aurora-serverless-v2.setting-capacity.html#aurora- serverless-v2.parameters-based-on-scaling
  8. ࢀՃొ࿥ୈ2ظ 70ඵͰ230νʔϜ͕׬ച 42k/min = 700req/secఔ౓ ɹSPAͳͷͰ΄΅͢΂ͯAPI Fargate 16 task (1

    vCPU 4GiB) ɹCPU ΄΅100%ʹ ɹFargate͸ࣄલʹtask਺खಈઃఆ άϥϑ͸CloudFrontͷϦΫΤετ਺
  9. ࢀՃొ࿥ୈ2ظ Queries & ServerlessDatabaseCapacity Queries 30 qps → 600 qps

    ServerlessDatabaseCapacity 0.5 → 2 Կ΋͠ͳ͍Ͱ΋ෛՙʹ௥ैͯ͠໰୊ͳ͠ 1෼ͰͷϐʔΫ͸΋ͬͱӶ͍4 4 ϝτϦΫεऔಘ࣌ʹ5෼ཻ౓ͷ஋͔͠࢒͍ͬͯͳ͔ͬͨͨΊ
  10. ༧બ։࢝࣌ Queries & ServerlessDatabaseCapacity 9:40 ͡Θ͡ΘͱΞΫηε͕૿͑Δ 10:00 1700໊͕Ұ੪ʹΞΫηε 10:00ͷΫΤϦ਺ ɹ9:55ͱൺֱͯ͠10ഒ

    ɹ9:59ͱൺֱͯ͠5ഒ ServerlessDatabaseCapacity 0.5 → 3ʹॠ࣌ʹ௥ै ઌճΓ্͕͍ͯͬͯ͠ΔΑ͏ʹ΋ʁ
  11. ༧બ1೔Λ௨ͯ͠ 10:00 ɹQueries 1.2k/sec ɹServerlessDatabaseCapacity 2.5 18:00 ɹQueries 2.8k/sec ɹServerlessDatabaseCapacity

    8.5 20࣌Ҏ߱ʹ௓Ͷ͍ͯΔͷ͸ӡӦʹΑΔ ௥ࢼͷӨڹ(ޙड़) Fargate͸๨Ε͍ͯͨ (ΦʔτεέʔϧͰ͍͍ײ͡ʹ૿͑ͨ)
  12. ༧બऴྃޙͷӡӦ௥ࢼ ࠷ॳͷϨΠςϯγ͕େ͖Ί Capacity͸एׯ஗Εͯ૿Ճ 2, 3ճ໨͸Capacity͕མ͖͍ͪͬͯͳ͍ →εϜʔζʹ௥ै͍ͯ͠Δ "Aurora Serverless v2Ͱͷ ύϑΥʔϚϯεͱεέʔϦϯά"5

    ʼ ݱࡏͷ༰ྔ͕େ͖͍΄ͲɺεέʔϧΞοϓ͕ ଎͘ͳΓ·͢ 5 https://docs.aws.amazon.com/ja_jp/AmazonRDS/latest/AuroraUserGuide/ aurora-serverless-v2.setting-capacity.html