Hey everyone, we have recently started working on ...
# server
f
Hey everyone, we have recently started working on developing Google Cloud Functions with Kotlin/JVM but we haven't found any examples on how to use coroutines in this environment. Has anyone worked on this or knows of any examples online we can look at? From what we found, seems like the calls to the cloud functions are blocking so we are using
runBlocking
to call suspend tunctions for now, but it doesn't sound right 🤔
n
aside question: is that a good idea to start a jvm in a faas context? • it starts slowly • it has no time to compile native bytecode 🤔
f
Those are good questions @nfrankel. We are exploring it for now and we are aware of the possible speed issues. Doing it with Kotlin/JS would definitely be faster but the lack of an easy way to create wrappers for JS libs makes it hard to upgrade versions and slow to implement as we need to constantly create/update the necessary wrappers foe the libs we need to use (we are using Kotlin/JS on the frontend and this is quite a slow process when adding new libraries). Since Google supports the JVM for Cloud Functions we thought it was worth a try.
n
Since Google supports the JVM for Cloud Functions we thought it was worth a try
it will work for sure my (loaded) question is whether there will be any benefit if i were you, i’d definitely consider this: https://thenatureofsoftware.se/posts/openfaas_graalvm_native/
f
Thanks for sharing @nfrankel. I had not heard of OpenFaaS but I'll have a look. I had heard of GraalVM a bit but I'll need to look into it in more detail as I have not used it before. For now however we'd like to test what we have and get some practical experience on what are the limitations before making any changes.
👍 1
n
graalvm (native image) is actually a trade-off you spend (much) more time building and less time running it’s great for short-term processes when the jvm has no time to compile to native code if you really really want to keep the jvm, then check parameters that allow you to discard native code compilation
👍 2
f
Thanks for explaining @nfrankel To see if I understood correctly, so if we use GraalVM, we'd then need to use OpenFaaS to put the resulting binary in a container and deploy it to a serverless environment? Or would I be able to compile using GraalVM and still deploy directly to Google Cloud Functions without using containers?
n
i never used openfaas myself so i don’t know 😬 plus, as i mention, i never dug into it because it feels like oil and water to me 😅
f
Haha fair enough, thanks for sharing the info anyway :) So from your point of view, what would be a better approach that still allows us to use Kotlin/JVM in a serverless environment with as little overhead as possible? Or is that just a dream? 🤣 As I mentioned, I'd love to use Kotlin/JS for this but the lack of lib wrappers makes it too hard to commit to at the moment.
n
if you want something to work, jvm is good enough but that’s like using a hammer to kill a fly if you want to get performance, then graalvm native image is great for short-lived processes but your build pipeline is going to be more complex IT is about trade-offs 😉
with the jvm check (and benchmark!) the time with different jvm parameters https://www.baeldung.com/jvm-tiered-compilation
f
Thanks I'll look into those JVM params too 👍
👍 1
e
Unless Google Cloud reuses the same JVM process for multiple invocations, using
runBlocking
is fine.
f
Thanks for the info @edrd 👍
🤘 1