What does HackerNews think of swift-nio?

Event-driven network application framework for high performance protocol servers & clients, non-blocking.

Language: Swift

#2 in Swift
You could take a look a swift-nio (https://github.com/apple/swift-nio) which is a pretty high-throughput system. swift-nio does this using some reference-counted GC where it simplifies the code and doesn't affect performance. Otherwise, value-types are used which incur no GC overhead (unless they are copy-on-write, and backed by something that requires reference counting).
You might be surprised. Check out Vapor [1] and Soto [2], which are built on Apple's SwiftNIO (non-blocking I/O) [3]. It's actually a very nice ecosystem. All the tools are in place to build web servers, Lambdas, etc.

[1] https://vapor.codes

[2] https://github.com/soto-project/soto

[3] https://github.com/apple/swift-nio

> Why should they? That isn't their target audience.

Because they need it?

Apple discontinued macOS server, i bet they use Linux in some of their servers

All their networking related libs are available and tested for Linux [1, 2, 3]

Let's not forget that they package Swift for Linux, and now also for Windows [4]

Swift is a cross-platform language (you not wanting to understand it doesn't change this fact), it's not a macOS framework

[1] - https://github.com/apple/swift-nio

[2] - https://github.com/apple/swift-protobuf/blob/main/.github/wo...

[3] - https://github.com/apple/swift-distributed-actors/search?q=l...

[4] - https://forums.swift.org/t/announcing-swift-5-6-2-for-linux-...

> I have the feeling swift never really worked in the server side

Vapor [1] is wonderful to work with and has a large user base. Apple is also putting significant resources into Server Side Swift with Swift NIO [2]. Lots of really cool stuff happening in that ecosystem

[1]: https://vapor.codes [2]: https://github.com/apple/swift-nio

I can't speak for Apple, of course, but some indications of their seriousness are there.

SwiftNIO is a cross-platform asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients. (https://github.com/apple/swift-nio)

Distributed Membership Protocol implementations in Swift: https://github.com/apple/swift-cluster-membership

Docker Official Image packaging for Swift: https://github.com/apple/swift-docker

Also, on official https://swift.org/download all releases and snapshots are automatically available for: Ubuntu 16.04, Ubuntu 18.04, Ubuntu 20.04, CentOS 7, CentOS 8, Amazon Linux 2

Official Swift Server work group is a steering team that promotes the use of Swift for developing and deploying server applications: https://swift.org/server/

Swift AWS Lambda Runtime: https://github.com/swift-server/swift-aws-lambda-runtime

Official Swift 5.3 release goals have stated a major goal of "expanding the number of platforms where Swift is available and supported, notably adding support for Windows and additional Linux distributions." (https://swift.org/blog/5-3-release-process/)

Huh? Apple provides an example implementation at https://github.com/apple/swift-nio and I would say it’s straightforward to “get up and running”.

It’s pretty easy to take Apple’s HTTP implementation, add a router, integrate a template engine and have something working, but then the real issues start, because the ecosystem and community just aren’t there.

> i don't think apple is ever going to release a server side framework

Maybe not, but there is this: https://github.com/apple/swift-nio

The issue with swift on the server currently is that it’s an entirely different compilation toolchain to that run on MacOS and iOS, so the language has different bugs than those that exist for app development, and gets less attention from swift developers.

If you want to take a stab at server side swift, I’d recommend looking at the swift port of Netty that Apple released called swift-nio (after the name “swetty” was nixed by Apple marketing and communications) - https://github.com/apple/swift-nio

Apple low key does some cool server projects with a Java bent. They've contributed to Netty (well, they hired core developers).[1]

They've been basically put them to work reimplementing it in Swift.[2] It's open and out there but not a lot of people paying attention. While it's still early days I think there may a year where, suddenly, Swift on the server is a super serious thing and all this work they've been doing on little old CloudKit kind of takes over the world.

Just a fun prediction.. but it wouldn't be the first time Apple pulled something like that.

I do like that Swift's non-tracing garbage collection model is well suited for server apps. Rust is cool too but maybe Swift would be a little friendlier and thus better suited to inherit Java's mantle. I mean can you just imagine if Apple is slowly building up Swift to overtake Java on the server? That that's one of their long game master plans? I know that sounds completely crazy.. It just might work. They do run one of the biggest data center networks in the world so they have a pretty good testbed and can justify a hefty R&D budget.

[1] https://www.infoq.com/presentations/apple-netty

[2] https://github.com/apple/swift-nio

Vapor generally kicks ass in benchmarks FWIW, and it's using this now so clearly Apple is beginning to pay attention to stuff around server side concurrency: https://github.com/apple/swift-nio

Although as I mentioned in another comment, if you're looking for something more mature, Kotlin is a great option. Vert.x has the widest database support and is lean and fast, so this is probably what you're looking for. But if just Mongo/Cassandra/Redis is acceptable, Spring Boot w/ Reactive Web looks pretty cool, too.

In addition to Vapor which other commenters have mentioned, Apple itself released Swift-NIO, a port of Netty to Swift that they’re actively developing - https://github.com/apple/swift-nio

It’s somewhat lower-level than web frameworks people may be used to coming from a Ruby/Node background, but it’s pretty powerful.

For people not familiar, Vapor is close to releasing version 3.0, using https://github.com/apple/swift-nio. I've heard rumors that the performance is really good, but I haven't ran anything personally.
Apple working on an HTTP server library called swift-nio-http2 [1] that they say is "coming soon", so I would wait for that before using swift on the server side.

[1] https://github.com/apple/swift-nio

Swift on Linux, which is the key to "server side" swift, is really coming along. However, it still has several rough edges that, while they can be worked around, mar the experience and probably discourage a lot of casual tinkerers who try it.

For instance, if you download the Swift 4.1 tarball, uncompress it, and start up the REPL, it doesn't really work. The first thing you will do is probably "import Foundation" (because the Swift standard library is really minimal, so Foundation is where most of the interesting stuff is). Then the REPL will complain:

    error: repl.swift:1:8: error: missing required module 'CoreFoundation'
You'd have to hunt on the Swift bug tracker[1] to figure out that's a packaging problem on Linux, and to fix it you have to do something like:

    sudo chmod a+r /opt/swift/usr/lib/swift/CoreFoundation/*
Then, say you make a toy program, and try to debug it using lldb. That might seem to work, but as soon as you stop at a breakpoint and try to print a value, booom! lldb will spit a wall of error text at you. (This assumes your program imports Foundation, again, but almost every program will.) This is also work-aroundable, as long as you are able to find the JIRA ticket thread describing how to work around it[2].

There are a bunch of little issues like this, that make it clear that Linux isn't yet a first-class platform for Swift. All this stuff is gonna work fine on your Mac.

OTOH though, the Foundation library itself has made amazing, amazing progress. It's super useful, mostly finished[3], and its pretty clear when stuff that works on Apple platforms isn't yet ready on Linux (because those bits use NSUnimplemented() which just crashes the program). That's important because without Foundation, which contains a lot of the basic building blocks for programs, Swift won't be competing with Go or Rust.

Swift Package Manager is also fully cross-platform and awesome.

Apple also recently released an interesting low-level cross-platform asynchronous event-driven network application framework, called swift-nio[4]. This is super-interesting, but also causes more churn; for instance, once swift-nio was released, the team behind the most popular Swift web application framework, Vapor[5], started frantically rewriting their v3 release to leverage it.

So... yeah, I would say "server side Swift" is becoming less niche, but... it's still pretty niche. On Linux, it's far less mature than Go or Rust, and you need to expect to have to bing[6] a bunch of annoying little issues to get things working.

[1]: https://bugs.swift.org/browse/SR-2783

[2]: https://bugs.swift.org/browse/SR-7065

[3]: https://github.com/apple/swift-corelibs-foundation/blob/mast...

[4]: https://github.com/apple/swift-nio

[5]: https://vapor.codes

[6]: just joking! haha ;-D

There's lots of testing for Swift on Linux (e.g. every pull request runs tests on macOS and Linux), and Apple recently announced https://github.com/apple/swift-nio which seems to have been very well received, e.g. the Vapor framework is completely switching to it for Vapor 3.