📜 ⬆️ ⬇️

CocoaConf DC 2016: Swift server side

In September 2016, our iOS developers visited Washington at the CocoaConf DC conference, where they gained a lot of interesting experience. There were a lot of fascinating reports in different directions, different levels of complexity. In this article we would like to talk about the report, which was interesting for its unusual and novelty - “Creating a Server Side Application with your Favorite Language: Swift!” By Jonathan Guthrie ( Twitter , Github ). Jonathan is one of the developers of Perfect - a framework that allows you to use Swift language in the development of server applications. This topic is interesting to many iOS-developers, because most of the "home" ideas stop the problem of implementing the server side. At the same time, the study of additional languages ​​or the involvement of outsiders does not add enthusiasm.

The article focuses on the theoretical part of the issue, and not on the code. Practical guides can be found in the "Additional Materials" section, or in a search engine.

Why Swift?


At the beginning of the report, many in the room had a question about the performance of the Swift-server. After all, most developers have probably come across the fact that new solutions for implementing other types of applications in their “native” language have side effects in the form of a drop in performance. A vivid example of such a solution, familiar to iOS developers, is PhoneGap. This framework allows JS developers to write iOS applications, only the result cannot boast of high speed. And the speaker noted the performance of the language as the first advantage. The illustration shows that the Swift language is not inferior to Java (as well as Scala, Closure), JavaScript overtakes by an order of magnitude, and such scripting languages ​​as Ruby, PHP and Python are far behind.

Benchmark
')

Performance comparison of Swift and other languages.

The second advantage is the fact that the language has static strong typing . That is, the finite types of variables and functions are determined at the compilation stage, and the language does not perform implicit conversions. Accordingly, we almost instantly diagnose problems like dividing a line by a number.

The third important aspect is the use of RAM . It may seem that this is not essential. Many have heard phrases like back-end developers from developers like “you just need to buy more pieces of hardware”. When executing the similar code ( Benchmark ), the Perfect framework requires far less resources than Node.JS, Java or Ruby.


Comparison of memory usage with Swift and other languages.

Why is this relevant? The answer is simple - the cost of cloud hosting. Practically for all major vendors, the main criterion affecting the price is the size of the cloud's RAM. Of course, with a more expensive tariff plan, you also receive additional CPU power, but according to John, in practice, the reason for switching to a more expensive tariff plan is memory.

For example, Amazon Web Services offers the following pricing plans:

PlanPrice (per month)
4 vCPU, 16 GB of memory ($ 0,239 / hour)$ 172.08
1 vCPU, 1 GB of memory ($ 0.13 / hour)$ 9.49

If our server will "fit" in the limitations of RAM, then you can have about 18 balanced instances. This is a pleasant moment for small startups or for developers who, for some reason, are no longer satisfied with free plans.

The Perfect framework does not require a large amount of memory under load or at startup ( Benchmark ), which is especially favorable when using the microservice architecture.


Comparison of memory consumption under load Swift and JS.

John also noted the possibility of isomorphic programming . An impressive idea is to use the same code to describe a domain domain and business logic. This would allow developers to reuse ready-made tested code, greatly speeding up development and reducing the number of bugs. As a result, the costs would decrease and the quality of the code would improve. On the other hand, all this sounds great in theory, but in practice the approach is not so easy to implement and has pitfalls, so we’ll treat this point with a healthy skepticism.

Alternative frameworks


Also a good sign for the development of Swift in terms of server development is a healthy competition among the frameworks. Now Perfect alternatives on the market are:


Kitura was created at IBM, and the developers officially announced that they would contribute as much as possible to deploying Swift services on their IBM Bluemix cloud platform.

→ Detailed Framework Comparison

Also the advantages and disadvantages of each of them are well laid out here .

The scope of the Swift language is actively expanding. Jonathan noted that although the developers are competitors, they all maintain good relationships, often lead discussions about the implementation of certain parts and everyone wants the Swift language to be increasingly used in servers in the future. This is facilitated by Apple, which created the Server APIs working group, which includes, in addition to its own developers, technical experts from the above companies. Workgroup manifest: https://swift.org/server-apis/ .

The group is working on the following issues:


There are already such benefits of collective work as standards for the implementation of basic interfaces and standards for implementations of HTTP .

This will help a regular Swift developer by:


Perfect assistant


Jonathan and the Perfect team have developed the Perfect Assistant tool with the most intuitive graphical user interface.


Features menu Perfect Assistant.

It allows:


This utility greatly helps developers who are just beginning to dive into the depths of server development. A lot of technically difficult problems at an early stage - starting a server or deploying it - are solved by pressing a few buttons.

I think that the writing of auxiliary graphical interfaces is the right direction, because it will keep the "fire in the eyes" of interested people, and the community of Swift-server development will increase.

findings


Using Swift for server development can be called a promising idea, whose popularity will only grow. The reasons:


Unfortunately, there are some drawbacks that prevent Swift from using in production now:


Additional materials


Speaker :

Twitter ⬝ Github ⬝ Medium

Video :

→ Speaker at try!. Swift NYC
→ WWDC
→ Excellent report from Kitura developers
→ Report on SwiftConf`16
→ Building Production Server

Articles :

→ Excellent article with code examples on Habré
→ Framework Comparison
→ Perfect Assistant

Source: https://habr.com/ru/post/327933/


All Articles