8

There are two approaches of "deploying" a Java Lambda:

  • create a "fat" jar including all (unpackaged) dependencies, e.g. by use of the maven-shade-plugin
  • create a zip file containing my code and a lib directory with all dependencies as jar files

As it takes really long until the environment that executes our simple Lambda is "booted" (20-30s), I wonder if either approach is "faster" than the other or can be further speed up?

9
  • 1
    I have only tried the fat jar approach and I can think that one is faster as there are less files to unzip... but you can try that out and test it for yourself ;). I honestly don't think that either approach will be noticeable faster, but you can try. Commented Oct 20, 2015 at 18:23
  • I've deployed many "Fat jar" lambdas using the Maven shade plugin, most start in < 200ms depending on the lambda size, and subsequent executions run in < 100ms. You need to look at the following. Your lambda size? I've seen good performance using the 1024mb tier. What is going on when you start your application. Are you running spring or something? Commented Oct 27, 2015 at 19:00
  • Tried both approaches, didn't notice a difference. However, I can distinguish 3 different behaviours: Initial ramp-up of 20-30 "instances" in parallel to deal with the events (~150-250/minute) causes "boot times" of 30s+; regular event processing takes less than 100ms; in the following hours there are some isolated "boot events" that take ~5s. Commented Oct 28, 2015 at 8:54
  • @djhworld: only old school java stuff. I use the AWS SDK to decrypt credentials using KMS, then access a RDS MySQL. The latter seems to take ~3s for the first time and could explain the 5s "boot events". Commented Oct 29, 2015 at 15:37
  • Lambda will kill your JVM occasionally so you'll see some Lambda invocations needing to start it up again Commented Oct 29, 2015 at 15:37

1 Answer 1

5

I have found that the FAT jar is the optimal approach for lambdas with a footprint smaller than the MB limit. If you are over the MB limit, add the libraries to the lambda's lib folder and read them in.

With jars in the lib, I have found is that the lambda loads a little slower when it launches the first time in a container... the first time it is slower, subsequent launches in the same container are very fast... if it goes to a new container, one-time slow again.

Here is some good info on those cold starts: https://hackernoon.com/im-afraid-you-re-thinking-about-aws-lambda-cold-starts-all-wrong-7d907f278a4f

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.