Slide 1

Slide 1 text

Building the Server-side Swift ecosystem Ian Partridge Swift lead IBM Runtimes @alfa

Slide 2

Slide 2 text

A long time ago, on a stage (not so) far away…

Slide 3

Slide 3 text

☀ A new hope https://swift.org/server/

Slide 4

Slide 4 text

Incubation process Forum pitch Sandbox Graduated Archived Forum proposal Incubation

Slide 5

Slide 5 text

SwiftNIO • Asynchronous network application framework • High performance protocol implementations • HTTP • WebSocket • SwiftNIO 2 • HTTP/2 in pure Swift! • TLS on BoringSSL • SwiftNIO = 32kloc. SwiftNIO tests = 34kloc. /apple/swift-nio/

Slide 6

Slide 6 text

Logging import Logging var logger = Logger(label: "com.acme.app.main") logger.info("Hello World!”) 2019-09-07T18:30:02+0000 info: Hello world! /apple/swift-log/ do { try App.startup() } catch { logger.fatal("Boom") 2019-09-07T18:30:02+0000 fatal: Boom } logger[metadataKey: "current-request"] = "\(UUID())" logger.info("new request”) 2019-09-07T18:30:02+0000 info: current-request= F8633013-3DD8-481C-9256-B296E43443ED new request logger.logLevel = .debug

Slide 7

Slide 7 text

Logging backends /vapor/console-kit/ /IBM-Swift/HeliumLogger/ /Adorkable/swift-log-format-and-pipe /ianpartridge/swift-log-syslog /chrisaljoudi/swift-log-oslog /Brainfinance/StackdriverLogging

Slide 8

Slide 8 text

Metrics import Metrics let counter = Counter(label: "com.acme.app.numberOfRequests") counter.increment(by: 5) /apple/swift-metrics/ let recorder = Recorder(label: "com.acme.app.responseSizes") recorder.record(8) let gauge = Gauge(label: "com.acme.app.threadCount") gauge.record(10) let timer = Timer(label: "com.acme.app.requestDuration") timer.recordMilliseconds(3.42)

Slide 9

Slide 9 text

Metrics backends /MrLotU/SwiftPrometheus /tomerd/swift-statsd-client

Slide 10

Slide 10 text

PostgreSQL /vapor/postgres-nio/

Slide 11

Slide 11 text

PostgreSQL /vapor/postgres-nio/ import PostgresNIO // Connect to the database let futureConnection = try PostgresConnection.connect( to: .makeAddressResolvingHost("my.psql.server", port: 5432), on: eventLoop) // Wait for the EventLoopFuture to resolve let connection = futureConnection.wait() // Run a query, getting an EventLoopFuture<[PostgresRow]> let futureVersion = try connection.simpleQuery("SELECT version()") let version = futureVersion.wait() print(version) // [["version": "11.0.0"]] let futureRows = try connection.query("SELECT * FROM cars WHERE name = $1", ["Mustang"]) futureRows.whenSuccess { rows in print(rows) // [["id": 24, "name": "Mustang"]] }

Slide 12

Slide 12 text

Redis /Mordil/swift-redi-stack/

Slide 13

Slide 13 text

Redis /Mordil/swift-redi-stack/ import RediStack let connection = RedisConnection.connect( to: try .init(ipAddress: "127.0.0.1", port: RedisConnection.defaultPort), on: eventLoop ).wait() let result = try connection.set("my_key", to: "some value") .flatMap { return connection.get("my_key") } .wait() print(result) // Optional("some value”)

Slide 14

Slide 14 text

HTTP Client /swift-server/async-http-client/ APNs library /kylebrowning/APNSwift ✨ Other libraries

Slide 15

Slide 15 text

Docker /apple/swift-docker • Image sizes • Swift 4.2: 1.48GB • apt-get -q install -y make libc6-dev clang-3.8 curl libedit- dev libpython2.7 libicu-dev libssl-dev libxml2 tzdata git libcurl4-openssl- dev pkg-config • Swift 5.0: 1.35GB
 • “Slim images” • Swift 5.0-slim: 194MB

Slide 16

Slide 16 text

Docker /apple/swift-docker FROM swift:5.0.3 as build WORKDIR /workdir COPY . . RUN swift build -c release FROM swift:5.0.3-slim as run WORKDIR /workdir COPY --from=build /workdir . CMD [".build/x86_64-unknown-linux/debug/docker-test"]

Slide 17

Slide 17 text

Linux releases • Many months between releases • Agreement from Swift core team for Linux-only releases • Increased cadence • 5.0.0 - March 25 • 5.0.1 - April 18 • 5.0.2 - July 15 • 5.0.3 - August 30 • 5.0.4 - open now!

Slide 18

Slide 18 text

The future… • More databases • MongoDB • MySQL • … • Backtraces on crashes • Distributed tracing

Slide 19

Slide 19 text

www.appsody.dev

Slide 20

Slide 20 text

Thank you www.swift.org/server
 forums.swift.org/c/server
 ☁ www.appsody.dev
 IBM booth