This talk was made for CocoaHeads Kyiv #13 which took place Dec 16 2017.
Server-side on Swiftby Volodymyr Shevchenko
View Slide
What for?- We will do mobile better- Can’t build App on our own- Backend is a black-box with API
Why Swift???
Why Swift?- we know Swift- we can reuse some code- Swift is faster
Kitura Perfect Vapor ZewoWhat do we have:
⭐ GitHub Req/sec Looks Good?Kitura 6K 2.1K NoPerfect 12.3K 4.2K YesVapor 11.6K 3.2K YesZewo 1.7K 1.7K NoBenchmarks of the TopServer-Side Swift frameworks
VaporPerfect
Let’s build something
Pet Store- Authorization- Domain CRUD- REST API
Check LocalCredentialsCreate newUserCheck FBCredentialsCreate SessionObjectSuccess?Facebook Database CacheYesNoERROR responseTOKEN response
Success?DatabaseCacheYesProceed with request401 responseFetch sessionfrom CacheFetch sessionfrom DBSuccess?No NoYes
User PetOrderTagCategoryDomain relations*
Our stack:- Perfect as a framework- Mongo DB as storage- StORM as ORM
Few words from Cap…
Leaks are evil
Crashes are evil
!Force unwrap is evil
CocoapodsCarthageSPM
XCode just an editor
≠
- this won’t compile on Linux:- after fix:
Foundation is NOT ported for100%https://github.com/apple/swift-corelibs-foundation/blob/master/Docs/Status.md……
≠(curl + libssl)(curl + openssl)
[“a”, “b”, ”c”] -> “a, b, c”Bugs in MongoDBStORM
[“a”, “b”, ”c”] -> “a, b, c”- Work without ORM- Switch to an other DB- Switch to Vapor + Fluent- Fix bug
Nested objects areMongoDBStORMnot supported
¯\_(ツ)_/¯
Lets Deploy
Where?
Where?- Amazon EC2- Microsoft Azure- Google Cloud- Digital Ocean- Linode- Alibaba cloud- IBM cloud- Packet- Vultr- …
How to deploy?
Perfect Assistant
Docker
Plain
2) Connect to remotemachine via SSH3) Install all requiredtools and libs4) Setup Databaseserver5) Clone sources fromGit repo6) Compile7) Configure firewall toallow http(s) traffic8) Run executable1) Create remotevirtual machine onselected providerPlain Deploy
Performance- apib tool- Latency (MIN, MAX, AVG)- Requests/second
Performancereq/sec Lat, min Lat, max Lat, avgHealthcheck 26.8K 0.6 42 7.4Empty Auth 739 9 643 269Auth + Read 407 10.1 952 487Auth + Write 389 9.4 1028 511
Scale- Vertical- Horizontal
Database is ServerDatabase ServerAPI ServerNetwork
Scaled infrastructureDatabase ServerAPI Server IIAPI Server IAPI Server IIILoad Balancer
0500100015002000Empty Auth Auth + read Auth + writeRequests per second
0150300450600Empty Auth Auth + read Auth + writeAverage latency, ms
Cluster Performancereq/sec Lat, min Lat, max Lat, avgHealthcheck 21.1K 1.4 1105 9.4Empty Auth 1820 4.7 473 109Auth + Read 897 3.1 243 55.6Auth + Write 916 13 617 217.5
Questions?
Thanks!