4. NSAgora - April 2019 4
Contents
Introduction
Why Swift on the server?
Current Swift web server toolkits
Benchmarks
Q&A
4
NSAgora The state of server-side swift
I
II
III
IV
V
13. import Foundation
// Immutable array - type inferred to an array of Strings
let swiftProperties = ["multi-paradigm", "compiled", "expressive", "type-safe"]
// Function that accepts an optional parameter and returns an array of Int
func getDashedPropertiesLenghts(in array: [String]?) -> [Int] {
guard let properties = array else {
// Check if 'array' is nil and return and empty array
return []
}
// An array conforms to the 'Sequence' protocol
let filtered = properties.filter { property -> Bool in
return property.contains("-")
}
// Transform the array of Strings into an array of its members length
return filtered.map({ $0.count })
}
// Call the method
_ = getDashedPropertiesLenghts(in: swiftProperties)
23. 11
Since being made open source in December 2015
when it only supported Darwin machines, we have
seen an immense effort from the Swift community to
bring Swift to other platforms.
Up until now over 250 proposals have been accepted
and implemented in the Swift language and toolchain
and over 23,000 pull requests to make the Foundation
framework available on Linux.
It also runs down the other scale on Raspberry Pi and
considerable efforts are being made to make Swift
available for Android as well.
74. 28
There are a couple of Swift web toolkits available at
this point.
IBM continuously invests in Swift on the cloud as well
as in Kitura, their Swift web toolkit, but that's not all.
There are 3 more notable Swift toolkits out there with
Perfect, Vapor and Zewo and at least 20 other
projects.
86. 37
To have a better idea of how well Swift
could do on the cloud we benchmarked
it against some of the most popular
toolkits available.
From all of the toolkits available we went
with Perfect because it fared the best
out of the available frameworks at this
moment.
To test how well it is doing we used two
DigitalOcean VM instances located in
Amsterdam.
94. 39
1.JSON
Return a "{ hello: world }" JSON
2.COMPUTATION
Compute the 10.000th Fibonacci
number
95. 39
1.JSON
Return a "{ hello: world }" JSON
2.COMPUTATION
Compute the 10.000th Fibonacci
number
3.LISTING
Return from a MySQL database all the
countries in the world in a JSON
96. 39
1.JSON
Return a "{ hello: world }" JSON
2.COMPUTATION
Compute the 10.000th Fibonacci
number
3.LISTING
Return from a MySQL database all the
countries in the world in a JSON
https://github.com/cyupa/web-rest-api-benchmark