This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-04
Channels
- # announcements (7)
- # aws (5)
- # babashka (72)
- # beginners (43)
- # calva (12)
- # cider (9)
- # clara (3)
- # clj-kondo (12)
- # cljdoc (32)
- # cljs-dev (10)
- # cljsrn (1)
- # clojure (78)
- # clojure-dev (50)
- # clojure-europe (17)
- # clojure-gamedev (8)
- # clojure-nl (1)
- # clojure-spec (30)
- # clojure-uk (3)
- # clojurescript (52)
- # core-async (1)
- # cursive (5)
- # datomic (8)
- # emacs (58)
- # events (2)
- # fulcro (5)
- # graalvm (7)
- # holy-lambda (37)
- # honeysql (9)
- # jobs (5)
- # leiningen (3)
- # lsp (7)
- # lumo (2)
- # malli (3)
- # meander (13)
- # membrane-term (64)
- # missionary (19)
- # music (3)
- # nextjournal (8)
- # off-topic (29)
- # pathom (16)
- # polylith (14)
- # portal (16)
- # re-frame (2)
- # reagent (5)
- # sci (14)
- # shadow-cljs (20)
- # spacemacs (6)
- # sql (1)
- # tools-deps (58)
- # vim (14)
Q: is there any way to attach a shutdown hook fn in HL? i.e. when lambda is unloaded because it’s idle too long, I want a fn to run which disposes network connections
You mean something like: 1. When the lambda has handled the payload. 2. And there is no more payloads, but Lambda is alive. 3. Call the hook?
Or maybe something like: 1. Lambda called the user handler. 2. Lambda is waiting for the response. 3. It's close to timeout, so call the hook?
neither. when the lambda is shutting down because it’s been idle for too long. then I want to be able to call a hook so I can clean up network connections held in an atom
This is not possible.
would be useful for anyone wanting to see when their lambdas are shutdown since it could write to the logs
Basically AWS Lambda does not provide any CPU or memory to the idle lambda. All the operations are stopped.
Otherwise the runtime loop white true would run forever
But it doesn't.
Hmm. Only the regular Linux shutdown hooks, but I don't know whether the code will be invoked. I can try.
I will have some more time in few hours, so I will investigate it. 🙂
I'm reading this: https://docs.aws.amazon.com/lambda/latest/dg/runtimes-modify.html. It seems that I would need to create an extension for this.
It looks like the runtime is killed immediately, while the extensions have 500ms to shutdown gracefully. ;O
Ok I do understand what to do, but be aware that you will pay additional $ for this.
https://docs.aws.amazon.com/lambda/latest/dg/runtimes-extensions-api.html#runtimes-extensions-registration-api The hook will be in:
(h/entrypoint ~lambdas {:shutdown-hook (fn [])})
sure. it would only be for the extra cpu time of the hook fn right? these hooks should be very small/fast so that this cost is low
even just an extra log line will be useful for most people because then they can see how quickly lambdas are unloaded i.e. when cold starts will be required again
I'm not sure how this gonna work. I think after the shutdown-hook is called the AWS will not wait? Or maybe I should manually exit the process.
> sure. it would only be for the extra cpu time of the hook fn right? these hooks should be very small/fast so that this cost is low Yeah
Cold start would be a little bit higher, since I have to register the internal extension.
Probably few ms, when shutdown-hook is used
Yeah. It will be optional.
Shutdown event is not supported via internal extension. If I create an external extension still you would not be able to access the resources, since the extension runs in a separate process.
{:headers {nil #object[java.util.Collections$UnmodifiableRandomAccessList 0x176ce308 [HTTP/1.1 403 Forbidden]], Date #object[java.util.Collections$UnmodifiableRandomAccessList 0x3ce7b033 [Fri, 05 Nov 2021 13:29:08 GMT]], Content-Length #object[java.util.Collections$UnmodifiableRandomAccessList 0x1ccbf9ac [116]], Content-Type #object[java.util.Collections$UnmodifiableRandomAccessList 0xd4b0649 [application/json]]}, :success? false, :status 403, :body {:errorMessage SHUTDOWN: ShutdownEventNotSupportedForInternalExtension, :errorType Extension.InvalidEventType}}
Nope. Only via external extension that run in the different process.
But this is not something I want to do
my use-case for this was cleaning up Redis connections but I’ve discovered (through load testing) that they are cleaned up automatically as the lambdas are unloaded
Cool. Also great you’re doing load testing. You prove how HL is a stable runtime