Upgrade to Pro — share decks privately, control downloads, hide ads and more …

'Server-side on Swift' by Volodymyr Shevchenko

'Server-side on Swift' by Volodymyr Shevchenko

This talk was made for CocoaHeads Kyiv #13 which took place Dec 16 2017.

Db84cf61fdada06b63f43f310b68b462?s=128

CocoaHeads Ukraine

December 16, 2017
Tweet

More Decks by CocoaHeads Ukraine

Other Decks in Programming

Transcript

  1. Server-side on Swift by Volodymyr Shevchenko

  2. What for? - We will do mobile better - Can’t

    build App on our own - Backend is a black-box with API
  3. Why Swift? ??

  4. Why Swift? - we know Swift - we can reuse

    some code - Swift is faster
  5. Kitura Perfect Vapor Zewo What do we have:

  6. ⭐ GitHub Req/sec Looks Good? Kitura 6K 2.1K No Perfect

    12.3K 4.2K Yes Vapor 11.6K 3.2K Yes Zewo 1.7K 1.7K No Benchmarks of the Top Server-Side Swift frameworks
  7. Vapor Perfect

  8. Let’s build something

  9. Pet Store - Authorization - Domain CRUD - REST API

  10. Check Local Credentials Create new User Check FB Credentials Create

    Session Object Success? Facebook Database Cache Yes No ERROR response TOKEN response
  11. Success? Database Cache Yes Proceed with request 401 response Fetch

    session from Cache Fetch session from DB Success? No No Yes
  12. User Pet Order Tag Category Domain relations *

  13. Our stack: - Perfect as a framework - Mongo DB

    as storage - StORM as ORM
  14. Few words from Cap…

  15. Leaks are evil

  16. None
  17. Crashes are evil

  18. ! Force unwrap is evil

  19. Cocoapods Carthage SPM

  20. XCode just an editor

  21. - this won’t compile on Linux: - after fix:

  22. Foundation is NOT ported for 100% https://github.com/apple/swift-corelibs-foundation/blob/master/Docs/Status.md … …

  23. ≠ (curl + libssl) (curl + openssl)

  24. [“a”, “b”, ”c”] -> “a, b, c” Bugs in MongoDBStORM

  25. [“a”, “b”, ”c”] -> “a, b, c” - Work without

    ORM - Switch to an other DB - Switch to Vapor + Fluent - Fix bug
  26. Nested objects are MongoDBStORM not supported

  27. ¯\_(ツ)_/¯

  28. Lets Deploy

  29. Where?

  30. Where? - Amazon EC2 - Microsoft Azure - Google Cloud

    - Digital Ocean - Linode - Alibaba cloud - IBM cloud - Packet - Vultr - …
  31. Where? - Amazon EC2 - Microsoft Azure - Google Cloud

    - Digital Ocean - Linode - Alibaba cloud - IBM cloud - Packet - Vultr - …
  32. How to deploy?

  33. Perfect Assistant

  34. Perfect Assistant

  35. Docker

  36. Plain

  37. 2) Connect to remote machine via SSH 3) Install all

    required tools and libs 4) Setup Database server 5) Clone sources from Git repo 6) Compile 7) Configure firewall to allow http(s) traffic 8) Run executable 1) Create remote virtual machine on selected provider Plain Deploy
  38. Performance - apib tool - Latency (MIN, MAX, AVG) -

    Requests/second
  39. Performance req/sec Lat, min Lat, max Lat, avg Healthcheck 26.8K

    0.6 42 7.4 Empty Auth 739 9 643 269 Auth + Read 407 10.1 952 487 Auth + Write 389 9.4 1028 511
  40. Scale - Vertical - Horizontal

  41. Database is Server Database Server API Server Network

  42. Scaled infrastructure Database Server API Server II API Server I

    API Server III Load Balancer
  43. 0 500 1000 1500 2000 Empty Auth Auth + read

    Auth + write Requests per second
  44. 0 150 300 450 600 Empty Auth Auth + read

    Auth + write Average latency, ms
  45. Cluster Performance req/sec Lat, min Lat, max Lat, avg Healthcheck

    21.1K 1.4 1105 9.4 Empty Auth 1820 4.7 473 109 Auth + Read 897 3.1 243 55.6 Auth + Write 916 13 617 217.5
  46. Questions?

  47. Thanks!