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

Server Side Swiftを使った サービス開発とその運用を考える

Yuki Takei
January 28, 2017

Server Side Swiftを使った サービス開発とその運用を考える

Tokyo Server Side Swift meetup#6 27, Jan, 2017

Yuki Takei

January 28, 2017
Tweet

More Decks by Yuki Takei

Other Decks in Technology

Transcript

  1. Serve-Side-SwiftͰෳ਺ͷOSSΛެ։͍ͯ͠·͢ʂ • Slimane: Web Framework + Web Server • Prorsum:

    Go Style Concurrent System and Networking Library • SwiftKnex: QueryBuilder for Mysql
  2. • Swift੡ͷWebϑϨʔϜϫʔΫ͸਺ଟ͘ଘࡏ͢Δ • ༗ྗͳͷ͸ɺKitura or vapor͔ʢຊ൪ӡ༻ͷ࣮੷͕ ෆ໌ͳ্ɺރΕ͍ͯΔͱ͸ݴ͑ͳ͍ʣ • ίϛϡχςΟͷن໛ͱ։ൃεϐʔυΛॏࢹ •

    ݴޠͷ੒௕΋ؚΊɺ1೥ޙʹ͸શ͘ҧ͏΋ͷʹͳͬͯ ͍ΔՄೳੑ͕ߴ͍ɻࠜؾڧ͘ϝϯς͢Δ֮ޛ͕ඞཁ • ։ൃ͕͍͖ͳΓStop͢Δةݥੑ΋(Slimane͕ͦ͏…) ϑϨʔϜϫʔΫ͸Ͳ͏͢Δʁ
  3. • SwiftαʔόʔΛී௨ʹཱͪ͋͛ͯӡ༻͢Δ৔߹͸ɺ super visorͰϓϩηεΛ؂ࢹ͢Δͷ͕Ұൠత • Docker(Ubuntu)΋໰୊ͳ͘࢖͑Δ • VMݴޠͰ͸ͳ͍ͷͰɺӡ༻͢ΔOSͰϏϧυ͢Δඞཁ ͕͋Δ •

    CI Tool(Ubuntu)ͰϏϧυͯͦ͠ͷόΠφϦΛσϓϩΠ ͢Δ͔ɺDocker ContainerΛ࡞ͬͯσϓϩΠ͕Ұൠత Swiftαʔόʔͷӡ༻ͱσϓϩΠ͸Ͳ͏͢Δʁ
  4. GRPCͱ͸ʁ www.grpc.io • google੡ͷRPCϑϨʔϜϫʔΫ • సૹϑΥʔϚοτ͕protocol buffers • ௨৴΋ؚ·ΕΔ •

    HTTP/2.0ඞਢ • ༷ʑͳݴޠ༻ʹplugin͕͋Δ • ϚΠΫϩαʔϏεؒͷ௨৴ʹgoogleͰ࢖͍ͬͯΔΒ͍͠
  5. • swift buildޙʹdocker containerΛCircleCI্Ͱ࡞ ੒ • CircleCI͔ΒECSͷΦʔέετϨʔγϣϯΛ࣮ߦ • Blue/GreenσϓϩΠϝϯτ •

    ΑͬͯɺSwiftઐ༻ͷσϓϩΠπʔϧ͸ෆཁ Q : σϓϩΠ͸Ͳ͏͢Δʁ A : Circle CIͰϏϧυͱσϓϩΠΛߦ͏
  6. ProrsumͷαʔόʔΞʔΩςΫνϟ DispatchSource + DispatchQueueΛ࢖ͬͨ Πϕϯτۦಈ + WorkerThreadͷϋΠϒϦοτϞσϧ main thread DispatchSourceͰɺ

    listeningSocketΛ؂ࢹ Queue Queue Queue Queue Queue Queue Queue Queue Queue client DispatchQueue(concurrent) nonblocking I/O blocking I/O
  7. Benchmarking Request/sec 0 17500 35000 52500 70000 Prorsum Kitura Go

    1.7 HTTP Server Express 14,769 64,768 17,144 29,436 ɾwrk -d 30s -t 4 -c 20 ɾResponded with the 10 length of random JSON array ɾMachine: MacOS Sierra, 8 logical cores, 8GB RAM
  8. SwiftKenxͱ͸ • Pure Swift Mysql Client + Query Builder •

    libmysqlclientʹґଘ͠ͳ͍ • TCPϨΠϠʔ͸Prorsum • εΩʔϚϚΠάϨʔγϣϯػೳΛαϙʔτ • SwiftݴޠͰදݱྗͷߴ͍SQL͕ॻ͚Δ • ܕηʔϑͳfetchɺinsert • ඇಉظI/OɺଟॏԽͷαϙʔτʢ͜Ε͔Βʣ
  9. • RFC 7230-7235(HTTP/1.1) • RFC 6455 (WebSocket) • RFC 7540(HTTP/2.0)

    • TCP/IP(v6,v4), UDP including I/O • TLS/Encryption ର৅͸ҎԼ