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

Enhance trimming to be more performant #15

Merged
merged 16 commits into from
Sep 12, 2024
Merged

Enhance trimming to be more performant #15

merged 16 commits into from
Sep 12, 2024

Conversation

npezza93
Copy link
Collaborator

No description provided.

def perform(id = nil)
id ||= ::SolidCable::Message.maximum(:id)

return unless (id % (trim_batch_size / 2)).zero?
Copy link

Choose a reason for hiding this comment

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

I think it would be better to do this check before creating the job, as we'll end up with a lot of no-op jobs otherwise.

We might be better using a random value rather than id, I could imagine cases say where there are not a lot of message coming through and you have a bunch of processes getting the same value for id.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it would be better to do this check before creating the job, as we'll end up with a lot of no-op jobs otherwise.

The job is running as perform_now so we shouldn't be enqueuing anything into the queue and we dont pay a penalty for no-oping.

We might be better using a random value rather than id, I could imagine cases say where there are not a lot of message coming through and you have a bunch of processes getting the same value for id

Ahh ok ill check that out

Copy link

Choose a reason for hiding this comment

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

The job is running as perform_now so we shouldn't be enqueuing anything into the queue and we dont pay a penalty for no-oping.

Oh sorry, I missed that 🙈

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No worries!


return unless (id % (trim_batch_size / 2)).zero?

::SolidCable::Message.where(
Copy link

Choose a reason for hiding this comment

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

This won't be valid on MySQL, you'll get something like:
You can't specify target table 'solid_cable_messages' for update in FROM clause.

I think something like this will work:

::SolidCable::Message.transaction do
   ids = ::SolidCable::Message.trimmable.non_blocking_lock.limit(trim_batch_size).pluck(:id)
   ::SolidCable::Message.where(id: ids).delete_all
end

As an aside, it would be good to run the tests against MySQL and PostgreSQL.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ha yea working on updating the test suite to run through all of them.

This won't be valid on MySQL, you'll get something like:
You can't specify target table 'solid_cable_messages' for update in FROM clause.

Whoops thanks

@npezza93 npezza93 merged commit d7d0832 into main Sep 12, 2024
3 of 4 checks passed
@npezza93 npezza93 deleted the trimming branch September 12, 2024 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants