funker icon indicating copy to clipboard operation
funker copied to clipboard

Should functions serve more than one request?

Open bfirsh opened this issue 8 years ago • 8 comments
trafficstars

The initial reason for this design was so that:

  • They were completely fresh every time
  • It was impossible to store state
  • There was only one degree of scaling (throughput of tasks running == throughput of function calls)
  • It just feels nice conceptually. task run == function call.

But, maybe this is a bit silly. The advantages of letting them be long-running is:

  • They're easier to scale (less task churn, connections are queued on server side, etc)
  • State can be stored if need be
  • It's just less weird, really.

bfirsh avatar Dec 01 '16 14:12 bfirsh

I think perhaps the function creator must assume the container is stateless/destroyed after each call. But as an optional optimisation you can keep the container running. Does that make sense? Not sure I've explained myself well...

amouat avatar Dec 01 '16 15:12 amouat

I would ban storing of state - that should go somewhere else. Otherwise it gets tricky to migrate between nodes etc.

amouat avatar Dec 01 '16 15:12 amouat

AWS Lambda functions last for 4 hours. Used to be 8. People do sometimes use this information, eg to cache stuff, save lookups if the function has been reused.

justincormack avatar Dec 01 '16 15:12 justincormack

Yep, that makes sense. People will still store state, but we can build in a max number of requests into each function or something so people have to design around the fact that it will disappear. (i.e. it can only be a cache)

bfirsh avatar Dec 01 '16 15:12 bfirsh

I'd just say you have to assume it can die at any moment. So put in a cache if you like, but make sure it works without it.

amouat avatar Dec 01 '16 15:12 amouat

Sure you have to do that anyway, as you will still get a random container, and they will be created with nothing in regularly anyway.

justincormack avatar Dec 01 '16 15:12 justincormack

Suggest random num reqs around a configurable mean.

That will smooth perf issues from mass restarts, and also make cache hits less predictable, which I guess is the aim.

ianmiell avatar Dec 04 '16 12:12 ianmiell

I think @justincormack has a good point - RE: Lambda functions being technically stateful and lasting up to 4 hours. I've been running this on an ARM/Pi Swarm where the cost of creating a container is higher.

alexellis avatar Dec 09 '16 10:12 alexellis