4
votes

Spring Cloud Functions introduce Spring capabilities like auto-configuration, dependency injection, metrics etc. but they feel quite heavyweight compared to a plain AWS lambda function in Java.

The startup time is much longer etc. So, I was curious whether the idea was to have more than one function provided by a Spring Boot application with Spring Cloud Functions contained within it, or whether they should be one function per application?

Two example projects to demostrate the difference in start up time: - https://github.com/marcthomas2013/simple-aws-spring-cloud-function - https://github.com/marcthomas2013/simple-aws-lambda

Deploying both of these projects each as AWS Lambda functions and leaving the environment details (memory etc) the same apart from the timeout for the Spring Cloud Function needs to be increased to 30-45 seconds.

1
I’m curious to see some evidence that startup time is longer (than what?). Aside from that I’m not really sure what the question means: AWS only runs one function per deployment, but it should be obvious that Spring Cloud Function allows you to package them together if you want to. And how is that relevant to the concern about startup time? - Dave Syer
Thank you for commenting Dave. When I was talking about the start up time i was referrig to Spring Cloud Function vs Pure AWS Lambda. The warm up time of the very first call is slower for the spring cloud function when compared to the plain AWS lambda function. The ability to bundle functions up in one spring boot jar does seem beneficial but it would be good to understand if this is best practice or not. There are lots of things we can do as developers but it doesn’t necessarily mean it’s a good thing to do. - Marc Thomas
I will try and create a couple of similar projects to demonstrate the load time difference. It's not a big difference but there is a difference. I was thinking that if I were to create a spring cloud function application that contained many functions and supporting code that perhaps that might begin to increase the time for Spring Boot to start up even further. I'm just trying to understand if there is a problem before discovering one. - Marc Thomas
Start up time for a JVM is highly correlated with the number of classes loaded, and not at all with the number of beans in a Spring application. So I don’t think packaging will make any difference. You shouldn’t make assumptions like that. - Dave Syer
I have updated the original question with two example projects to demonstrate the difference in start up time between a vanilla Java AWS Lambda function and a Spring Cloud Function. - Marc Thomas

1 Answers

1
votes

I'm considering this tradeof myself. Fast warmup vs Spring Universe.

The SpringBoot project takes (much) longer to initialize because the Spring do a lot of work to get started. The advantage of course is that now you have the power and convenience of Spring instead of implementing everything yourself.

What I'm missing is a way to deploy a complete set of functions in one Lambda that can serve many different requests. I'm considering to implement a kind of dispatcher pattern where I only register 1 function that receives the Event. Then it analyses the event, dispatches it to the right handler within the same lambda for further processing. In that way I have a lot fewer lambdas registered (1 per app vs 1 per function). The warmup time is not a huge problem, as there are different ways of pre-warming and keeping the lambdas warm.

Therefore I'd go with a SpringBoot, Multifunction Lambda