Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queue: Add setting for maximumBatchingWindow #161

Merged
merged 6 commits into from
Mar 18, 2022

Conversation

jakejscott
Copy link
Contributor

I added an issue for this here #160

Copy link
Contributor

@t-richard t-richard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this 🙏

Just some minor comments or questions.

Documentation would also be appreciated 😁

@@ -130,6 +137,13 @@ export class Queue extends AwsConstruct {
// The default function timeout is 6 seconds in the Serverless Framework
const functionTimeout = configuration.worker.timeout ?? 6;

const maximumBatchingWindow =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably extract this in a private method as it's calculated 2 times

@@ -240,6 +252,7 @@ export class Queue extends AwsConstruct {
private appendFunctions(): void {
// The default batch size is 1
const batchSize = this.configuration.batchSize ?? 1;
const maximumBatchingWindow = this.queue.fifo ? 0 : this.configuration.maxBatchingWindow ?? MAX_BATCHING_WINDOW;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was previously set to undefined if FIFO is enabled. Why the change to 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can set it back to undefined no problem.

The reason why I set it to 0 was from the docs it says that 0 is the default: https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-params

And TypeScript was complaining in that unary expression :)

const maximumBatchingWindow =
configuration.fifo === true ? 0 : configuration.maxBatchingWindow ?? MAX_BATCHING_WINDOW;

// This should be 6 times the lambda function's timeout + MaximumBatchingWindowInSeconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

src/constructs/aws/Queue.ts Show resolved Hide resolved
@mnapoli mnapoli added the enhancement New feature or request label Feb 2, 2022
docs/queue.md Outdated
maxBatchingWindow: 5 # SQS will wait 5 seconds (so that it can batch any messages together) before delivering to lambda
```

*Default: 60 seconds*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#160 (comment)

Also I'm wondering if the default for maxBatchWindow should be 0 rather than 60 as it might catch people out?

Actually I agree with you… CloudFormation says the default is 0 for SQS:

image

I would say we should switch to 0, WDYT @t-richard?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK the batching window is mostly for cost/usage optimization. It will wait longer so it can eventually gather more messages for a batch which will avoid too much Lambda invocations.

Also, setting this to something else than 0 allows for batches of more than 10 items which we don't currently allow (but maybe we should 🙂).

There's no clear answer here, it depends on the use case people make from the queue. Sometimes performance will be prefered, sometimes usage optimization.

If I had to make a choice, I'd keep it as is. 60 seconds seems like a good default to me because it allows for better optimization without impacting performance too much. It will have no impact for batchSize of 1 and most of the time you are seeking optimization when using batches.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I wasn't sure if there were scenarios I was missing.

Let's use 0 as default then, because:

  • it's consistent with the actual default from AWS
  • it's not surprising (anything else is surprising because it makes the queue non-real-time, which isn't stated upfront in this construct)

As you mentioned, setting any other value is an optimization that users can make based on the specific usage for their queue, so let's keep it real-time by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update the PR with 0 as the default.

});
});

it("sets the SQS visibility timeout to 6 times the function timeout + max batching window in seconds when using custom maxBatchingWindow", async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@ldragone
Copy link

Hello, is there any news regarding the release of this modification?
It would be very useful to be able to change the hard-coded value of 60 seconds.

@predam
Copy link

predam commented Mar 2, 2022

Hello guys! I really need to change the value of maximumBatchingWindow , do you need any help in order to complete this merge?

@babyhuey
Copy link

Please can we merge this and get a release out? Really need this change

@mnapoli
Copy link
Member

mnapoli commented Mar 18, 2022

Looking great, thank you!

@mnapoli mnapoli merged commit 95c78dc into getlift:master Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants