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

Enable automatic message visibility refresh #87

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Conversation

notac
Copy link

@notac notac commented Sep 20, 2022

Description of changes:

This PR will enable the auto-refresh of the visibility timeout of active messages.

This will allow users to use much lower default visibility timeouts, which will ensure messages can be returned to the queue promptly after a job fails, etc.

NOTE: I didn't do the work of adding automated tests yet, will do so if the work is acceptable.

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license.

@mullermp mullermp added the pr/needs-review This PR needs a review from a Member. label Sep 20, 2022
Copy link
Contributor

@alextwoods alextwoods 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 the contribution! Overall approach I believe makes sense - this is a useful feature!

lib/aws/rails/sqs_active_job/executor.rb Outdated Show resolved Hide resolved
lib/aws/rails/sqs_active_job/executor.rb Outdated Show resolved Hide resolved
lib/aws/rails/sqs_active_job/executor.rb Outdated Show resolved Hide resolved
lib/aws/rails/sqs_active_job/executor.rb Outdated Show resolved Hide resolved
Copy link

@jshah jshah left a comment

Choose a reason for hiding this comment

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

left a few comments to understand this approach, let me know if they make sense

lib/aws/rails/sqs_active_job/executor.rb Outdated Show resolved Hide resolved
Copy link

@jshah jshah left a comment

Choose a reason for hiding this comment

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

We also want this refresh to happen during the shutdown method if the jobs are in the middle of being run.

nvm, I misunderstood the approach

while refresh_monitor
begin
# Extend the visibility timeout to the provided refresh timeout
message.change_visibility({ visibility_timeout: @visibility_refresh })
Copy link

Choose a reason for hiding this comment

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

what if the visibility_timeout is already set to the max limit of 12 hours?

Copy link
Author

Choose a reason for hiding this comment

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

If this is lower, what is submitted to change_visibility will be respected first.

Copy link

Choose a reason for hiding this comment

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

I would expect this to throw an error since 12 hours is the max. We can't extend past that.

Additionally, I'm thinking of this scenario:

  1. visiblity_timeout is 2 hours, visbility_refresh is 1 hour
  2. we receive a message, and start processing. visibility_timeout is extended to 3 hours
  3. sleep for 30 minutes
  4. 30 minutes elapses (30 mins total), visibility_timeout is extended to 4 hours
  5. 30 minutes elapses (1 hour total), visibility_timeout is extended to 5 hours
  6. ...

In the above scenario, won't we hit the limit much faster than the time the job has to run? Basically what I'm trying to say is that we should cover the case where the visiblity_timeout has already maxed out.

# Extend the visibility timeout to the provided refresh timeout
message.change_visibility({ visibility_timeout: @visibility_refresh })
# Wait half the refresh timeout, and repeat
sleep(@visibility_refresh / 2.0)
Copy link

Choose a reason for hiding this comment

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

trying to understand the use case of where a message completes but this thread is still sleeping. Will the worker start on the next message or will it be stalled because this thread is sleeping?

If the worker starts on the next message, will that message have a new thread for @monitor set up? Is there a case where consequent jobs finish quickly, and the monitor just has a bunch of sleeping threads and could eventually run out of threads to monitor the incoming messages

Copy link

Choose a reason for hiding this comment

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

also, does the @monitor thread need to have shutdown logic and be added to https://github.com/aws/aws-sdk-rails/blob/main/lib/aws/rails/sqs_active_job/poller.rb#L62-L64?

Copy link
Author

Choose a reason for hiding this comment

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

Nah, as soon as the parent thread exits refresh_monitor will be set to false so this one will shut down. If a new job is picked up a new thread will be spun.

Copy link

Choose a reason for hiding this comment

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

Nah, as soon as the parent thread exits refresh_monitor will be set to false so this one will shut down

but when will it shut down? if this thread is sleeping, it could be shut down way after the parent thread finishes

@mullermp
Copy link
Contributor

Thanks for making updates. It looks like tests are failing, likely syntax.

@mullermp mullermp added the pr/blocked This PR cannot be merged or reviewed, because it is blocked for some reason. label Nov 21, 2022
@mullermp
Copy link
Contributor

@notac We're looking to release a minor version of this gem soon with some other changes. I've fixed the syntax errors for this PR. This cannot be merged until we add some tests and address comments from @jshah. Were you still interested in moving this forward?

@mullermp mullermp added pr/work-in-progress This PR is a draft and needs further work. pr/do-not-merge This PR should not be merged at this time. and removed pr/blocked This PR cannot be merged or reviewed, because it is blocked for some reason. labels Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/do-not-merge This PR should not be merged at this time. pr/needs-review This PR needs a review from a Member. pr/work-in-progress This PR is a draft and needs further work.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants