-
Notifications
You must be signed in to change notification settings - Fork 18
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
Conversation
app/jobs/solid_cable/trim_job.rb
Outdated
def perform(id = nil) | ||
id ||= ::SolidCable::Message.maximum(:id) | ||
|
||
return unless (id % (trim_batch_size / 2)).zero? |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries!
app/jobs/solid_cable/trim_job.rb
Outdated
|
||
return unless (id % (trim_batch_size / 2)).zero? | ||
|
||
::SolidCable::Message.where( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
No description provided.