aws-lambda

borkdude 2020-03-21T12:04:50.000600Z

https://github.com/dainiusjocas/babashka-lambda

borkdude 2020-03-22T10:53:15.018200Z

OK, thanks. I'll await your results.

borkdude 2020-03-22T10:54:37.018400Z

I think it might also be good to post an issue about this to oracle/graal, since it seems they intended to fix the issue

borkdude 2020-03-22T10:55:04.018600Z

instead of us working around it

borkdude 2020-03-22T11:00:20.018800Z

commented here now: https://github.com/oracle/graal/issues/841#issuecomment-602181005

2020-03-22T18:08:03.019200Z

I've tried with try/catch. The same failure.

borkdude 2020-03-22T18:19:01.019400Z

ok, then our decision was good

2020-03-22T21:15:58.019600Z

It turns out that lambda runtime has curl. So no external dependencies needed. Then the issue is to parse curl response with headers. @borkdude do you plan to support parsing curl response into {:headers {} :body "" :ect :etc} in babashka.curl?

borkdude 2020-03-22T21:28:54.019800Z

@dainius.jocas Cool. I think it's good to have support for this, but it's not currently implemented.

2020-03-22T21:32:24.020Z

Another issue with using curl is that it is much much slower, than clj-http-lite. The echo took 200ms consistently to execute while clj-http-lite take 15ms. Here is my naive implementation of curl response parsing https://gist.github.com/dainiusjocas/d2a5ca60ae25cd260f37b7c125a0b2e6

borkdude 2020-03-22T21:33:33.020400Z

why would curl be slower you think?

borkdude 2020-03-22T21:40:12.020600Z

I made an issue for parsing the headers here: https://github.com/borkdude/babashka.curl/issues/5 I think this should be optional, so maybe when passed an option like :response true will return the full response map and when it's not set, it will return only the body?

2020-03-22T21:48:24.021Z

no idea why it could be that much slower.

2020-03-22T21:51:43.021200Z

IMO, the current functionality should not change, so this response parsing should under some new param like :response true. Note that response headers are retrieved with :raw-args ["-i"]

borkdude 2020-03-22T21:58:33.021400Z

yeah, so when :response true, use the "-i" argument implicitly

2020-03-22T22:18:16.021600Z

πŸ‘

borkdude 2020-03-22T22:52:21.021800Z

FWIW I see similar times between babashka.curl and slurp

user=&gt; (time (do (curl/get "<https://www.clojure.org>") nil))
"Elapsed time: 75.406528 msecs"
nil
user=&gt; (time (do (slurp "<https://www.clojure.org>") nil))

borkdude 2020-03-23T08:52:00.022Z

@dainius.jocas Could it be that the slowness with curl was with repeated execution of requests? Maybe clj-http-lite uses connection pooling?

2020-03-23T09:12:05.022200Z

I doubt that the slowness is because connection pooling. As it is written in the README No persistent connection support

2020-03-23T09:15:40.022400Z

I have a suspicion that it might be because doing shell out on a very constrained environment, just 128MB RAM and very little CPU. I would like to test with more RAM given to the lambda and some profiling.

2020-03-23T09:55:37.022600Z

I have an idea to package babashka as a Lambda layer, and make a proper template that uses handler option, that would be a script file. In this way one could write a lambda function right in the cloud IDE or the packaging script could produce --uberscript for compactness. @borkdude what do you think if I publish babashka as a public lambda layer?

borkdude 2020-03-23T09:56:10.022800Z

:thumbsup:

πŸ‘ 1
borkdude 2020-03-23T11:05:16.023Z

@dainius.jocas Btw, if you want to develop babashka.curl you can load it with bb from the classpath with :reload, instead of the built-in one.

valtteri 2020-03-21T15:35:37.001900Z

Cool! How is the cold startup time?

borkdude 2020-03-21T15:57:49.002100Z

Don't know, ask Dainius I guess πŸ™‚ @dainius.jocas

borkdude 2020-03-21T15:58:13.002400Z

normally bb starts within 13 ms on a laptop

valtteri 2020-03-21T16:01:16.004800Z

I’ll give it a spin once I’m back on computer! Startup-time is usually not that critical to me but I’m just curious.

borkdude 2020-03-21T16:40:30.005100Z

he did say to me that there was one issue in bb that prevented this from working, he's going to do a PR for that

valtteri 2020-03-21T16:52:00.005300Z

Prevented what from working?

borkdude 2020-03-21T16:53:23.005800Z

this is the lambda example

borkdude 2020-03-21T16:53:29.006Z

but he didn't tell me what, so I have no clue

borkdude 2020-03-21T16:53:37.006200Z

we will know soon hopefully

valtteri 2020-03-21T17:00:08.006400Z

I just tried and was able to deploy it to lambda. Had to make small modofikations to makefile on MacOS because it wasn’t happy with /tmp/....

valtteri 2020-03-21T17:00:38.006600Z

the first call took 486.57 ms which is fast imo.

valtteri 2020-03-21T17:10:41.007Z

And second cold call was 484.16 ms. So we could say it’s < 500ms πŸ™‚

2020-03-21T17:51:29.007200Z

Hi, yeah, the cold start is 400ms, subsequent calls are 30ms. Worth mentioning is that the cold start and the duration depends on how much RAM is dedicated to the lambda, the more the faster lambda is.

valtteri 2020-03-21T18:40:25.009800Z

Yep I saw variance between 4ms and 120ms on hot calls with 128Mb RAM. Which I think is quite good.

borkdude 2020-03-21T18:45:12.011100Z

@dainius.jocas About your PR, what happens without it on AWS? Do you get an error? https://github.com/borkdude/babashka/pull/305/files#diff-b4e1e6a8c0b365c3b9fac4c30360f72d

2020-03-21T18:47:22.011300Z

Without the change Lambda fails in a very similar way as is described here https://github.com/oracle/graal/issues/841

2020-03-21T18:53:57.011600Z

Also, I've found very similar issue https://github.com/quarkusio/quarkus/issues/4262. Here it is said that

You can work around the problem by defining the environment variable DISABLE_SIGNAL_HANDLERS to any value. Obviously this means that you won't have OS signal handling though.
Maybe the environment variable for babashka should be the same?

2020-03-21T18:59:01.012300Z

It is. I'm just not sure on how to name the environment variable. But my overall solution is just a quick and dirty hack to make the thing work. Probably more sophisticated design is needed to support Lambda use case.

borkdude 2020-03-21T19:01:56.012600Z

So far babashka specific env variables starts with BABASHKA_, like BABASHKA_CLASSPATH. What about BABASHKA_DISABLE_PIPE_HANDLER?

borkdude 2020-03-21T19:03:17.012800Z

Pipe handling doesn't work on Windows either

2020-03-21T19:05:58.013Z

ok, I'll rename the env variable in the PR

borkdude 2020-03-21T19:18:32.013200Z

merged. I assume you don't need a new build? btw, @valtteri - for you it did work right, without this patch?

2020-03-21T19:35:19.013500Z

A new build would be nice because in the lambda archive I'm packaging the bb binary. For the example lambda I've deployed a babashka docker to Docker Hub https://hub.docker.com/r/dainiusjocas/babashka and then used it to build lambda archive. So, if babashka would provide a build, I'd adjust the example. Propably, later I'd convert it into a template project.

borkdude 2020-03-21T19:40:22.013700Z

There are pre-release builds in #babashka_circleci_builds - I'll hope to release a new one soon.

2020-03-21T19:45:22.015Z

Perfect! No worries, I'm in no rush πŸ™‚

valtteri 2020-03-21T19:45:34.015500Z

@borkdude correct, it worked without the patch

borkdude 2020-03-21T19:46:52.015700Z

@valtteri Hmm, so maybe the patch isn't needed then - or is there something different in your env @dainius.jocas

2020-03-21T19:49:06.015900Z

The patch is needed, I've packaged the patched version of bb to a docker, and then used the patched bb for building the lambda in the docker.

FROM dainiusjocas/babashka:latest as BABASHKA

FROM clojure:tools-deps-alpine as BUILDER
RUN apk add --no-cache zip
WORKDIR /var/task

COPY --from=BABASHKA /usr/local/bin/bb bb

ENV GITLIBS=".gitlibs/"
COPY lambda/bootstrap bootstrap

COPY deps.edn deps.edn

RUN clojure -Sdeps '{:mvn/local-repo "./.m2/repository"}' -Spath &gt; cp
COPY src/ src/
COPY resources/ resources/

RUN zip -q -r function.zip bb cp bootstrap .gitlibs/ .m2/ src/ resources/ deps.edn
See the first line here.

borkdude 2020-03-21T19:50:20.016200Z

ah, that is why your code worked for valtteri, this makes sense. thanks

πŸ‘ 2
borkdude 2020-03-21T22:25:04.016500Z

@dainius.jocas I wonder if a simple try/catch would have also sufficed as a workaround to this

borkdude 2020-03-21T22:25:18.016700Z

Or was it more like a hard unrecoverable crash?

borkdude 2020-03-21T22:29:16.016900Z

if try/catch around handle-pipe! works, then that would be preferable I think

borkdude 2020-03-21T22:35:16.017100Z

also, this commit ought to have fixed the problem: https://github.com/dmlloyd/graal/commit/dedcc86471b0209eeebf1df816b5f2590dc3361d which version of graalvm did you use to compile your docker image?

2020-03-21T22:43:42.017300Z

I haven't tried try/catch. Here is the error message from logs https://gist.github.com/dainiusjocas/feafeef5653ff2c6e8c7b2d9627a831d

2020-03-21T22:45:00.017500Z

I've used the same version as is specified in the Dockerfile

borkdude 2020-03-21T22:57:40.017700Z

Looking at that log, I suspect try/catch won't do it, but you could give it a try if it's not too much to ask. I did release v0.0.78 now and renamed the variable to BABASHKA_DISABLE_PIPE_SIGNAL_HANDLER

2020-03-21T23:11:10.017900Z

Tomorrow I'll try the try/catch approach. I also suspect that it will not work because lambda runtime panics when lambda tries to do anything with signals. But I'll try