formkiq / lambda-runtime-graalvm

Lambda Runtime using Graalvm
Apache License 2.0
18 stars 5 forks source link

Lambda handler class is instantiated for each request #8

Closed Morras closed 3 years ago

Morras commented 3 years ago

Each invocation of the LambdaFunction calls the constructor of the provided Lambda handler.

This goes against the normal behaviour of the Java runtime, which only instantiates the Lambda handler class on the first invocation. The [custom runtime documentation](Initialization tasks) also mentions that "Initialize the function" should happen in the Initialization step and not when processing tasks.

Looking at the code, I think it is a matter of moving line 207 of LambdaRuntime outside the while(true) loop, but don't have enough context to be sure that does not break anything else.

I might find some time to experiment with this next week.

mfriesen commented 3 years ago

Yes, I agree with you. I think the only reason it's there, is because if the clazz.getConstructor().newInstance(), throws an Exception, the handleInvocationException(..) method needs to be called.

I'll take a look and see if I can reorganize things.

mfriesen commented 3 years ago

Fixed in Release 2.2.2