Server Side Swift の個人的な利用シーン

9ebab3d4f66a62a859ad238e7e97597f?s=47 Yuki Takei
February 07, 2018

Server Side Swift の個人的な利用シーン

Vapor Meetup 1st in Tokyo 2018/02/06

9ebab3d4f66a62a859ad238e7e97597f?s=128

Yuki Takei

February 07, 2018
Tweet

Transcript

  1. 5.

    ࣗݾ঺հ ໊લ: ෢Ҫ༏ݾ (noppoMan) ॴଐ: ϑϦʔϥϯε, iDEAKITT Twitter: @noppoMan722 GitHub

    noppoMan ओͳ෼໺͸ɺΠϯϑϥɺαʔόʔαΠυ։ൃશൠɺσʔλղੳͰ͢ɻ iOSΞϓϦέʔγϣϯ։ൃ΋΍Γ·͢ɻ ࠓɺFGOʹϋϚͬͯ·͢ʂww
  2. 6.
  3. 12.
  4. 13.
  5. 17.

    ࣌୅͸Ϋϥ΢υɺBFF (Backend for Frontend) • Ϋϥ΢υͷ୆಄ʹΑΓɺόοΫΤϯυͷ࣮૷޻਺͸େ෯ ࡟ݮ • Ϋϥ΢υαʔϏε΁ͷ஌ࣝͷՁ஋͕ඇৗʹߴ·͍ͬͯΔ •

    SPA, ωΠςΟϒ + APIͱ͍͏ߏ੒͕ଟ͘ͳΓɺSEOΛআ ͘SSRͷػձ͸ݮͬͨ • ٕज़͸దࡐదॴʹͳ͖ͬͯͨ(ΤίγεςϜͷൃలతʹ) • ΑͬͯɺϑϧελοΫϑϨʔϜϫʔΫΛඞͣ͠΋બ୒͢Δ ඞཁ͸ͳ͍࣌୅
  6. 24.

    Service A Service B Service C Auth Server (Swift) ɾEmail

    & Password ɾFacebook ɾTwitter ɾGoogle ͜Μͳ΍ͭ
  7. 32.

    • Swift͸Liunx্ͰϏϧυ͢Δ͜ͱͰɺELFʹͳΔ • Amazon Linux͸CentOSͷܑఋͳͷͰɺجຊతʹSwift͸ಈ͘ (Foundationͱ͔͸᠘͋Δ͔΋ʁ) • σϓϩΠ͸ϓϩάϥϜΛLinuxͰϏϧυͯ͠ɺELFΛS3ʹ Ξοϓϩʔυ •

    Lambdaؔ਺಺ͷNode.js΍Python͔ΒSwiftͷELFΛαϒϓ ϩηεͱ࣮ͯ͠ߦ • LambdaʹHTTPͰΞΫηεͰ͖ΔΑ͏ɺAPI-GatewayΛར༻ αʔόʔϨεʹSwiftΛ࣮ߦ͢Δʢࠓճ͸Lambdaʣ
  8. 36.
  9. 37.

    And

  10. 38.
  11. 44.

    ࣮ࡍʹӡ༻͍ͯ͠Δߏ੒͕ͪ͜Β Proxy Execute Hexaville as CGI Lambda (Node.js 6.1) API

    Gateway DynamoDB ɾEnable TTL ɾEnable Autoscale Other Services Read/Write Temporary Data HTTP/1.1 OAuth
  12. 45.

    • ݴޠ΍ඪ४ϥΠϒϥϦͦͷ΋ͷ͸LambdaͰ໰୊ͳ͘ಈ࡞ • Lambda, API-Gateway, DynamoDBશ͕ͯϑϧϚωʔδυ ͳͷͰɺ99%ӡ༻Ϩε • σʔϞϯԽ͞Εͳ͍ͷͰɺGCDͰCPUΛޮ཰Α͘࢖͍੾ Εͳ͍ͱ͔ؾʹ͠ͳ͍͍ͯ͘

    • σϝϦοτͱͯ͠ɺαϒϓϩηεੜ੒ͷίετ͕ߴ͖ͭ͘ɺ ؆୯ͳϓϩάϥϜͳΒNode.js͚ͩͷ΄͏͕଎͍ => ͱ͸͍͑ମײͰ஗͍ͱ͸ײͮ͡Β͍ αʔόʔϨεͰSwiftΛӡ༻ͯ͠Έͯ
  13. 48.
  14. 53.

    • ωΠςΟϒόΠφϦʹͳΔͷͰσϓϩΠ͸༰қ • σʔϞϯԽ͢Δ৔߹ɺVMɺGC͕ແ͍ͨΊ͓͡͞Μ͍Βͣ • ݴ͏·Ͱ΋ͳ͘ಈ࡞͸ߴ଎ • ڧྗͳ੩తܕ෇͚ͱNull҆શੑͷԸܙͰɺ࣮ߦ࣌Τϥʔ͸͔ͳ Γى͜ΓͮΒ͍ •

    ڞ༗ϥΠϒϥϦԽग़དྷΔ • UIKit΍Objective-Cʹґଘ͠ͳ͍iOS༻ͷϥΠϒϥϦ͕ར༻Մೳ • iOSͰ͸ඞਢͷͨΊ৽͍͠ݴޠʹͯ͠͸։ൃऀ͕ଟΊ SwiftΛόοΫΤϯυ(Linux)Ͱར༻͢ΔϝϦοτ
  15. 56.
  16. 66.

    Swiftͷؔ਺γϯϘϧͷऔಘ $ nm -gU .build/x86_64-apple-macosx10.10/debug/libNativeExtensionInSwift.dylib 0000000000001180 T __T022NativeExtensionInSwiftAAV10printHelloyyF 00000000000010f0 T

    __T022NativeExtensionInSwiftAAV9fibonaccis5Int32VAEF 0000000000001230 T __T022NativeExtensionInSwiftAAVABycfC 0000000000001360 T __T022NativeExtensionInSwiftAAVMa 0000000000003af0 S __T022NativeExtensionInSwiftAAVMn 0000000000004310 S __T022NativeExtensionInSwiftAAVN
  17. 71.

    Swift Node.js C++ ϑϩʔ 3͔Βͷଓ͖ 5ͷؔ਺ϙΠϯλΛNodeͷ಺෦తͳҾ਺ɺ ฦΓ஋ΛฦͤΔΑ͏ʹϥοϓ 6 SwiftͷϓϩάϥϜΛ ಈతɾ੩తϥΠϒϥϦͱͯ͠༧ΊϏϧυ

    4 swift.cc಺Ͱɺ1Ͱ࡞੒ͨ͠ ڞ༗ϥΠϒϥϦΛdl_open 2Ͱऔಘͨ͠γϯϘϧΛdl_symʹ౉͠ɺ 4͔Βؔ਺ϙΠϯλΛऔಘ 5
  18. 80.

    • dylib΍soͷಡΈࠐΈ͸ॳճͷҰճͷΈͳͷͰɺΦʔόʔ ϔουΛؾʹ͢Δඞཁ͸ͳ͍ • ͜ͷಛੑ͸αʔόʔϨεͰඇৗʹ׆͖Δ => αϒϓϩηεੜ੒ͷίετ͕ແ͘ͳΓSwiftΛར༻͢Δ σϝϦοτ͕ղܾ • Swift͸Cͷܕ΋্ख͘ѻ͑Δ

    => αϯϓϧͰ͸ɺCIntܕΛ࢖͍ͬͯΔ͕ɺSwiftͷ @convention(c)Λར༻͢Ε͹ɺIntܕ΍StringܕΛউखʹ CInt΍CStringͱͯ͠ѻͬͯ͘ΕΔ ωΠςΟϒΤΫεςϯγϣϯ։ൃݴޠͱͯ͠ͷSwift
  19. 82.
  20. 83.
  21. 94.
  22. 96.