Server Side Swift with Perfect: Getting Started | Ray Wenderlich

Perfect is an open source server side Swift framework, that helps you write web apps and services using Swift 3. Learn how to get started with Perfect, and create your first server side Swift web app.


This is a companion discussion topic for the original entry at https://videos.raywenderlich.com/screencasts/server-side-swift-with-perfect-getting-started

Hi Ray,

thanks a lot for your tutorial on “perfect”!

Is there any easy way to remote debug a swift application running on an (develpoment) server?

Using XCode it’s quite easy to debug an swift application running on the local machine. Unfortunately it’s not always easy to run a server application on the local workstations cause of Datebase connections and various other things that hat difficult to „emulate“ on a local machine. To make the swift web application behave more like in production use, I would prefer to do some kind of remote debugging of the application running on the server.

It seams like llvm is able to support remote-debugging. Is there any option to attache XCode Debugger to the remote application (running on the server), or is there any other IDE capable of doing this?

Hello @rwenderlich ! Great tutorial.

Can you please mention some pros and cons of using Swift on a server (compared to node.js for example)?

I am now starting to experiment with server side programming, and it seems that there are just too many options out there (and everyone is all in for node.js nowadays)

I found a post on Medium with some benchmarks and by the looks of it, it seems that Swift outruns node.js in every aspect. However node.js has been there for a long time and there is a lot of community traction (help, tutorials, libraries etc.)

Some direction would be very much appreciated !

To reply tkallioras’s question:

I have tested on Node.js 7.x and Perfect 2: Perfect is still a winner in latency, memory and requests. In fact, ~50% less memory than Node.js

You’ll need to research which is fast in productivity or performance. Best to get a Linode VPS for a trial and create your own benchmark in HTTP and HTTPS mode.

To correct, not everyone is using Node.js.

Perfect HTTP is based on Node.js libev but the:
Pros:

  • Security is important.
  • Less error prone (enum helps you type less string).
  • Productivity with easier to understand coding in Swift than on JavaScript.
  • Benchmark on my end, Perfect outperforms Node.js in HTTP many folds
  • Works with Big Data.
  • Benchmark (Note that the timing result could be wrong, you could write high-performance code once you master the tricks) http://benchmarksgame.alioth.debian.org/u64q/swift.html
  • Write C code in Swift.
  • You could read the Swift roadmap for 2017 and beyond
    http://researcher.watson.ibm.com/researcher/files/us-lmandel/lattner.pdf
  • How often WordPress have been in spotlight over vulnerabilities?
  • Beautiful code as Ruby.
  • It also took Node.js few years to reach its popularity after many negatives and didn’t see the benefits then. Node.js doesn’t fit where performance matter.
  • AI for Swift (SSS and iOS) is more prefer.

Cons:

  • Not as popular as Node.js, PHP, Java, .Net. Why bother? Swift for iOS and SSS can be written in one language, Nginx or Apache is optional.
  • Spent more time than Node.js but the end results is much more reliable and secure than Node.js if you want to use for production.

Of course V8 is planning to overhaul with high-performance engine, we won’t know what happens but Swift will focus on rolling out new version annually.

p.s. You can still working on Node.js if your team will be more productivity and you need to use React.js or SSR. The choice is yours, by the way, Node.js is not really as popular as PHP.

Hi Ray,
interesting tutorial! Nice to learn more about different options to use Swift for writing your own API.
However, I followed along with your Vapor screencast series, and I wondered how you would compare Vapor and Perfect?
They probably can do the same things, using Swift. Which one would you prefer to use?
Thanks,
Filip

The trainer won’t be able to answer your question. It’s depend on

Vapor:
For pure swift and you prefer Fluent like Laravel Fluent with supported databases without touching low-level C.

Low learning curved for web developers who simple wants to serve contents similar to Blogs like WordPress or eCommerce. It has easy to use permission control.

Performance should be better once Swift 4 or 5 release with support on those Rust, Go, other models.

Note: Vapor behind Nginx will be slower.

Choose Vapor if you don’t mind to contribute Vapor code frequently to iron out bugs, see their #release in Slack channel.

It’s toward an MVC web framework just like Laravel.
https://vapor.github.io/documentation/guide/folder-structure.html

Perfect:
Support some existing C libraries to reuse existing code, just like Scala and Kotlin reuse Java libraries. You get to leverage your Perfect website with Enterprise-class e.g. Kafka, etc as Perfect team adopting them. You have the best of both world and you will only need to write in Swift code.

Demo:


Performance in Perfect is excellence and use battle-tested HTTP.
Fairly learning curved for a start, as long as the community helps you with some tips and do a bit of research, you’ll gains lot of ideas to build any applications that demand performance.

What if we do not need Nginx or Apache for reverse proxy in Perfect? It’s possible with a bit of workaround to maximize performance.

Choose Perfect: If you prefer stability and less disruption to your and clients’ projects.

In my experience, you could build it like MeteorJS in some way, it’s more than MVC web framework and you could choose your folder structures.

Kitura is useful for first-class support in IBM cloud services that aims to be performent and less memory usages than Java.

To the end of comparison, use both. One for purely serving on Internet and that what makes Vapor as popular as PHP community. One for working on the backends if you can’t afford downtime or need to work with commercial application.

Important, if you prefer to write HTTP level, you could choose either Vapor or Perfect HTTP module and write in your own way with a little more verbose code to gain better performance for specific tasks. Both could built like WordPress. It’s your chance to try both out for a few months and decide which is you prefer.

Remember to monitor memory and CPU usage on both frameworks.

@actually,
Thanks for your detailed reply, and I’ll be sure to check out those links!