Slide 1

Slide 1 text

Swift3 Framework Slimane and Server Side Swift Yuki Takei @iOSDC 2016 Aug, 19

Slide 2

Slide 2 text

Yuki Takei (@noppoMan722) ϑϦʔϥϯειϑτ΢ΣΞΤϯδχΞ iDEAKITTͱ͍͏ελʔτΞοϓͰϦʔυσϕϩούʔΛ͍ͯ͠·͢ɻ ΠϯϑϥɺWebɺiOSɺࣗવݴޠॲཧͳͲΛ΍Γ·͢ɻ ˎ࠷ۙɺΩʔϘʔυʢγϯηαΠβʔʣΛ࢝Ί·ͨ͠ɻ ࣗݾ঺հ

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Tokyo Server Side Swift Meetup ΛෆఆظͰ։࠵͓ͯ͠Γ·͢(স) εϐʔΧʔืूதʂʂʂʂ ࣍ճͷձ৔͸Onlab(ܙൺण)༧ఆ

Slide 5

Slide 5 text

Έͳ͞ΜɺServer SideͰ΋Swiftॻ͍ͯ·͔͢ʁ

Slide 6

Slide 6 text

Swift͕OSSʹͳͬͯૣ൒೥Ҏ্

Slide 7

Slide 7 text

͜ͷ൒೥ؒͰͨ͘͞ΜͷSwift੡Web Frame Work ͕ొ৔͖ͯ͠·ͨ͠ɻ

Slide 8

Slide 8 text

·ͨ๻ݸਓͱͯ͠΋͜ͷ൒೥ؒ͸ɺ Server Side SwiftͱָۤΛͱ΋ʹͨ͠೔ʑͰͨ͠ʢসʣ

Slide 9

Slide 9 text

2016/01ɺSlimane։ൃ։࢝ʂΑ͓͓͠ؤுΔ͓ͧʂ

Slide 10

Slide 10 text

2016/02ɺҰ௨Γग़དྷͨʂMeet up΍ͬͪΌ͏͓ͧʂ

Slide 11

Slide 11 text

2016/03ɺ͋ΕʁSwift Updateͨ͠ΒίϯύΠϧͰ͖ͳ͍ͧ

Slide 12

Slide 12 text

2016/04ɺ·ͨग़དྷͳ͍ɻυϥεςΟοΫʹ࢓༷͕มΘͬͯ͘…

Slide 13

Slide 13 text

2016/05ɺmacͩͱಈ͘ͷʹɺLinuxͩͱಈ͔ͳ͍….

Slide 14

Slide 14 text

2016/06ɺϙΠϯλपΓͷAPI͛͢ʔมΘͬͯΔ΍Μ͚ʂʂ

Slide 15

Slide 15 text

2016/07ɺώϟοϋʔww @escaping ww

Slide 16

Slide 16 text

·͡Ͱɺ10000Օॴ͘Β͍Swift3ͷΞοϓσʔτʹΑΔίϯύ ΠϧΤϥʔ௚͠·ͨ͠

Slide 17

Slide 17 text

ͦͷ͘Β͍ͷεϐʔυͰSwift3͸੒௕͍ͯ͠·͢ɻ

Slide 18

Slide 18 text

࿩͕ͦΕ·͕ͨ͠ɺɺ

Slide 19

Slide 19 text

ຊ೔͸ɺ൒೥ؒͷOSS Swiftͷ׆ಈΛ௨ͨ͠ूେ੒తͳ͓࿩͕ ग़དྷΕ͹ͱࢥ͍·͢ɻ ʢओʹWeb FrameWorkͱͦΕʹవΘΔ͓࿩Ͱ͢ɻʣ

Slide 20

Slide 20 text

·ͣ͸ɺͲΜͳϑϨʔϜϫʔΫ͕Ͳ͏͍ͬͨࢥ૝΍ٕज़Ͱ ݱΕ͍ͯΔͷ͔ɻ

Slide 21

Slide 21 text

ݱ࣌఺ͰؾʹͳΔ΋ͷΛϐοΫΞοϓͯ͠͝঺հ͍ͨ͠·͢ɻ

Slide 22

Slide 22 text

IBM Kitura

Slide 23

Slide 23 text

IBM Kitura Vapor

Slide 24

Slide 24 text

Vapor IBM Kitura Zewo

Slide 25

Slide 25 text

Vapor IBM Kitura Zewo Slimane

Slide 26

Slide 26 text

ZewoɺVeniceX ΄΅ݸਓɻɻorz Vapor IBM Kitura Communities

Slide 27

Slide 27 text

Super Moduler/Full Stack Express Inspired/Tiny, Faster Laravel Inspired Full Stack/Popular Sinatra, Express like, From IBM Futures

Slide 28

Slide 28 text

CSP Event Loop Model+Master/Worker Pattern Prefork Model Prefork Model Concurrency/Parallelism Models

Slide 29

Slide 29 text

Simple Full Stack Faster Slower

Slide 30

Slide 30 text

Open-swift Original+Core Foundation Denominations Open-swift Open-swift

Slide 31

Slide 31 text

Open-Swift?

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

• Cross Project Standard for SwiftΛᨳͬͨɺCore- Foundationͷ࠶ఆٛٴͼϦϓϨΠεΛ໨తͱ͠ ͨϓϩδΣΫτ • ProtocolΛఆΊͨ΋ͷʢ΄΅੍໿ʣͷͨΊɺϩ δοΫϨε • ओʹWebΞϓϦέʔγϣϯ޲͚ Open-Swiftͱ͸

Slide 34

Slide 34 text

• C7ɿCore standards for Swift • S4: HTTP standards for Swift • D5: Database standards for Swift ҎԼͷ3ͭͷϨϙδτϦ͕ଘࡏ͢Δ

Slide 35

Slide 35 text

C7 • Stream • Connection • Data • URI • JSON Stream(TCPɺPipe etc..)ɺURIɺDataߏ଄ͳͲͷɺ ΞϓϦέʔγϣϯͷجຊ෦෼ͷ࢓༷ɺΠϯλʔϑΣʔε

Slide 36

Slide 36 text

• Request • Response • HTTP Status Code • Server • Middleware • Responder S4 WebͷͨΊͷ࢓༷ɺΠϯλʔϑΣʔε(rubyͷrackʹ͍ۙ)

Slide 37

Slide 37 text

D5 DB΍ϞσϧͷͨΊͷ࢓༷ɺΠϯλʔϑΣʔε ·ͩREADME.md͔͠ίϛοτ͞Ε͓ͯΒͣɺ ৄ͘͠͸Θ͔Γ·ͤΜʢരʣ

Slide 38

Slide 38 text

ͳͥɺOpen-Swift͕ඞཁͳͷ͔

Slide 39

Slide 39 text

• Swift୯ମʹ͸Web։ൃͷج൫͸ͳ͍ • CFͷAPIͷந৅౓͕௿͍ɺObjetive-CΛࣺ͖ͯΕͳ͍ • OSS൛ͷCF͸ະ࣮૷ͳ΋ͷ͕͋Γɺmac΄ͲϦονʹ ੔͍ͬͯͳ͍ɻ • αʔόʔଆͷ࣮૷ʹ͸ଟ͘ͷύϥμΠϜ͕ଘࡏ͠ɺΠϯ λʔϑΣʔε͕όϥόϥʹͳΓ͕ͪɻ • Server SideϓϩάϥϜݴޠ/؀ڥͷൃలͷཪʹ͸ɺ͍ͭ Ͱ΋ΤίγεςϜ͕͋ͬͨ

Slide 40

Slide 40 text

ࠓޙͷServer Side SwiftൃలͷͨΊɺΦϨΦϨ͸΍Ί·͠ΐ͏ ʢͱ͸͍͑ɺCore-Foundation͕Μ͹ͬͯʂʂʂʂʂʂʣ

Slide 41

Slide 41 text

͜͜·Ͱ͕Server Side Swiftʹؔ͢Δ͓࿩Ͱ͢ɻ

Slide 42

Slide 42 text

Slimaneͷ঺հ

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

• ExpressΛinspireͨܰ͠ྔWAF/Web Server • Node.jsͷ5ഒɺRevelͷ2ഒߴ଎ʢͩͬͨʣ • ΠϕϯτϧʔϓϞσϧɺϊϯϒϩοΩϯάI/O • Master/WorkerύλʔϯʹΑΔϚϧνεϨουରԠ • Core Foundationʹґଘ͠ͳ͍ • ϚΠΫϩαʔϏε޲͚ͷAPIαʔόʔ΍SwiftͰඇಉظωοτ ϫʔΫϓϩάϥϛϯάΛߦ͏͜ͱ͕ओ໨త Slimaneͱ͸

Slide 46

Slide 46 text

ৄ͘͠ݟ͍͖ͯ·͠ΐ͏

Slide 47

Slide 47 text

• Middleware/Router+HTTP Server • RailsͷΑ͏ͳFull StackϑϨʔϜϫʔΫͰ͸ͳ͍ • ඞཁʹԠͯ͡MɺVΛબ୒ • Network΍FileSystem͸Suv͕ఏڙ͍ͯ͠Δ΋ͷΛ ར༻͢Δ(Suv.TCPSocketɺSuv.FsͳͲ) Slimaneͷ࣮ଶ͸ͱͯ΋খ͍͞

Slide 48

Slide 48 text

Layer system call thread pool event loop Swift bindings of libuv Async net working platform TCP, UDP, Process, FS, DNS etc.. HTTP Server WAF(Routing, Middleware)

Slide 49

Slide 49 text

Runtime EVENT LOOP FILE SYSTEM NETWORK NETWORK System Operation & Register Callback COMPUTATION Operation Complete Trigger Callback Requests Suv(libuv wapper) epoll kqueue worker threads

Slide 50

Slide 50 text

Ͱ͸ɺSlimaneΛΠϯετʔϧͯ͠Έ·͠ΐ͏

Slide 51

Slide 51 text

ίϚϯυϥΠϯπʔϧ͕͋Γ·͢ɻ

Slide 52

Slide 52 text

$ npm i -g slimane-cli

Slide 53

Slide 53 text

➜ slimane git:(master) ✗ slimane new TestApp [~/Documents/program/oss/slimane/slimane] /Users/yuki/Documents/program/oss/Slimane/Slimane/TestApp ├── Makefile ├── Package.swift ├── Sources │ ├── app.swift │ └── main.swift └── public └── images └── Slimane_logo.jpg 3 directories, 5 files ➜ TestApp git:(master) ✗ slimane build ここでSPMの依存解決、コンパイルが走る。(結構時間かかります。) ➜ TestApp git:(master) ✗ .build/debug/TestApp [~/Documents/program/oss/slimane/slimane/TestApp] The server is listening at 0.0.0.0:3000 [pid:50928] Monday, August 01 2016 00:11:48 /

Slide 54

Slide 54 text

➜ slimane git:(master) ✗ slimane new TestApp [~/Documents/program/oss/slimane/slimane] /Users/yuki/Documents/program/oss/Slimane/Slimane/TestApp ├── Makefile ├── Package.swift ├── Sources │ ├── app.swift │ └── main.swift └── public └── images └── Slimane_logo.jpg 3 directories, 5 files ➜ TestApp git:(master) ✗ slimane build ここでSPMの依存解決、コンパイルが走る。(結構時間かかります。) ➜ TestApp git:(master) ✗ .build/debug/TestApp [~/Documents/program/oss/slimane/slimane/TestApp] The server is listening at 0.0.0.0:3000 [pid:50928] Monday, August 01 2016 00:11:48 / ϓϩδΣΫτͷεχϖοτΛ࡞੒

Slide 55

Slide 55 text

➜ slimane git:(master) ✗ slimane new TestApp [~/Documents/program/oss/slimane/slimane] /Users/yuki/Documents/program/oss/Slimane/Slimane/TestApp ├── Makefile ├── Package.swift ├── Sources │ ├── app.swift │ └── main.swift └── public └── images └── Slimane_logo.jpg 3 directories, 5 files ➜ TestApp git:(master) ✗ slimane build ここでSPMの依存解決、コンパイルが走る。(結構時間かかります。) ➜ TestApp git:(master) ✗ .build/debug/TestApp [~/Documents/program/oss/slimane/slimane/TestApp] The server is listening at 0.0.0.0:3000 [pid:50928] Monday, August 01 2016 00:11:48 /

Slide 56

Slide 56 text

➜ slimane git:(master) ✗ slimane new TestApp [~/Documents/program/oss/slimane/slimane] /Users/yuki/Documents/program/oss/Slimane/Slimane/TestApp ├── Makefile ├── Package.swift ├── Sources │ ├── app.swift │ └── main.swift └── public └── images └── Slimane_logo.jpg 3 directories, 5 files ➜ TestApp git:(master) ✗ slimane build ここでSPMの依存解決、コンパイルが走る。(結構時間かかります。) ➜ TestApp git:(master) ✗ .build/debug/TestApp [~/Documents/program/oss/slimane/slimane/TestApp] The server is listening at 0.0.0.0:3000 [pid:50928] Monday, August 01 2016 00:11:48 / SPMɺModuleMapͷґଘղܾ / ίϯύΠϧ

Slide 57

Slide 57 text

➜ slimane git:(master) ✗ slimane new TestApp [~/Documents/program/oss/slimane/slimane] /Users/yuki/Documents/program/oss/Slimane/Slimane/TestApp ├── Makefile ├── Package.swift ├── Sources │ ├── app.swift │ └── main.swift └── public └── images └── Slimane_logo.jpg 3 directories, 5 files ➜ TestApp git:(master) ✗ slimane build ここでSPMの依存解決、コンパイルが走る。(結構時間かかります。) ➜ TestApp git:(master) ✗ .build/debug/TestApp [~/Documents/program/oss/slimane/slimane/TestApp] The server is listening at 0.0.0.0:3000 [pid:50928] Monday, August 01 2016 00:11:48 /

Slide 58

Slide 58 text

➜ slimane git:(master) ✗ slimane new TestApp [~/Documents/program/oss/slimane/slimane] /Users/yuki/Documents/program/oss/Slimane/Slimane/TestApp ├── Makefile ├── Package.swift ├── Sources │ ├── app.swift │ └── main.swift └── public └── images └── Slimane_logo.jpg 3 directories, 5 files ➜ TestApp git:(master) ✗ slimane build ここでSPMの依存解決、コンパイルが走る。(結構時間かかります。) ➜ TestApp git:(master) ✗ .build/debug/TestApp [~/Documents/program/oss/slimane/slimane/TestApp] The server is listening at 0.0.0.0:3000 [pid:50928] Monday, August 01 2016 00:11:48 / Ϗϧυޙʹग़དྷ্͕ͬͨόΠφϦΛ࣮ߦ

Slide 59

Slide 59 text

ϒϥ΢βͰ֬ೝ

Slide 60

Slide 60 text

͜Ε͚ͩͷ؆୯ͳStepͰɺϓϩδΣΫτΛ։࢝Ͱ͖·͢ɻ

Slide 61

Slide 61 text

Slimaneىಈ·ͰͷίʔυΛ௥͍͖ͬͯ·͠ΐ͏

Slide 62

Slide 62 text

Routing

Slide 63

Slide 63 text

• get • put/patch • post • delete • option RouterͰରԠ͍ͯ͠Δϝιου

Slide 64

Slide 64 text

S4.AsyncResponder

Slide 65

Slide 65 text

S4.AsyncResponder શͯͷResponder͸AsyncResponderΛ࣮૷͢Δඞཁ͕͋Δ

Slide 66

Slide 66 text

struct HelloWorldResponser: AsyncResponder { public func respond(to request: Request, result: ((Void) throws -> Response) -> Void) result { Response(body: “Hello world") } } } Responder

Slide 67

Slide 67 text

app.get("/foo", HelloWorldResponser()) app.get(“/bar/:id”) { request, result in result { Response(body: "id is \(request.params["id"]!)") } } Routingͷίʔυ(ొ࿥)

Slide 68

Slide 68 text

Middleware

Slide 69

Slide 69 text

S4.AsyncMiddleware.swift

Slide 70

Slide 70 text

S4.AsyncMiddleware.swift શͯͷMiddleware͸AsyncMiddlewareΛ࣮૷͢Δඞཁ͕͋Δ

Slide 71

Slide 71 text

MiddlewareͷίʔυʢϩάΠϯνΣοΫʣ public struct AuthenticationMiddleware: AsyncMiddleware { public func respond(to request: Request, chainingTo next: AsyncResponder, result: ((Void) throws -> Response) -> Void) { if request.session?["isAuthorized"] != nil { return next.respond(to: request, result: result) } result { Response(status: .unauthorized) } } }

Slide 72

Slide 72 text

MiddlewareͷίʔυʢϩάΠϯνΣοΫʣ public struct AuthenticationMiddleware: AsyncMiddleware { public func respond(to request: Request, chainingTo next: AsyncResponder, result: ((Void) throws -> Response) -> Void) { if request.session?["isAuthorized"] != nil { return next.respond(to: request, result: result) } result { Response(status: .unauthorized) } } } ϩάΠϯ͍ͯͨ͠Β࣍ͷMiddlewareʹνΣΠϯ

Slide 73

Slide 73 text

MiddlewareͷίʔυʢϩάΠϯνΣοΫʣ public struct AuthenticationMiddleware: AsyncMiddleware { public func respond(to request: Request, chainingTo next: AsyncResponder, result: ((Void) throws -> Response) -> Void) { if request.session?["isAuthorized"] != nil { return next.respond(to: request, result: result) } result { Response(status: .unauthorized) } } } ϩάΠϯ͍ͯ͠ͳ͚Ε͹ɺ401Λฦ͢

Slide 74

Slide 74 text

app.use(StaticFileServingMiddleware()) app.use { request, next, result in print("Hello") next.respond(to: request, result: result) } Middlewareͷίʔυ(ొ࿥)

Slide 75

Slide 75 text

HTTP Server

Slide 76

Slide 76 text

import Slimane let app = Slimane() try app.listen()

Slide 77

Slide 77 text

૊Έ߹ΘͤΔͱ…. import Slimane let app = Slimane() app.use { req, next, result in print("middleware") next.respond(to: req, result: result) } app.get("/") { req, responder in responder { Response(body: "Hello iOSDC") } } try! app.listen() // => listening at 0.0.0.0:3000

Slide 78

Slide 78 text

Express Slimane const express = require('express'); const app = express(); app.use((req, res, next) => { console.log("middleware"); next(); }); app.get("/", (req, res) => { res.send("Hello iOSDC"); }); app.listen(); // => listening at 0.0.0.0:3000 import Slimane let app = Slimane() app.use { req, next, result in print("middleware") next.respond(to: req, result: result) } app.get("/") { req, responder in responder { Response(body: "Hello iOSDC") } } try! app.listen() // => listening at 0.0.0.0:3000 ίʔυΛExpressͱൺֱ

Slide 79

Slide 79 text

Express Slimane const express = require('express'); const app = express(); app.use((req, res, next) => { console.log("middleware"); next(); }); app.get("/", (req, res) => { res.send("Hello iOSDC"); }); app.listen(); // => listening at 0.0.0.0:3000 import Slimane let app = Slimane() app.use { req, next, result in print("middleware") next.respond(to: req, result: result) } app.get("/") { req, responder in responder { Response(body: "Hello iOSDC") } } try! app.listen() // => listening at 0.0.0.0:3000 ίʔυΛExpressͱൺֱ ׂͱࣅͯ·͢Ͷɻ

Slide 80

Slide 80 text

͜͜·Ͱ͕Slimaneʹؔ͢Δ࠷ॳͷεςοϓͱͳΓ·͢ɻ

Slide 81

Slide 81 text

࣍͸ɺSlimaneΛ֦ுͯ͠΋͏গ͠Ϧονʹͯ͠Έ·͠ΐ͏ɻ

Slide 82

Slide 82 text

View

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

RenderΛSlimaneʹΠϯετʔϧ͢Δ͜ͱͰɺςϯϓϨʔτΤ ϯδϯΛ࢖ͬͨಈతίϯςϯπΛ഑৴ՄೳʹͳΓ·͢ɻ

Slide 85

Slide 85 text

import Slimane import Render import MustacheViewEngine let app = Slimane() app.get("/") { req, result in result { let templateData: TemplateData = ["name": "Slimane"] let render = Render(engine: MustacheViewEngine(templateData: templateData), path: “index”) return Response(custom: render) } } try! app.listen() RenderΛ࢖ͬͯHTMLΛ഑৴͢Δྫ

Slide 86

Slide 86 text

import Slimane import Render import MustacheViewEngine let app = Slimane() app.get("/") { req, result in result { let templateData: TemplateData = ["name": "Slimane"] let render = Render(engine: MustacheViewEngine(templateData: templateData), path: “index”) return Response(costom: render) } } try! app.listen() RenderΛ࢖ͬͯHTMLΛ഑৴͢Δྫ MustacheViewEngineΛengineͱͯ͠ɺ RenderΦϒδΣΫτΛ࡞੒

Slide 87

Slide 87 text

import Slimane import Render import MustacheViewEngine let app = Slimane() app.get("/") { req, result in result { let templateData: TemplateData = ["name": "Slimane"] let render = Render(engine: MustacheViewEngine(templateData: templateData), path: “index”) return Response(custom: render) } } try! app.listen() RenderΛ࢖ͬͯHTMLΛ഑৴͢Δྫ Response.initializerͷcostom labelʹ render ObjectΛ౉͢

Slide 88

Slide 88 text

{{name}} Welcome to {{name}} views/index.mustache

Slide 89

Slide 89 text

JSON

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

Zewo/JSONͱBodyParserΛ࢖͍ɺJSONΛѻ͍·͢ɻ

Slide 92

Slide 92 text

import Slimane import BodyParser import JSON let app = Slimane() app.use(BodyParser.JSON()) app.post("/") { req, responder in print(req.json?[“string”].asString) print(req.json?[“number”].asNumber) print(req.json?[“object”].asObject) responder { let successJSON: JSON = ["message": "OK"] Response( status: .created, headers: Header([“Content-Type”: “application/json“]), body: try JSONMapSerializer.serialize(successJSON) ) } } application/jsonͷRequest/Responseͷྫ

Slide 93

Slide 93 text

import Slimane import BodyParser import JSON let app = Slimane() app.use(BodyParser.JSON()) app.post("/") { req, responder in print(req.json?[“string”].asString) print(req.json?[“number”].asNumber) print(req.json?[“object”].asObject) responder { let successJSON: Map = ["message": "OK"] Response( status: .created, headers: Header([“Content-Type”: “application/json“]), body: try JSONMapSerializer.serialize(successJSON) ) } } main.swift JSON BodyParserΛMiddlewareʹొ࿥

Slide 94

Slide 94 text

import Slimane import BodyParser import JSON let app = Slimane() app.use(BodyParser.JSON()) app.post("/") { req, responder in print(req.json?[“string”].asString) print(req.json?[“number”].asNumber) print(req.json?[“object”].asObject) responder { let successJSON: Map = ["message": "OK"] Response( status: .created, headers: Header([“Content-Type”: “application/json“]), body: try JSONMapSerializer.serialize(successJSON) ) } } main.swift JSON Value΁ͷΞΫηε

Slide 95

Slide 95 text

import Slimane import BodyParser import JSON let app = Slimane() app.use(BodyParser.JSON()) app.post("/") { req, responder in print(req.json?[“string”].asString) print(req.json?[“number”].asNumber) print(req.json?[“object”].asObject) responder { let successJSON: JSON = ["message": "OK"] Response( status: .created, headers: Header([“Content-Type”: “application/json“]), body: try JSONSerializer.serialize(successJSON) ) } } main.swift JSONܕ(Type safeͳߏ଄ܕ)ͰDictionaryΛੜ੒͠ɺ JSONSerializer.serializeʹ౉͢͜ͱͰJSONStringʹ

Slide 96

Slide 96 text

Blocking Operation

Slide 97

Slide 97 text

event loop͸ࢭΊͯ͸ͳΒͳ͍ʂ

Slide 98

Slide 98 text

• ϑΟϘφονͳͲͷಉظతͳ࠶ؼؔ਺ • ҉߸Խॲཧɺը૾ॲཧͳͲ • libmysqlͳͲΛ࢖ͬͨϒϩοΩϯάI/O event loop͕ࢭ·Δྫ

Slide 99

Slide 99 text

Ͱ΋ɺ͜ΕΒͷॲཧͬͯ࢖͑ͳ͘ͳͬͨΒࠔΓ·͢ΑͶʁ

Slide 100

Slide 100 text

Process.qwork

Slide 101

Slide 101 text

ίʔυ import Suv let onThread = { ctx in let sql = "select * from foo where bar = 1" let ctx.storage[“result”] = mysql_real_query(con, sql, sql.characters.count) let res = mysql_use_result(con) result = mysql_foo..... } let onFinish = { ctx in print(ctx.storage[“result”]) } Process.qwork(onThread: onThread, onFinish: onFinish)

Slide 102

Slide 102 text

ͱɺଞʹ΋·ͩ·ͩͨ͘͞Μ͋ΔͷͰ͕͢ɺ ࣌ؒͷ౎߹Ͱશͯ͝঺հͰ͖ͣɺɺ

Slide 103

Slide 103 text

https://github.com/slimane-swift/ ڵຯ͕͋Δํ͸ɺ SlimaneͷϓϩδΣΫτϖʔδΛੋඇޚཡ͍ͩ͘͞ɻ

Slide 104

Slide 104 text

ͦΖͦΖಈ͍͍ͯΔͱ͜Ζ͕Έ͍ͨͰ͢ΑͶʁ

Slide 105

Slide 105 text

Ͱ͸ɺ

Slide 106

Slide 106 text

SlimaneΛ࢖࣮ͬͨફతͳWeb Application ͷ࣮૷ʹ޲͚ͯ࿩͍͖ͯ͠·͢ɻ

Slide 107

Slide 107 text

ྫ͑͹ɺGithubΞΧ΢ϯτΛ࢖ͬͨChatαʔϏε ͷ࣮૷Λߟ͑ͯΈ·͠ΐ͏ɻ

Slide 108

Slide 108 text

• HTTPS Client • JSON • Session • DataBaseClient • View • Web socket Server/Client • Deploy SlimaneҎ֎ͰɺGithubΞΧ΢ϯτΛ࢖ͬͨ ChatαʔϏεʹඞཁͳ΋ͷ

Slide 109

Slide 109 text

• HTTPS Client -> slimane-swift/SecureHanger • JSON • Session • DataBaseClient • View • Web socket • Deploy SlimaneҎ֎ͰɺTwitterΞΧ΢ϯτΛ࢖ͬͨ ChatΞϓϦʹඞཁͳ΋ͷ

Slide 110

Slide 110 text

• HTTPS Client -> slimane-swift/SecureHanger • JSON -> Zewo/JSON, slimane-swift/BodyParser • Session • DataBaseClient • View • Web socket • Deploy SlimaneҎ֎ͰɺTwitterΞΧ΢ϯτΛ࢖ͬͨ ChatΞϓϦʹඞཁͳ΋ͷ

Slide 111

Slide 111 text

• HTTPS Client -> slimane-swift/SecureHanger • JSON -> Zewo/JSON, slimane-swift/BodyParser • Session -> slimane-swift/SessionMiddleware • DataBaseClient • View • Web socket • Deploy SlimaneҎ֎ͰɺTwitterΞΧ΢ϯτΛ࢖ͬͨ ChatΞϓϦʹඞཁͳ΋ͷ

Slide 112

Slide 112 text

• HTTPS Client -> slimane-swift/SecureHanger • JSON -> Zewo/JSON, slimane-swift/BodyParser • Session -> slimane-swift/SessionMiddleware • DataBaseClient -> noppoMan/swift-redis • View • Web socket • Deploy SlimaneҎ֎ͰɺTwitterΞΧ΢ϯτΛ࢖ͬͨ ChatΞϓϦʹඞཁͳ΋ͷ

Slide 113

Slide 113 text

• HTTPS Client -> slimane-swift/SecureHanger • JSON -> Zewo/JSON, slimane-swift/BodyParser • Session -> slimane-swift/SessionMiddleware • DataBaseClient -> noppoMan/swift-redis • View -> slimane-swift/Render • Web socket • Deploy SlimaneҎ֎ͰɺTwitterΞΧ΢ϯτΛ࢖ͬͨ ChatΞϓϦʹඞཁͳ΋ͷ

Slide 114

Slide 114 text

• HTTPS Client -> slimane-swift/SecureHanger • JSON -> Zewo/JSON, slimane-swift/BodyParser • Session -> slimane-swift/SessionMiddleware • DataBaseClient -> noppoMan/swift-redis • View -> slimane-swift/Render • Web socket -> slimane-swift/WS • Deploy SlimaneҎ֎ͰɺTwitterΞΧ΢ϯτΛ࢖ͬͨ ChatΞϓϦʹඞཁͳ΋ͷ

Slide 115

Slide 115 text

• HTTPS Client -> slimane-swift/SecureHanger • JSON -> Zewo/JSON, slimane-swift/BodyParser • Session -> slimane-swift/SessionMiddleware • DataBaseClient -> noppoMan/swift-redis • View -> slimane-swift/Render • Web socket -> slimane-swift/WS • Deploy -> Suv.Cluster and Suv.Signal SlimaneҎ֎ͰɺTwitterΞΧ΢ϯτΛ࢖ͬͨ ChatΞϓϦʹඞཁͳ΋ͷ

Slide 116

Slide 116 text

શ෦࡞Γ·ͨ͠ (ʆʀωʀ´)

Slide 117

Slide 117 text

Ͱ͸ɺ࣮ࡍʹDemoͰಈ͔ͯ͠Έ·͠ΐ͏ɻ

Slide 118

Slide 118 text

No content

Slide 119

Slide 119 text

͜ΕΛ࢖ͬͯDemoΛߦ͍͖ͬͯ·͢ɻ ιʔείʔυΛݟ͍ͨํ͸ੋඇ git cloneͯ͠Έ ͍ͯͩ͘͞ɻ

Slide 120

Slide 120 text

publish subscribe storage(Redis) Redis Slimane apps ຊ೔ͷDemoͷߏ੒(on AWS EC2 t2.medium) Client

Slide 121

Slide 121 text

SwiftͰ΋ϞμϯͳWebαʔϏεͷόοΫΤϯυΛ։ൃՄೳͱ ͍͏͜ͱ͕෼͔Γ·ͨ͠ʂ

Slide 122

Slide 122 text

·ͱΊ

Slide 123

Slide 123 text

• ݱࡏ͸Swiftݴޠ΋ϑϨʔϜϫʔΫ΋੒௕ஈ֊ • SwiftͰ΋ؤுΕ͹ϞμϯͳWebΞϓϦ͕ॻ͚Δ • ૑ੈهͳͨΊɺ͕Μ͕ΜίϯτϦϏϡʔλʔʹͳ ΕΔ • ݱࡏͷݴޠ࢓༷తʹඇಉظFW͸͋·Γ͓͢͢Ί͠ ·ͤΜʢসʣ • Swift੡ͷWeb Server͸ߴ଎ʹಈ࡞͢Δ

Slide 124

Slide 124 text

• TLS/HTTP 2.0 • QUIC • Async/Await • Actors or Coroutines(Other Project) Next Step

Slide 125

Slide 125 text

ੋඇҰॹʹSlimaneΛ࡞Γ·͠ΐ͏ʂʂʂ

Slide 126

Slide 126 text

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