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

Schedule copay notification jobs in time intervals #12964

Merged
merged 0 commits into from
Jun 15, 2023

Conversation

ScottyRJames
Copy link
Contributor

@ScottyRJames ScottyRJames commented Jun 12, 2023

Summary

  • Sidekiq limiter was ideal with our use case
    • Window/bucket caused jobs to fail
    • Concurrent blocked other jobs from being processed
  • Use throttle approach
    • Schedule a certain amount of jobs for every time period
    • Period and batch size determined by settings values
    • Tweak as needed

Related issue(s)

- department-of-veterans-affairs/va.gov-team#0000
https://github.com/department-of-veterans-affairs/devops/pull/13134
https://github.com/department-of-veterans-affairs/vsp-infra-application-manifests/pull/2010

Testing done

  • Tested with local sidekiq queue

What areas of the site does it impact?

Sidekiq/copay notifications

Acceptance criteria

  • I fixed|updated|added unit tests and integration tests for each feature (if applicable).
  • No error nor warning in the console.
  • Events are being sent to the appropriate logging solution
  • Documentation has been updated (link to documentation)
  • No sensitive information (i.e. PII/credentials/internal URLs/etc.) is captured in logging, hardcoded, or specs
  • Feature/bug has a monitor built into Datadog or Grafana (if applicable)
  • If app impacted requires authentication, did you login to a local build and verify all authenticated routes work as expected
  • I added a screenshot of the developed feature

Requested Feedback

Any concern for spinning up batches of jobs every couple minutes?

@ScottyRJames ScottyRJames marked this pull request as ready for review June 12, 2023 18:08
@ScottyRJames ScottyRJames requested review from a team as code owners June 12, 2023 18:08
@va-vsp-bot va-vsp-bot requested a deployment to throttle-copay-notification-queue/main/main June 12, 2023 18:08 In progress
@va-vsp-bot va-vsp-bot requested a deployment to throttle-copay-notification-queue/main/main June 12, 2023 19:28 In progress
@va-vfs-bot va-vfs-bot temporarily deployed to throttle-copay-notification-queue/main/main June 12, 2023 19:32 Inactive
@va-vsp-bot va-vsp-bot requested a deployment to throttle-copay-notification-queue/main/main June 13, 2023 12:25 In progress
@va-vfs-bot va-vfs-bot temporarily deployed to throttle-copay-notification-queue/main/main June 13, 2023 12:26 Inactive
@va-vsp-bot va-vsp-bot requested a deployment to throttle-copay-notification-queue/main/main June 13, 2023 12:29 In progress
@va-vfs-bot va-vfs-bot temporarily deployed to throttle-copay-notification-queue/main/main June 13, 2023 12:31 Inactive
@va-vsp-bot va-vsp-bot requested a deployment to throttle-copay-notification-queue/main/main June 13, 2023 15:45 In progress
@va-vfs-bot va-vfs-bot temporarily deployed to throttle-copay-notification-queue/main/main June 13, 2023 16:00 Inactive
@va-vsp-bot va-vsp-bot requested a deployment to throttle-copay-notification-queue/main/main June 13, 2023 16:37 In progress
@va-vfs-bot va-vfs-bot temporarily deployed to throttle-copay-notification-queue/main/main June 13, 2023 16:39 Inactive
@ryan-mcneil
Copy link
Contributor

@ScottyRJames just curious - do you have other team members that you could get to give their blessing before it gets to us? It's a process that we're slowly rolling out/requesting for all PRs, as it's difficult for us to give thorough PR reviews, especially when we don't have the full context or understanding of the business reqs.

@ryan-mcneil ryan-mcneil self-assigned this Jun 13, 2023
@va-vsp-bot va-vsp-bot requested a deployment to throttle-copay-notification-queue/main/main June 14, 2023 13:48 In progress
@va-vsp-bot va-vsp-bot requested a deployment to throttle-copay-notification-queue/main/main June 14, 2023 13:48 In progress
@va-vfs-bot va-vfs-bot temporarily deployed to throttle-copay-notification-queue/main/main June 14, 2023 13:48 Inactive
@kjsuarez kjsuarez self-assigned this Jun 14, 2023
@kjsuarez
Copy link
Contributor

LGTM 👍

@va-vfs-bot va-vfs-bot temporarily deployed to throttle-copay-notification-queue/main/main June 14, 2023 13:54 Inactive
@va-vsp-bot va-vsp-bot requested a deployment to throttle-copay-notification-queue/main/main June 14, 2023 16:21 In progress
@ScottyRJames
Copy link
Contributor Author

@ryan-mcneil Thanks for the heads up on this new process, @kjsuarez is another BE engineer on the debt resolution team and left a review earlier. Also added these files to our team within CODEOWNERSHIP to try to reduce the platform dependency for our team's managed code

@va-vfs-bot va-vfs-bot temporarily deployed to throttle-copay-notification-queue/main/main June 14, 2023 16:32 Inactive
@va-vsp-bot va-vsp-bot requested a deployment to throttle-copay-notification-queue/main/main June 14, 2023 18:57 In progress
@va-vfs-bot va-vfs-bot temporarily deployed to throttle-copay-notification-queue/main/main June 14, 2023 18:57 Inactive
@va-vsp-bot va-vsp-bot requested a deployment to throttle-copay-notification-queue/main/main June 14, 2023 20:22 In progress
@va-vfs-bot va-vfs-bot temporarily deployed to throttle-copay-notification-queue/main/main June 14, 2023 20:22 Inactive
Comment on lines 20 to 24
unique_statements.each_with_index do |statement, index|
# For every BATCH_SIZE jobs, enqueue the next BATCH_SIZE amount of jobs JOB_INTERVAL seconds later
CopayNotifications::NewStatementNotificationJob.perform_in(
JOB_INTERVAL * (index / BATCH_SIZE), statement
)
Copy link
Contributor

Choose a reason for hiding this comment

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

@ScottyRJames I just wanted to make sure this is what you intended. If JOB_INTERVAL and BATCH_SIZE were 90 and 100 respectively, then we'd be kicking off a new job every .9 seconds (not JOB_INTERVAL seconds), correct? Maybe I'm missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ryan-mcneil It will kick off 100 new jobs every 90 seconds rather since ruby division defaults to the floor with integers.

For example, if one of the statements had index 127 it would be evaluated like 90 * (127 / 100) -> 90 * 1 which perform_in will take and schedule the job at 90 seconds later. So if unique_statements were to be 500 statements long each of the slated times would be like

Indices Start Time
0 - 99 Time.now
100 - 199 Time.now + 90s
200 - 299 Time.now + 180s
300 - 399 Time.now + 270s
400 - 499 Time.now + 360s
500 Time.now + 450s

If we wanted to go towards your thinking, it would look like like JOB_INTERVAL * (index / BATCH_SIZE).to_f. I think by default Sidekiq checks for new jobs every 5 seconds so it wouldn't be to the exact millisecond that it's scheduled at. It's still workable if you think it would be better to stagger the jobs even more rather than spinning up a batch at a time but it would be more like 6-7 new jobs every 5 seconds vs a new job every .9 seconds.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, you're right. I wasn't considering the ruby division. Just wanted to make sure you considered it, and it looks like you're a step ahead of me 👌

@HeatherRienks
Copy link

following

@va-vsp-bot va-vsp-bot requested a deployment to throttle-copay-notification-queue/main/main June 15, 2023 13:46 In progress
@va-vfs-bot va-vfs-bot temporarily deployed to throttle-copay-notification-queue/main/main June 15, 2023 13:47 Inactive
@ScottyRJames ScottyRJames requested a review from ryan-mcneil June 15, 2023 16:27
@va-vsp-bot va-vsp-bot requested a deployment to throttle-copay-notification-queue/main/main June 15, 2023 16:54 In progress
Copy link
Contributor

@ryan-mcneil ryan-mcneil left a comment

Choose a reason for hiding this comment

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

👌

@ScottyRJames ScottyRJames merged commit 1deb266 into master Jun 15, 2023
@ScottyRJames ScottyRJames deleted the throttle-copay-notification-queue branch June 15, 2023 18:22
ryan-mcneil pushed a commit that referenced this pull request Dec 11, 2023
* Schedule jobs using throttle technique

* Fix time in comment

* spread_interval -> job_interval

* Make comment more clear

* Add spec for batch processing

* Add debt related workers to codeowners

* Remove CODEOWNERS change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants