zappa / Zappa

Serverless Python
https://zappa.ws/zappa
MIT License
3.35k stars 362 forks source link

Provide configuration for reserved and provisioned concurrency #1267

Closed monkut closed 7 months ago

monkut commented 1 year ago

Lambda now provides a reserved and provisioned concurrency setting/configuration.

https://docs.aws.amazon.com/lambda/latest/dg/lambda-concurrency.html#reserved-and-provisioned

https://docs.aws.amazon.com/lambda/latest/dg/configuration-concurrency.html

zappa currently provides a keep_warm function to periodically keep a single lambda instance "warm". However, the current keep_warm method is not expected to reduce cold starts for more than a single instance.

This issue requests that reserved and provisioned concurrency are properly integrated with zappa. Potentially consider depreciating keep_warm in favor of these new concurrency settings.

javulticat commented 10 months ago

Hey, just wanted to provide some quick thoughts here! (Note: Ok, now having finished with writing what follows, it seems my thoughts turned out to be not-so-quick 🙃 - sorry, I'll provide a quick TL;DR.)

TL;DR

Unless new features are critical (e.g., supporting a new Python version), we should probably not add them to Zappa right now, as I'm in the process of replacing Zappa's ancient self-management of infra with the ability to interface with modern Infrastructure-as-Code (IaC) platforms that will enable all of the current features of Zappa, plus allow the use of pretty much every AWS feature that anyone could ever want.

Regarding the two features specifically mentioned, as far as adding either to Zappa:

Of course, using IaC, knowledgeable users can enable either of these features (and countless more), but doing so via IaC requires far more intentionality than simply playing around with the settings found in a single JSON file (zappa_settings.json).


Background

For context, here are a few of the premises of Zappa (all IMHO, of course): what it is (and is not) and the scope of the role it should aim to play within the broader context of the overall AWS ecosystem and related tools:

Discussion

Whew 😅. Ok, with that context in mind, let's discuss the features that were brought up.

Introduction

"Reserved concurrency" and "provisioned concurrency" are actually quite different features, targeting different use cases (with potentially drastically different cost implications) so I think each should be discussed separately. To that end:

Reserved Concurrency

Description

Limits how many simultaneous invocations there may be of a given Lambda function. For example, most accounts start out with a total limit of 1000 simultaneous Lambda invocations across all functions (note: this is a limit that can easily be raised by asking AWS support - I've seen it be set well into the millions at large, corporate entities - AWS just prefers to start accounts with relatively low limits so an inexperienced user/org doesn't accidentally run up a $100k+ bill due to a bug that is launching way more Lambda invocations than expected), and, assuming that an AWS account has that default level of 1000, then setting the "reserved concurrency" on function x means that function x will be able to have up to 400 simultaneous Lambda invocations, but cannot exceed 400, even if there is demand for more. What it also means is that all other functions would now only have a pool of 600 "unreserved" Lambda invocations they can simultaneously share, as the 400 "reserved" for function x cannot be used by any other function.

What that means for Zappa

Arguments against/for it being added to Zappa's config:

Summary

If the community actually does indicate that they have a strong desire for the ability to enable "reserved concurrency" via Zappa's config, and someone submitted a high-quality PR with complete test coverage that didn't require an extensive review process, I suppose I wouldn't be opposed to merging it, as full integration with IaC platforms will likely take a while. But, this isn't something I would personally commit to adding support for, as I don't think it's an important enough feature to warrant pausing my work toward replacing Zappa's outdated manual infra configuration system with the ability to use various IaC platforms to do the infra configuration for Zappa.

Provisioned Concurrency

Description

Keeps a defined amount of Lambda function instances active/"spun up"/warm, regardless of activity. For example, if the "provisioned concurrency" of function x is set to 100, then 100 instances of function x will run 24/7 indefinitely, even if function x is not invoked for days/weeks/months/years. If function x then receives 500 simultaneous invocations, 100 of those invocations will be able to take advantage of a "warm start", while the other 400 will have to "cold start". After ~5 minutes after the completion of function x's invocation, if function x does not again receive more than 100 simultaneous invocations, the 400 instances that were spun up in addition to the 100 kept active by "provisioned concurrency" will get spun down again. Users of "provisioned concurrency" not only have to pay for the Lambda runtime, but they also have to pay an additional fee is levied by AWS for the use of the "provisioned concurrency" feature. In other words, the cost/min of running a Lambda function instance via "provisioned concurrency" is greater than the cost/min of running a Lambda function instance that is created normally, even if it is then "kept warm" by other means (discussed below).

What that means for Zappa

Arguments against/for it being added to Zappa's config:

Summary

I really don't think adding "provisioned concurrency" support to Zappa is a good idea. The fact that it would break the implicit contract Zappa has had with its users since its inception that "you can (safely) use Zappa to mess around with deploying your apps to Lambda" by adding a setting that could deploy a Lambda function that would immediately begin accruing charges on their AWS bill is a complete non-starter by itself, IMO, and that's far from the only concern it would bring.

github-actions[bot] commented 7 months ago

Hi there! Unfortunately, this Issue has not seen any activity for at least 90 days. If the Issue is still relevant to the latest version of Zappa, please comment within the next 10 days if you wish to keep it open. Otherwise, it will be automatically closed.

github-actions[bot] commented 7 months ago

Hi there! Unfortunately, this Issue was automatically closed as it had not seen any activity in at least 100 days. If the Issue is still relevant to the latest version of Zappa, please open a new Issue.