Kotlin Native has some server-side samples, could ...
# kotlin-native
n
Kotlin Native has some server-side samples, could that be extended to cover Serverless? Is Serverless development going to be officially supported in Kotlin Native?
g
But what is serverless development? I mean each “serverless” service has own API and even own supported platforms (jvm/js/native)
I’m not expert, but I played with different services such as openwhisk, aws lambda, firebase (kotlin js), all of them have very different set of features, different platforms, own packaging and deployment tools. It’s hard to create really helpful sample, because most of problems is on side of service and their deployment tools
n
There are some frameworks like Serverless (https://serverless.com/framework/) which attempt to provide a common API that works across all FAAS (Function As A Service) platforms. Serverless these days has become the defacto framework for FAAS platforms, and has official Kotlin support (for Kotlin JVM and Kotlin JS, no Kotlin Native support yet ⏲️).
g
But it requires support of Serverless Framework, probably it should be done by community, don’t think that support of one particular framework by K/N team is a right solution on current stage of K/N
hmmm, I may be wrong, but looks like serverless framework do not allow to support different platforms, it’s more like faas-dependant templates generator
n
Agree with the community providing support for Serverless with Kotlin Native. Do think that the Kotlin Native team can do some basic things (likely small bits and pieces) to ensure that Kotlin Native works well on FAAS platforms (aka platform neutral).
g
Do you see any problems with it? As I understand you can deploy K/N program to any faas platform with support of binaries
we don’t have yet K/N library for http or sockets, so the only choice now is use some C library or raw sockets
I think K/N team should work on this before support of any other particular use cases
n
Are there some FAAS platforms that allow binary deployment? Some FAAS platforms allow for Docker deployment.
g
Because if you have http server it’s trivial to implement any faas with support of binaries
openwhisk
docker is also option, but again, it’s jus binary distribution that listen port
nothing magic there
n
There is a case of Kotlin Native working in Open Whisk: https://jaxenter.com/kotlin-native-serverless-tutorial-fibonacci-fun-136615.html
g
yes, just docker image
so this sample uses C library for Json
would be better to invest to kotlinx.serilization than to particula-faas-partiular-framework sample
I don’t want to rant here too much, sorry if it sounds rough
I just think that this is a great field for community contribution and not clear what exactly K/N team should do here
n
Just to clarify where the Kotlin Native team fits into this. There are Kotlin Native performance optimisation's that will need to be done to ensure the Kotlin Native runtime is performant in Serverless use cases, and the Kotlin Native team is in the best position to do this.
g
How “Serverless use case” is different from other use cases? Startup time? it’s already pretty fast, much faster than jvm Any performance optimisations is good for any use case
Checked openwhisk samplese for custom docker
this Python http script to proxy requests to your custom program looks as incredibly clunky and non-optimal solution
anyway, it allows to run any custom program
o
in a sense, even KotlinConf Spinner example https://github.com/JetBrains/kotlinconf-spinner/blob/master/kotlin-native/samples/fullstack/httpserver/src/main/kotlin/server/HttpServer.kt contains “serverless” server (i.e. lightweight standalone server), which is running for a year already, without much problems
g
Funny thing that such self contained server is not what people expect from “serverless”, they want integration with some third party “FaaS” service For example on openwhisk you even don’t need http service inside, they pass request to main function arguments as Gson JsonObject 🤔
I have really strange feelings after tests of all those “serverless” services and frameworks
But actually openwhisk kotlin runner supports data classes, so it’s better than raw JsonObject, but overall architecture of those solutions looks not really good for me
o
yep, term is somewhat vague indeed, but at least if we’re talking about producing small standalone binaries written in relatively high-level language - K/N is pretty good here
☑️ 1
👍 1
o
that’s Kotlin/JVM one, I guess
👌 1
g
this is what actually runs your functions, no magic there
Yes, of course, for JVM
o
running it as a standalone process would provide better isolation and resource control, I’d say
g
They run this service on each request, as I know
at least openwhist tries to do some smart things about jvm, because start jvm is not so fast
but anyway, it looks not really effecient
but you right, k/n looks as much better alternative than jvm in this particular usecase
This is how they run custom binaries, there is Pyton (sic!) web server that proxies requests to your binary https://github.com/tleyden/openwhisk-dockerskeleton/blob/master/actionproxy.py
o
One way to understand “serverless” that helps me is that “server” here is not a dedicated hardware, and being serverless doesn’t mean running in a cloud. “Server” here is a dedicated software (web server, framework, etc) that has a specific lifecycle (binds to a port, listens to connections, processes http requests). Hence FaaS is serverless, but docker with a http server is not.
s
I would like to experiment about Kotlin/Native support for Serverless, and I am thinking about the deployment options because even if most platform runs under Linux x86-64 that could be not always the case. Could we imagine using Klib as a deployement unit to deploy LLVM bytecode on a FaaS that could be compiled as an native executable on the Faas platform ?
I know that Klib is not expected to be an executable but FaaS is higher level so maybe if Klib implement a given function type and provide function named by convention we could use that
For long term, I really think WebAssembly should be explored as a possible option. See
Any thoughts ?
g
It’s actually not clear for me why wasm instead of platform compatible binary?
I know, this is not the most common approach for serverless services, but I don’t understand why
s
You don't know the internals of the system you are deployed on, this is sandboxed runtime so great for security, it is a good trade-off between performance, flexibility and security
Serverless could run on Arm or x86 for example
So I don't want to deploy a specific platform executable
I want to deploy a sandboxed autonomous efficient fonction
o
Docker example shows that generally Linux binaries are good enough executable unit format representation, so I’d suggest to use raw native code instead of yet another VM
1
n
In other words Kotlin Native would be a good way to go depending on what Serverless software is being developed.
s
There are serverless environments for Swift. I think IBM's OpenWhisk offers it. Perhaps Kotlin-native could run in a Swift environment?
g
Swift runner for OpenWhisk compiles Swift files itself. There is no magic. The only thing what they do is compile your swfit source code on their server I don’t see any problems to do same for K/N, they even use gradle as a build tool for swift, I just think that this approach is strange, but if people like, maybe who is really intereseted, could write openwhist runtime for K/N, it shouldn’t be hard. But Swift and possible K/N has a problem: first time when you run your action your file with function will be compiled before execution, not so bad, it will be cached. But still this can be avoided using docker image
You can check implementation, it’s not so many code: https://github.com/apache/incubator-openwhisk-runtime-swift
So approach with docker looks much better for me, especially if you want to have dependencies and know exactly what is available on your platform.
s
Make sense yeah