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

Introduction of Slimane And Server Side Swift (Japanese)

9ebab3d4f66a62a859ad238e7e97597f?s=47 Yuki Takei
March 08, 2016

Introduction of Slimane And Server Side Swift (Japanese)

9ebab3d4f66a62a859ad238e7e97597f?s=128

Yuki Takei

March 08, 2016
Tweet

Transcript

  1. INTRODUCTION OF SLIMANE AND SERVER SIDE SWIFT Yuki Takei

  2. TABLE OF CONTENTS ▸ ࣗݾ঺հ ▸ Swift ͰServer Side? ▸

    Slimaneʹ͍ͭͯ ▸ σϞ ▸ ϕϯνϚʔΫ ▸ ։ൃܦݧஊ(ςετ΍ɺLinuxͰࠔͬͨ͜ͱͳͲ) ▸ ՝୊ɺ·ͱΊ
  3. ࣗݾ঺հ ෢Ҫ ༏ݾ ϑϦʔϥϯε ιϑτ΢ΣΞΤϯδχΞ / ϥδΦύʔιφϦςΟ ௨শ noppoman ݱࡏͷओͳ࢓ࣄ

    ɾגࣜձࣾiDEAKITT Ϧʔυσϕϩούʔ ʢ૑ۀظ͔Β) ɾגࣜձࣾSmartDrive όοΫΤϯυ/σʔλղੳʢ૑ۀظ͔Β) ݴޠͩͱɺNode.js, Ruby, Python, GO, SwiftΛ࠷ۙͩͱΑ͘࢖͍·͢ɻ MikeTOKYOͱ͍͏ϥδΦΛ΍͍ͬͯ·͢ɻস
  4. ࣗݾ঺հ / OSS ACTIVITY npdynamodb node-mariadb Slimane/SlimaneHTTP Suv

  5. ࣗݾ঺հ / OSS ACTIVITY ຊ೔঺հ͍ͤͯͨͩ͘͞΋ͷͰ͢ɻ npdynamodb node-mariadb Slimane/SlimaneHTTP Suv

  6. ஫) ͨͩ͠ɺͲΕ΋શ͘༗໊Ͱ͸͋Γ·ͤΜɺɺ

  7. SwiftͰServer Side?

  8. 2015೥12݄ʹɺSwift͕OSSԽ Linux Readyʹ

  9. SWIFTͰSERVER SIDE? ▸ core-foundation (Swift࣮૷ͷFoundation) ▸ Swift Package Manager (go

    getతͳ΍ͭ) ▸ XCTest ▸ gcd ▸ swift-llvm/lldb ύʔβʔ΍ϥϯλΠϜͳͲͷجຊతͳswiftݴޠػೳͷଞɺ ͳͲ΋ҰॹʹOSSԽ
  10. ͬͯ͜ͱ͸Զ΋αʔόʔ࡞ΕΔ͡ΌΜʂʂ

  11. ͱ͍͏͜ͱͰɺၟӽͳ͕Β࡞ͬͯΈ·ͨ͠ɻ

  12. None
  13. SLIMANEʹ͍ͭͯ ▸ ExpressɺSinatraͷྲྀΕΛ૊ΉܰྔϑϨʔϜϫʔΫ ▸ ඇಉظI/OʢΠϕϯτϧʔϓʣ ▸ C10K໰୊ ▸ ؆୯ɺγϯϓϧͳrouting ▸

    middlewareʹΑΔ֦ு ▸ Cluster mode(Ϛϧνϓϩηε؀ڥ) ▸ ໊લͷ༝དྷ͸ϑΝογϣϯσβΠφͷΤσΟεϦϚϯ Slimane͸ݱࡏචऀ͕։ൃதͷܰྔwebϑϨʔϜϫʔΫ
  14. SLIMANEʹ͍ͭͯ Slimane͸Web Server/Web Application FrameWork ҎԼͷ̏૚͔Βߏ੒͞ΕΔ Slimane SlimaneHTTP Suv *

    ɾURL Routing * ɾMiddleware * ɾBody Parser * ɾCookie And Session * ɾStatic Assets Serving ɾHTTP Server ɾHTTP Client Not implemented yet ɾHTTP Upgrade ɾHTTPS ɾNetworking ɾFileSystem ɾProcess ɾCluster and Worker ɾTimer, DNS, Signal ɾEncryption etc… High Low
  15. SLIMANEʹ͍ͭͯ / SUV Suv Suv͸libuvϕʔεͷඇಉظI/OϥϯλΠϜ ɾSlimaneʹ͓͚Δ࠷΋௿ϨϕϧͳAPI܈ ɾඇಉظͳTCPɺPipeɺFileSystem΍ProcessͳͲΛఏڙ ɾͦͷଞ҉߸Խܥ΋ͪΐͪ͜ΐ͜(uv_work_queue) ɾͲ͔͜Node.jsͬΆ͍interface (ͨͩ͠ɺI/O݁Ռ͸

    Either) ɾNetworking ɾFileSystem ɾProcess ɾCluster and Worker ɾTimer, DNS, Signal ɾEncryption etc…
  16. SLIMANEʹ͍ͭͯ / SLIMANEHTTP SlimaneHTTP ɾHTTP Server ɾHTTP Client Not implemented

    yet ɾHTTP Upgrade ɾHTTPS SuvϕʔεͷඇಉظHTTP Server/Client ɾSlimaneͷHTTPϨΠϠʔ ɾryan࡞ͷhttp-parser͕ϕʔε ɾHTTP/1.1ͷServerͱClient࣮૷ ɾHTTPS͸·ͩʢۙ೔ணखʣ ɾUpgrade(Websocket/HTTP2.0ͳͲ)͸·ͩ
  17. SLIMANEʹ͍ͭͯ / SLIMANE Slimane ɾURL RoutingɺMiddlewareΛఏڙ ɾCookie ParserɺSessionɺBodyParserɺFile Serving ɾ֦ு͕ඞཁ͕ͩɺViewςϯϓϨʔτ΋࢖͑Δ

    ɾModelͳ͠ʢඇಉظDBDriver͸طଘͷ΋ͷΛfolkͳͲ͠ ͯผ్։ൃ༧ఆʣ ɾઐ༻ίϚϯυϥΠϯΠϯλʔϑΣʔεʢۙ೔ެ։ʣ * ɾURL Routing * ɾMiddleware * ɾBody Parser * ɾCookie And Session * ɾStatic Assets Serving
  18. αʔόʔ্ཱͪ͛·Ͱͷ؆୯ͳίʔυΛ ݟͯΈ·͠ΐ͏

  19. SLIMANEʹ͍ͭͯ / ίʔυ ,

  20. σϞ

  21. ଎౓͕ؾʹͳͬͨͷͰɺ Swift΍ଞݴޠͷWAFͱڞʹ ϕϯνϚʔΫΛऔͬͯΈ·ͨ͠ɻ

  22. ͬͱͦͷલʹ….

  23. ࣄલ৘ใͷͨΊʹɺ ͍͔ͭ͘SwiftͷWebFrameWorkΛ঺հ͠·͢ɻ

  24. ϕϯνϚʔΫͷલʹ…. SWIFTͰ࢖͑ΔϑϨʔϜϫʔΫͷ঺հ ▸ Zewo (CSPɺGCDɺServerɺRoutingɺSSLͳͲ) ▸ Vapor (Laravel Inspired MVC)

    ▸ Swifton (Rails Inspired MVC) ▸ Kitura (From IBM. Express Like) ▸ Nest (Common Swift Server Side Interface PJ) େখͷServerɺWAF΍CSP࣮૷ͳͲ͕ɺ͜ͷ3ϲ݄ؒͰଓʑొ৔
  25. BENCHMARK݁Ռ Time 0 1.75 3.5 5.25 7 SLIMANE SLIMANE HTTP

    NGINX EXPRESS REVEL SWIFTON VAPOR KITURA ɾܭଌ͸apache benchͰߦͬͨ (ab -n 10000 -c 100) ɾ؀ڥ͸ɺAWS EC2ͷt2.medium(vCPU: 2, Mem: 4) ɾDBΞΫηεແ͠ɺͦΕͧΕͷindex htmlΛฦ͢୯७ͳςετ ɾKituraҎ֎͸Έͳrelease build
  26. Slimaneͷwikiʹৄ͍͠਺ࣈ͕͋Γ·͢ɻ https://github.com/noppoMan/Slimane/wiki/ benchmarking-result

  27. ։ൃܦݧஊɺࠓޙͷ՝୊ͳͲ

  28. ։ൃܦݧஊ(։ൃத΍ςετɺLINUX্Ͱࠔͬͨ͜ͱͳͲ) ▸ cݴޠΛѻ͏ࡍɺSystem headerͷએݴ͕LinuxͱmacͰҧ͏ͨΊɺ Posixޓ׵ͳؔ਺΍ɺϓϩύςΟΛѻ͏Α͏ʹ ▸ OSS൛Foundation͸ະ࣮ͩ૷͞Ε͍ͯͳ͍ػೳ͕ଟ͍ɻ ▸ ࢿྉ࡞੒࣌఺ͰɺXCTestͷඇಉظػೳ͕αϙʔτ͞Ε͍ͯͳ͍ (Quickͷ࡞ऀΑΓPR͕ग़͍ͯ·͢ɻ)

    ▸ libuv͸αϯϓϧ਺͕͋·Γଟ͘ͳ͍ͨΊɺΘ͔Βͳ͍ͱ͜Ζ͸ node.jsͷίʔυΛݟ࣮ͯ૷ΛϚωͯΈͨΓ ▸ Linux༻ͷϥΠϒϥϦͳͲ͸ɺ·ͩ·ͩͳʹ͕ྲྀߦΔ͔Θ͔Βͳ͍ɻ
  29. SLIMANEͷࠓޙͷ՝୊ ▸ libuvʢඇಉظʣͷͨΊɺྑ͘΋ѱ͘΋ͦ͜ʹͱΒΘΕΔ ▸ ಛʹωοτϫʔΫ΍ϑΝΠϧI/Oޙͷcallback hell ▸ PromiseͳͲͰcallback hellΛආ͚Δ(nodeͷyieldཉ͍͠…) ▸

    αʔυύʔςΟ੡ͷϥΠϒϥϦͱͷ਌࿨ੑ(ಛʹಉظI/Oܥ) ▸ ·ͩ·ͩmemory leak͕͋ΔʢZewoͷϥΠϒϥϦͰ͢Β͍ͯ͠Δ..ʣ ▸ ϓϩμΫγϣϯ؀ڥͰͷӡ༻ɺϑΟʔυόοΫ͕ඞਢ ▸ ։ൃ଎౓ͷ໰୊ɻ஥ؒΛूΊͯεϐʔυΞοϓ͍ͨ͠
  30. ࠷ޙʹ·ͱΊͰ͢ɻ

  31. ·ͱΊ ▸ Swiftαʔόʔ͸݁ߏ଎͍ʢνϡʔχϯά࣍ୈʣ ▸ ଓʑͱϑϨʔϜϫʔΫ΍αʔόʔ͕ొ৔͍ͯͯ͠ɺઓཚͷ࣌ ͕΍ͬͯ͘Δ…ʁ(PR͸ͪΐͬͱগͳΊͳؾ͕) ▸ SwiftͰඇಉظI/O͸·ͩ·ͩૣख़ ▸ XcodeͰ։ൃ

    -> LinuxͰϏϧυͷࡍ͸ɺະ࣮૷ͷػೳ΋͋Δ ͷͰཁ஫ҙ
  32. Slimane։ൃࠓޙ΋ؤு͍ͬͯ͜͏ͱࢥ͍·͢ɻ ؾܰʹPR͍͚ͨͩΔͱ޾͍Ͱ͢ʂ

  33. ɾSlimane https://github.com/noppoMan/Slimane ɾSlimaneHTTP https://github.com/noppoMan/SlimaneHTTP ɾSuv https://github.com/noppoMan/Suv ɾslimane-example https://github.com/noppoMan/slimane-example

  34. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ