-
Notifications
You must be signed in to change notification settings - Fork 19
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 autotrimming #11
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/jobs/solid_cable/prune_job.rb → app/jobs/solid_cable/trim_job.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidCable | ||
class PruneJob < ActiveJob::Base | ||
class TrimJob < ActiveJob::Base | ||
def perform | ||
::SolidCable::Message.prunable.delete_all | ||
::SolidCable::Message.trimmable.delete_all | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConfigStubs | ||
extend ActiveSupport::Concern | ||
|
||
class ConfigStub | ||
def initialize(**) | ||
@config = ActiveSupport::OrderedOptions.new. | ||
update({ adapter: :test }.merge(**)) | ||
end | ||
|
||
def config_for(_file) | ||
@config | ||
end | ||
end | ||
|
||
def with_cable_config(**) | ||
Rails.stub(:application, ConfigStub.new(**)) { yield } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
require "config_stubs" | ||
|
||
class SolidCableTest < ActiveSupport::TestCase | ||
include ConfigStubs | ||
|
||
test "it has a version number" do | ||
assert SolidCable::VERSION | ||
end | ||
|
||
test "autotrimming when nothing is set" do | ||
assert_not Rails.application.config_for("cable").key?(:autotrim) | ||
assert SolidCable.autotrim? | ||
end | ||
|
||
test "autotrimming when set to false" do | ||
with_cable_config autotrim: false do | ||
assert_not SolidCable.autotrim? | ||
end | ||
end | ||
|
||
test "autotrimming when set to true" do | ||
with_cable_config autotrim: true do | ||
assert SolidCable.autotrim? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
While this should work pretty well with SQLite, I have some worries about how this would behave on MySQL or PostgreSQL.
It's deleting an unbounded number of messages so could lock for a fair amount of time. If the database is being replicated, that could also trigger replication lag as those deletes are processed.
Also there could generally be locking issues with concurrent jobs attempting to run the query.
The approach solid_cache takes is to delete small amounts of data but do it often.
We expire N records, but trigger the expiration after N/2 inserts so we have downward pressure on the cache size when it is too large. But we don't try to clear everything out at once as that could be millions and millions of records.
Solid Cache then has a slightly complicated process for deleting records in a concurrent safe manner, but I think we could maybe just rely on
SKIP LOCKED
here instead. That means you need MySQL 8.0 at least, but Solid Queue already requires that so I don't think it would be an issue to have Solid Cable do the same.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.
Put up #15 which should address this. Let me know what you think!