10 ms·
Swift AWS Lambda Runtime
- mikece 6y agoIf you have tons of Swift code that needs to run in watchOS, iOS, iPadOS AND the cloud, this would kinda make sense... but how frequently is that the case? When I was still doing mobile the goal was to write as LITTLE client-side code as possible and put as much logic/heavy lifting on the API side as possible because we can make changes there far quicker than in the native client. And almost all of the client-side code was about GET/POSTing to the API or interacting with the SDK to draw things on the screen -- almost no business logic. That said, I didn't work much on apps that were supposed to work without a data connection for long periods of time... in that case it's more likely you'll run into scenarios where you're writing business logic in the app (in Swift/ObjC) but even then the goal was to keep that kind of code to a minimum (or less).
- phaedryx 6y agoI can think of a few scenarios off of the top of my head: App sends an event, Lambda sorts it into queue(s) for processing App wants to know if its data is stale, asks Lambda I think there is a niche for small, quick processing. Why write it in Node or whatever if your devs already know Swift?
- Eric_WVGG 6y agoApple’s goal for Swift is to be "the new default language for computer science." They see it as supplanting Java. Whether you think that's crazy or not, pure server Swift is a thing, personally I love it. https://vapor.codes https://vapor.codes
- j88439h84 6y agoJava is the default language for computer science??
- panzi 6y agoAt many universities it's the language they teach and have most of their exercises in. The exercises that are explicitly about something else excluded. Functional programming -> Haskell, logic oriented programming -> Prolog, statistics -> R, writing compilers -> C with flex/yacc/bison etc. Everything else: Java. At least it was like that for me when I studied in the '00s and '10s in Vienna.
- aryonoco 6y agoJava? Where I am, the language of computer science is, and has been for the last 5 years or so, Python. I rarely see Java outside enterprise applications anymore (and Android, though it's being supplanted by Kotlin there). Java is the new COBOL.
- pjmlp 6y agoApple's goal for Swift is quite clear on its documentation, to replace C and Objective-C. As for anything else it isn't quite clear.
- Eric_WVGG 6y ago> The goal of the Swift project is to create the best available language for uses ranging from systems programming, to mobile and desktop apps, scaling up to cloud services. https://swift.org/about/ https://swift.org/about/ > "My goal for Swift has always been, and still is, total world domination," Chris Lattner, the creator of Swift, said onstage at Apple's Worldwide Developers Conference in 2017. https://www.businessinsider.com/developers-love-swift-apple-programming-language-ios-apps-2020-3 https://www.businessinsider.com/developers-love-swift-apple-... I'm having trouble finding the specific bit about "default language for computer science," might have been his interview on the ATP podcast. anyway
- pjmlp 6y agoWhat Chris Lattner might desire and what Apple wants isn't the same thing, specially since nowadays he doesn't get much to say on where Swift goes. Had he stayed at Apple overseeing the language design I would agree.
- jmull 6y agoSwift is a nice language in its own right, and, according to the post, is a good fit for the lambda environments. So there doesn’t need to be a direct connection to iOS to decide to use Swift for serverless function. A developer might just decide to use Swift for serverless functions. (I can see the benefit to sharing certain kinds of code between client and server, but a lot of things have to line of for this to make sense, so I’m not sure if that’s a significant driver.)
- CalmStorm 6y agoSwift does not allow null pointer, and therefore there is no null pointer exception. This is a very nice feature, especially compared with other server-side compiled languages like Golang and Java. Swift is modern and concise, I hope it takes off on server-side.
- mrtksn 6y agoThat’s great news. For some reason cloud function run extremely slowly for me on Firebase. Like a few seconds slow on the first call if not called frequently, then it drops to milliseconds level.
- WrtCdEvrydy 6y agoYeah, this is called a 'startup effect' in most cloud function environments. Lambda has a thing called 'prewarming' which basically hits it every 15ish seconds to make sure it's still active...
- mrtksn 6y agoI am considering to implement something like that by myself. It’s not an acceptable performance otherwise. Alternatively I am looking into running it on different tech, I would have moved already on Swift on Linux if Fireplace had a library for Swift beyond iOS.
- gnulinux 6y agoDoes it really sleep in 15 seconds such that it needs to warm up? Why call it every 15 seconds? Why not every hour, every day? Is there a documentation how often it needs a warm-up?
- WrtCdEvrydy 6y agoI believe AWS docs say that your function is loaded on a machine for 15 seconds after termination... so if a new request comes in during that time it goes to that function instead of starting a new one.
- moduspwnens14 6y agoLambda has provisioned capacity now. You can just tell it how many to keep warm and it'll keep that many warm (but still cold start additionally as necessary).
- asadlionpk 6y agoThat's by design. Your server 'sleeps' and - wakes up on for a request(few seconds delay on request), - stays awake (requests are fast here), - goes back to sleeping if idle for sometime (15mins?) This is what keeps the costs low (or free). Same is true for Heroku, Lambda, Vercel, Azure Functions, etc.
- avolcano 6y agoIs there any recent rundown on the state of server-side Swift in general? I know there was a lot of discussion when IBM stopped working on it back in January. At the broadest level, I wonder what the footprint of Swift at runtime is, both in terms of CPU and RAM. I've been really enjoying Kotlin as a server-side language - it's a massive step up in productivity from TypeScript - but the overhead of the JVM certainly is notable, even in small personal projects (my small Javalin app uses four times the RAM at rest as my Express app did). Swift is really interesting to me because it is very similar in practice to Kotlin, but with some very cool and powerful additional language features. So, if server-side Swift has a smaller footprint at runtime and equal or better performance than Kotlin on the JVM[1], that'd be a really compelling language for me. [1] yes, I know GraalVM/native options exist for Kotlin, but every time I've tried to investigate ecosystem compatibility, it leads to me glancing at pages long-articles about "how to configure X framework for GraalVM" that make it not seem worth the effort yet
- technics256 6y agoWhat about Kotlin make it a step above typescript in terms of productivity?
- avolcano 6y agoThis is a blog post I've been putting off writing for a while; I'll try to tl;dr it best I can given it's somewhat off-topic: * TypeScript's lack of runtime types and stable reflection APIs make it hard to have any guarantees of type soundness without either code generation (e.g. schemats) or complex type programming to convert a runtime representation of a type to a static type (e.g. io-ts). I find this very frustrating when doing web backend programming, where you are constantly doing i/o with external services (whether HTTP APIs, or input from client requests, or database interaction). This is particularly maddening because there's no de facto standards (seriously, there are a lot of these libraries: https://github.com/moltar/typescript-runtime-type-benchmarks https://github.com/moltar/typescript-runtime-type-benchmarks), so it's not easy to e.g. find a DB library that will let you define an io-ts schema that a query should match without re-wrapping things yourself. Basically: if TypeScript had runtime types, and an `as` cast threw an exception when a value doesn't match the specified type, I'd be much more inclined to keep using it. I genuinely think that's table stakes for a type safe language. (and lest you think this has to be how TS works given the nature of how it's compiled to vanilla JS, I suggest you take a peek at Sorbet, which knew this was necessary: https://sorbet.org/docs/runtime https://sorbet.org/docs/runtime) * The TS ecosystem is generally underwhelming. I don't think any HTTP framework for it is particularly good, nor any ORM/query builder. I think there are a lot of really neat experiments still happening in this space, and it seems like every day GitHub's little "explore repositories" sidebar shows me another cool library someone's built for TS trying to solve some of these problems, but it's all early stage stuff with a bus factor of 1 and a long todo list. To be fair, _Kotlin's_ ecosystem actually has a lot of these problems; the semi-official Jetbrains-maintained Kotlin web framework and DB access library both have a ton of untriaged issues and seemingly little production use. The good news is, at least on the server, you can completely ignore the "Kotlin" ecosystem in favor of the Java ecosystem, and this is _shockingly_ effective. Just about every JVM framework I've seen has some kind of officially-maintained Kotlin adapter, presumedly because it's not hard to sell Java developers on "what if you could keep using the exact same tools with a nicer language." These adapters aren't even needed, mind you, they just provide nicer APIs that can use Kotlin language features. Javalin + JDBI is infinitely nicer out of the box than trying to turn Express and Knex into a production-ready API with anything approaching type safety. * This isn't a make-or-break thing, but Kotlin is just generally _nicer_ than JS or TS in a lot of ways, while still having a very similar programming style. For example, the collection types are far more robust than something like Lodash (let alone the absolute joke that is the ES6 Map/Set API).
- _31 6y agoAlways happy to see more new Swift projects pop up, especially on the server side. It's great watching the language evolve and continue to add more powerful features.
- jtdev 6y agoAll of the closure obsession in Swift is extremely off-putting to me.
- magnetic 6y agoCan you elaborate?
- jtdev 6y agoClosures everywhere... why? They make code difficult to reason about and read and only seem to satisfy the FP zealots.
- saagarjha 6y agoYou don't have to be a functional programming zealot to be able to recognize the value of not having to define a function just so you can sort a list using a different predicate.
- jtdev 6y agoExcept that’s not the extent of how programming with closures is forced on Swift coders. Essential all major modern languages have collection sorting functions built into the base collection types that accept “by” (or similar) arguments... which is quite intuitive to even Jr. programmers.
- vertex-four 6y agoOK, what's an actual example of your problem? I don't write Swift, but I'm curious about it - where's a closure used when some fixed logic would've sufficed?
- jtdev 6y agoDid you read the parent article? Good examples there.
- dzonga 6y agoswift is a nice language. however, don't do the mistake of developing server side applications on it. tried it, after drinking the ibm, vapor kool-aid in 2016ish. the community though friendly is weak. still to well known stacks if you're going to be doing server side stuff
- rubyn00bie 6y agoChalk one up for time wasted not addressing what people really need... I truly love Swift, like god-damn is it my cup of tea, but I can't really bring myself to write it anymore. I've written over 10,000+ lines , shipped and maintained a few different production apps, but anymore I just have no urge to write it. And the biggest reason why? I think it being open source is a joke until Apple, and I mean Apple themselves, implements some sort of cross-platform UI framework with it. Like, most of what is written in Swift is fucking UI code that's totally useless on other platforms. I think it's pretty laughable I can run Swift on AWS but I can't do a simple GUI app on Linux or Windows using the OOB Swift SDK. Apple, you're a fucking trillion dollar organization, for fucks sake stop being so damn stingy with portability. When I can write cross-platform GUI apps with Swift, maybe I'll give a fuck 'bout running it on a server. Just my two very bitter, hurt, and sad two cents...
- madeofpalk 6y agoI just don’t think that’s where Apple’s priorities are for swift. They want a modern language for their platform first and foremost, and then secondly if they developers can write server components for their apps in Swift, then that’s good as well.
- cglong 6y agoI wonder if they're hoping people that choose Swift as their first programming language will experience "vendor lock-in" and will be disinclined from branching out to other platforms that don't support Swift. This would make sense given the Swift Playgrounds initiative.
- tasogare 6y agoMicrosoft ignored the same exact point (official multiple UI) for C# for years, despite having it at some point (Silverlight out of browser). So I can totally understand what you are expressing there, yet I think there are even less chance Apple act on and provide such framework in the future.
- jmull 6y agoA good, modern, general purpose cross-platform GUI application framework is a very different proposition than server-side Swift. It’s also a very, very tall order that would require a lot of resources to create and a lot more to maintain... and I don’t see big strategic benefits to Apple in doing so. I don’t think it’s going to happen. Maybe WASM will lead to browser-side Swift and then you can do Electron-style cross platform apps using web technologies. (Not that I think Apple would put resources to that either.)
- happybuy 6y agoThis is a great and very useful addition to the Swift ecosystem. Currently develop a very popular iOS/macOS app in Swift which talks to an AWS Lambda backend written in Node.js. This has required some model code to have dual Swift and Node versions. If the Swift AWS Lambda Runtime was available previously this wouldn't be necessary. I'd say a lot of developers in the Apple eco-system would be in a similar situation and this runtime can help to streamline a lot of client-server approaches.
- pier25 6y agoAnyone used compiled languages with cloud functions? I've only used JavaScript but I'm guessing a compiled binary (eg: Go) would have better cold starts, no?
- econcon 6y agoLast time I herd c# had best cloudstart performance on lambda.
- renewiltord 6y agoInteresting, AWS Lambda provides a runtime API so you can implement your own runtimes. kewl https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.ht...
- ec109685 6y agoGiven lambda can only possibly send one request at a time to a handler, what is the advantage of using the non-blocking primitives and separate worker thread versus doing work on the main thread?
- sudhirj 6y agoIn this model, the only advantage would be parallelism inside the request. If you had to fetch 100 things as part of this request there’s no need to do them one by one.
- vaxman 6y agoThis is cool --finished a deep dive of SwiftNIO all the way down to the IETF "TAPS" specification (ah, good 'ole Courier font, brings a tear to my eye). Will my soul brother, the great chrome dome Werner Vogels, be joining the flamboyant users of the most advanced hair care products ever invented on stage this year during WWDC to announce new support of Apple? macOS instances that can be spun up and down from Screen\ Sharing.app? Xcode compile farms that work seamlessly with a new iPad Pro edition of Xcode? Apple-subsidized (so free) access to all AWS for developers? (oh, I can dream) If not, then there's nooo way I would use Swift outside of The "ecosystem" (first time I've read that expression used inside of Apple's own documentation, albeit on a GitHub project), though I might use SwiftNIO back ported to iOS to do something cool with Multipeer and ARKit.