Fork me on GitHub
#clojure
<
2020-06-01
>
kwladyka07:06:39

How long start hello World Clojure app? how long comparing to Java? How long with dependencies? I am asking in context of ‘google cloud run’ so this can matter here. The app need to fully start as fast as possible. I am not sure if Clojure is good for this model. Comparing to for example Rust or Go it can be a difference.

Nir Rubinstein07:06:42

Well, Clojure and Java both need to spin up the JVM, while Rust and Go compile to native executable - the comparison is inherently lacking. If it's just a "hello world" app, that needs to spin up as fast as possible and you're still keen on using Clojure, you can probably do it with GraalVM

kwladyka07:06:43

Somebody use Clojure I with google cloud run and can share experience?

kwladyka07:06:40

Yes comparison is not the best, but trying to figure out if it is good idea to use cloud run or not

kwladyka07:06:22

I would like to know what google define by > container instance is starting

kwladyka07:06:31

I guess as soon as jar is run in container it is runtime

didibus08:06:50

It isn't fast enough for serverless, unless you use ClojureScript or you compile Clojure ahead of time to a native executable

didibus08:06:18

Both of those impose some restrictions to your Clojure code. With ClojureScript, well, you can't use any Java dependencies, only JS. And with GraalVM native compilation, not all Clojure libraries or Java library are compatible.

didibus08:06:12

You could also use babashka potentially, though it is even more restricted.

vemv08:06:14

> It isn't fast enough for serverless If that was entirely true, e.g. https://github.com/pedestal/pedestal/tree/master/samples/aws-codestar-lambda wouldn't exist.

didibus09:06:38

Well, I mean, if you are worried about it, its probably not fast enough. The only downside is cold-starts, so if you don't mind users waiting a few seconds once in a while when they hit a cold start. Or if you are okay paying for reserved nodes which you can do on AWS, not sure about google, then it is still viable

eskos10:06:56

If you’re willing to embrace the bumps and partly rough weather, using GraalVM can be incredibly fast, definitely “fast enough for serverless”.

kwladyka12:06:03

GraalVM I will take a look what it is

lukasz14:06:24

One thing about cloud run - it's not quite like Lambda or Cloud Functions. Your Cloud Run instance is kept alive for longer (basically for as long as it keeps getting requests from clients), and you can configure one instance to handle multiple concurrent requests - so the cold start problem is only a factor you have very small traffic, otherwise it might work better than say, typical FAAS where 1 req = 1 invocation

kwladyka14:06:51

Thanks. I got similar conclusions but wasn’t sure.

Trevor19:06:35

For faster startup time you could try java -client -jar ... https://news.ycombinator.com/item?id=22459518

Trevor19:06:26

oh it's ignored on 64bit JVM's... nvm

didibus19:06:07

Oh right, I was thinking of cloud function

didibus19:06:32

Hum, I don't know enough about cloud run. But from a quick glance, I don't think Clojure start time would matter

didibus19:06:48

It seems more inline with a traditional auto-scaling instance setup

didibus19:06:43

And you could just set it to add an additional instance at some threshold of traffic which you can plan accordingly to how long it takes for the instance to boot

didibus19:06:09

I'd also imagine the container takes probably a good chunk of time to get setup anyways, so the Clojure start time above that won't matter too much

emccue20:06:09

If you need something to start as fast as possible, I would personally just whip it up in rust or go

slimslenderslacks01:06:10

@U0WL6FA77 Not cloud run, but I recently took a look at running clojure in the Google Cloud function java11 runtime. If you're interested, I've been writing up some notes here: https://github.com/atomist-skills/gcf-java11-clojure

👍 4
slimslenderslacks01:06:51

I'll ping the channel when I've got more info about timings. We run a lot of clojurescript Node.js functions on gcf - quite interested in how this java11 runtime performs.

👍 4
kwladyka08:06:45

yes, this are also things in my consideration. google cloud functions can be used with java / node.js so I guess with js / cljs / java / clj. I am curious if using cljs and clj is a good idea with cloud functions where time really matter

slimslenderslacks16:06:56

@U0WL6FA77 I fixed that 404. Sorry!

👍 4
kwladyka16:06:31

What is the final conclusion? Is it worth to use Clojure with functions?

slimslenderslacks16:06:51

Well, the gcf functions stay hot for about 5 minutes, and as long as that's true, I'm seeing startup times consistently under 10ms.

kwladyka16:06:49

What about complexity (simplicity) ?

slimslenderslacks16:06:23

But if you don't have sustained throughput, and the invoker shuts down, you see 3-4 seconds.

kwladyka16:06:50

while startup is under 10ms I am fine with this

slimslenderslacks16:06:39

When you say complexity, are you talking about packaging/monitoring/logging/etc?

slimslenderslacks16:06:18

Ya, I've been quite pleased with the development experience so far, because it's my normal clojure development flow, with a few "additive" things to test with the google java function invoker before deployment. The deployment I documented above was "mostly" tools cli based. You'll see that I had to directly invoke javac in one place, but we might be able to get rid of that.

kwladyka16:06:26

So I see you have to use Java for “boilerplate” https://github.com/atomist-skills/gcf-java11-clojure/blob/master/src/main/java/functions/Main.java and hmm what is happening here. I am not sure.

kwladyka16:06:03

oh ok you load Clojure and you have to manually load by clojure dependencies

slimslenderslacks16:06:21

I was expecting that we could (gen-class) an HttpFunction and get rid of that.

lukasz16:06:29

FWIW Lein makes a lot of this easier in some aspects (uberjars, compiling java code), but that's a preference. Also, this is based on my experience with AWS Lambda, I never used Cloud Functions.

slimslenderslacks16:06:58

Right, ya, I think Lein would be perfect for this too. I've been challenging myself to use deps.edn for everything lately 🙂

lukasz16:06:12

Although, Lambda works out of the box and doesn't need Java classes, eg this is enough: https://gist.github.com/lukaszkorecki/b59bfab4e5a3a25a47f3933fe01ee662

lukasz16:06:33

(I'll be open sourcing this bit as part of a bigger write up)

kwladyka16:06:40

My concern is Clojure vs ClojureScript for functions while I can use both.

kwladyka16:06:57

so like js vs Java

slimslenderslacks16:06:01

^ Right! That's awesome! Ya, I wouldn't be satisfied with this gcf method until we can also (gen-class) the HttpFunction. It should be as simple as the solution you use for lambda

lukasz16:06:09

@U0WL6FA77 depends on which base platform you're more familiar with- I'd pick JVM over JS, because I just don't have enough knowledge to debug node ;-)

lukasz16:06:44

@U0143KP47M4 weird, it looks like Lambda-like approach should work. I wish I had the time to try it out. Also, Atomist looks really interesting - gonna check it out

slimslenderslacks16:06:58

We already do a lot of work with google cloud functions with clojurescript running on Node.js - that's a workflow I know well (can document if anyone is interested). So for me, this was about seeing whether the java11 runtime might be a good addition.

slimslenderslacks16:06:17

@U0JEFEZH6 I thought this would work https://github.com/atomist-skills/gcf-java11-clojure/blob/master/src/main/clj/atomist/Main.clj but I think I've run into some ClassLoader issues with google's java function invoker

kwladyka16:06:30

for some reason I see in google all examples in cljs, but not in clj

kwladyka16:06:40

your’s is the only one I know

slimslenderslacks16:06:45

The java11 runtime is pretty new. This might start to change.

kwladyka16:06:58

even with Java8

kwladyka16:06:00

unless I am blind

slimslenderslacks16:06:19

Oh, did they have java8 already? Ya, I think I just hadn't realized that.

kwladyka16:06:54

I can be wrong

kwladyka16:06:42

maybe it was only for AppEngine

kwladyka16:06:24

ok, this explain the situation

👍 4