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.

CocoaHeads Ukraine

December 16, 2017
Tweet

More Decks by CocoaHeads Ukraine

Other Decks in Programming

Transcript

  1. Server-side on Swift
    by Volodymyr Shevchenko

    View Slide

  2. What for?
    - We will do mobile better
    - Can’t build App on our own
    - Backend is a black-box with API

    View Slide

  3. Why Swift?
    ??

    View Slide

  4. Why Swift?
    - we know Swift
    - we can reuse some code
    - Swift is faster

    View Slide

  5. Kitura Perfect Vapor Zewo
    What do we have:

    View Slide

  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

    View Slide

  7. Vapor
    Perfect

    View Slide

  8. Let’s build something

    View Slide

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

    View Slide

  10. Check Local
    Credentials
    Create new
    User
    Check FB
    Credentials
    Create Session
    Object
    Success?
    Facebook Database Cache
    Yes
    No
    ERROR response
    TOKEN response

    View Slide

  11. Success?
    Database
    Cache
    Yes
    Proceed with request
    401 response
    Fetch session
    from Cache
    Fetch session
    from DB
    Success?
    No No
    Yes

    View Slide

  12. User Pet
    Order
    Tag
    Category
    Domain relations
    *

    View Slide

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

    View Slide

  14. Few words from Cap…

    View Slide

  15. Leaks are evil

    View Slide

  16. View Slide

  17. Crashes are evil

    View Slide

  18. !
    Force unwrap is evil

    View Slide

  19. Cocoapods
    Carthage
    SPM

    View Slide

  20. XCode just an editor

    View Slide


  21. View Slide

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

    View Slide

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


    View Slide


  24. (curl + libssl)
    (curl + openssl)

    View Slide

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

    View Slide

  26. [“a”, “b”, ”c”] -> “a, b, c”
    - Work without ORM
    - Switch to an other DB
    - Switch to Vapor + Fluent
    - Fix bug

    View Slide

  27. Nested objects are
    MongoDBStORM
    not supported

    View Slide

  28. ¯\_(ツ)_/¯

    View Slide

  29. Lets Deploy

    View Slide

  30. Where?

    View Slide

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

    View Slide

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

    View Slide

  33. How to deploy?

    View Slide

  34. Perfect Assistant

    View Slide

  35. Perfect Assistant

    View Slide

  36. Docker

    View Slide

  37. Plain

    View Slide

  38. 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

    View Slide

  39. Performance
    - apib tool
    - Latency (MIN, MAX, AVG)
    - Requests/second

    View Slide

  40. 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

    View Slide

  41. Scale
    - Vertical
    - Horizontal

    View Slide

  42. Database is Server
    Database Server
    API Server
    Network

    View Slide

  43. Scaled infrastructure
    Database Server
    API Server II
    API Server I
    API Server III
    Load Balancer

    View Slide

  44. 0
    500
    1000
    1500
    2000
    Empty Auth Auth + read Auth + write
    Requests per second

    View Slide

  45. 0
    150
    300
    450
    600
    Empty Auth Auth + read Auth + write
    Average latency, ms

    View Slide

  46. 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

    View Slide

  47. Questions?

    View Slide

  48. Thanks!

    View Slide