Server Side Swift
Hüseyin APTİOĞLU | Software Infrastructure
Agenda
• Crash-Course Swift
• Swift Package Manager
• Server Side
• Benchmarking
Swift
• 1940s -> 9 programming languages
• 1950s -> 58 programming languages
• Fortran (concept)
• Fortran II
• Lisp
• …
• 1960s -> 113 programming languages
• Fortran IV
• Basic
• Cobol
• …
• 1970s -> 170 programming languages
• Pascal
• Smaltalk
• C
• ….
• 1980s -> 231 programming languages
• Turbo Pascal
• Erlang
• C ++
• Objective C
• ….
http://www.slideshare.net/GiordanoScalzo/the-joy-of-serverside-swift-development?qid=c2bc7c73-5bac-47e1-b834-45ac4b35edde&v=&b=&from_search=7
Swift
• 1990s -> 292 programming languages
• Python
• Java
• Ruby
• Visual Basic
• Delphi
• ….
• 2000s -> 339 programming languages
• C#
• Scala
• Go
• ….
• 2010s -> 354 programming languages
• Rust
• Kotlin
• Elm
• ….
http://www.slideshare.net/GiordanoScalzo/the-joy-of-serverside-swift-development?qid=c2bc7c73-5bac-47e1-b834-45ac4b35edde&v=&b=&from_search=7
Swift
• 355. Swift
• v1.0 in September 2014
• Opened in Dec 2015
• v2.2 first ver. in the Open
• v3.0.1
Swift Tour
Mutable
Variables
Immutable
Swift Tour
Mutable
Type Inference
Immutable
Swift Tour
Optionals
Swift Tour
Function parameter names
Swift Tour
Guard Statement
Swift Tour
Closures
Swift Tour
Tuples
Swift Tour
Extensions
Swift Tour
and more …
• Enumerations
• Inheritance
• Initialization
• Error Handling
• Type Casting
• Generics
• Access Control
• …
• …
Swift
Why is Swift a good choice for server-side ?
• Fast
• Modern
• Safe
• Interactive
• Open Source
• Apple
Server-side App Trade Off
Why is Swift a good choice for server-side ?AppPerformance
Developer Productivity
C
C++
Obj.C
Java
Perl
JavaScript
Python
Ruby
Lua
Groovy
ARC
Automatic Reference Counting (ARC)
Swift manages the memory for you, but unlike many other high level
languages, it doesn’t use a garbage collector to do this.
- No periodically running
- No pause
- The CPU cycles for your own program
Automatic Reference Counting (ARC)
LLVM
LLVM is actually an umbrella project that includes a variety of compilers and low
level tools
In short, LLVM compiles your code to a platform-neutral Intermediary Representation (IR), which can then be
optimised and converted to the desired architecture. This allows all platform optimisation efforts to be
concentrated in one place
For Swift, Apple added a new layer to this architecture: the Swift Intermediate Language (SIL).
SPM
Swift Package Manager
• Part of Swift 3
• Init project
• Generate Xcode Proj
• Resolve dependencies
The Swift Package Manager is a tool for managing the distribution of Swift
code. It’s integrated with the Swift build system to automate the process
of downloading, compiling, and linking dependencies.
Package.swift
Swift
• Swift is easier to read
• Swift is easier to maintain
• Swift is safe
• Swift is unified with memory management
• Swift requires less code
Swift vs Objective-C
Swift
Swift vs Java
Swift version 3.0-dev (LLVM 491f98861f, Clang 2ff6ce54d0, Swift fd4bd4c965)
swift-DEVELOPMENT-SNAPSHOT-2016-11-29-a-ubuntu16.04
Target: x86_64-unknown-linux-gnu
java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)
https://benchmarksgame.alioth.debian.org/u64q/swift.html
II. Most Loved
GitHub - apple/swift
Server Side Swift
open-source
Officially, only Linux is supported
open-source
Unofficially
Swift on Android
Install swift to linux
• Install required dependencies
$ sudo apt-get install clang libicu-dev
• Download the latest swift binary release from https://swift.org/download/#releases
• Extract the archive
$ tar xzf swift-<VERSION>-<PLATFORM>.tar.gz
• Add the Swift toolchain to your path
$ export PATH=/path/to/usr/bin:"${PATH}"
• Test with REPL (Read Eval Print Loop)
Swift Scripts
#!/usr/bin/env swift
let fruits = ["Banana", "Mango", "Apple", "Orange"]
let sortedFruits = fruits.sorted{$0 < $1}
print(sortedFruits)
chmod +x sort.swift
./sort.swift
Creating an Executable
Contents of file hello.swift
println("Hello world")
$ swiftc hello.swift
$ ./hello Hello world
Web Frameworks
• Perfect (9871)
• Vapor (7786)
• IBM Kitura (5002)
• Swifton (2042)
• Swifter (1852)
• Zewo (1502)
• …
• ...
• ...
Perfect 2.0
Vapor
Kitura
Benchmarking
wrk -d 10m -t 4 -c 20 http://10.0.1.11:(PORT)/blog
Benchmarking
wrk -d 10m -t 4 -c 20 http://10.0.1.11:(PORT)/json
Ready for Production?
Not Yet !!!
- Web frameworks < 1 year
- Server = Maturity
IBTECH

Server Side Swift

  • 1.
    Server Side Swift HüseyinAPTİOĞLU | Software Infrastructure
  • 2.
    Agenda • Crash-Course Swift •Swift Package Manager • Server Side • Benchmarking
  • 3.
    Swift • 1940s ->9 programming languages • 1950s -> 58 programming languages • Fortran (concept) • Fortran II • Lisp • … • 1960s -> 113 programming languages • Fortran IV • Basic • Cobol • … • 1970s -> 170 programming languages • Pascal • Smaltalk • C • …. • 1980s -> 231 programming languages • Turbo Pascal • Erlang • C ++ • Objective C • …. http://www.slideshare.net/GiordanoScalzo/the-joy-of-serverside-swift-development?qid=c2bc7c73-5bac-47e1-b834-45ac4b35edde&v=&b=&from_search=7
  • 4.
    Swift • 1990s ->292 programming languages • Python • Java • Ruby • Visual Basic • Delphi • …. • 2000s -> 339 programming languages • C# • Scala • Go • …. • 2010s -> 354 programming languages • Rust • Kotlin • Elm • …. http://www.slideshare.net/GiordanoScalzo/the-joy-of-serverside-swift-development?qid=c2bc7c73-5bac-47e1-b834-45ac4b35edde&v=&b=&from_search=7
  • 5.
    Swift • 355. Swift •v1.0 in September 2014 • Opened in Dec 2015 • v2.2 first ver. in the Open • v3.0.1
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
    Swift Tour and more… • Enumerations • Inheritance • Initialization • Error Handling • Type Casting • Generics • Access Control • … • …
  • 15.
    Swift Why is Swifta good choice for server-side ? • Fast • Modern • Safe • Interactive • Open Source • Apple
  • 16.
    Server-side App TradeOff Why is Swift a good choice for server-side ?AppPerformance Developer Productivity C C++ Obj.C Java Perl JavaScript Python Ruby Lua Groovy
  • 17.
    ARC Automatic Reference Counting(ARC) Swift manages the memory for you, but unlike many other high level languages, it doesn’t use a garbage collector to do this. - No periodically running - No pause - The CPU cycles for your own program
  • 18.
  • 19.
    LLVM LLVM is actuallyan umbrella project that includes a variety of compilers and low level tools In short, LLVM compiles your code to a platform-neutral Intermediary Representation (IR), which can then be optimised and converted to the desired architecture. This allows all platform optimisation efforts to be concentrated in one place For Swift, Apple added a new layer to this architecture: the Swift Intermediate Language (SIL).
  • 20.
    SPM Swift Package Manager •Part of Swift 3 • Init project • Generate Xcode Proj • Resolve dependencies The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies. Package.swift
  • 21.
    Swift • Swift iseasier to read • Swift is easier to maintain • Swift is safe • Swift is unified with memory management • Swift requires less code Swift vs Objective-C
  • 22.
    Swift Swift vs Java Swiftversion 3.0-dev (LLVM 491f98861f, Clang 2ff6ce54d0, Swift fd4bd4c965) swift-DEVELOPMENT-SNAPSHOT-2016-11-29-a-ubuntu16.04 Target: x86_64-unknown-linux-gnu java version "1.8.0_92" Java(TM) SE Runtime Environment (build 1.8.0_92-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode) https://benchmarksgame.alioth.debian.org/u64q/swift.html
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
    Install swift tolinux • Install required dependencies $ sudo apt-get install clang libicu-dev • Download the latest swift binary release from https://swift.org/download/#releases • Extract the archive $ tar xzf swift-<VERSION>-<PLATFORM>.tar.gz • Add the Swift toolchain to your path $ export PATH=/path/to/usr/bin:"${PATH}" • Test with REPL (Read Eval Print Loop)
  • 30.
    Swift Scripts #!/usr/bin/env swift letfruits = ["Banana", "Mango", "Apple", "Orange"] let sortedFruits = fruits.sorted{$0 < $1} print(sortedFruits) chmod +x sort.swift ./sort.swift
  • 31.
    Creating an Executable Contentsof file hello.swift println("Hello world") $ swiftc hello.swift $ ./hello Hello world
  • 32.
    Web Frameworks • Perfect(9871) • Vapor (7786) • IBM Kitura (5002) • Swifton (2042) • Swifter (1852) • Zewo (1502) • … • ... • ...
  • 33.
  • 34.
  • 35.
  • 36.
    Benchmarking wrk -d 10m-t 4 -c 20 http://10.0.1.11:(PORT)/blog
  • 37.
    Benchmarking wrk -d 10m-t 4 -c 20 http://10.0.1.11:(PORT)/json
  • 38.
    Ready for Production? NotYet !!! - Web frameworks < 1 year - Server = Maturity
  • 39.