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

Compact definitions during runtime #571

Merged
merged 2 commits into from
Sep 8, 2023

Conversation

spuun
Copy link
Member

@spuun spuun commented Sep 5, 2023

WHAT is this pull request doing?

With high churns (e.g. tons of short-lived queues) the definitions file can grow indefinitely. This will add compaction every 10000th "delete" frame. (10k was chosen completely arbitrary.)

HOW can this pull request be tested?

Run specs, or launch lavinmq and create and delete a queue more than 10k times.

Copy link
Member

@kickster97 kickster97 left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -19,6 +19,8 @@ module LavinMQ
include SortableJSON
include Stats

DEFINITIONS_DIRT_COMPACT_THREASHOLD = 10_000
Copy link
Member

Choose a reason for hiding this comment

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

let's make it a config variable

Copy link
Member

Choose a reason for hiding this comment

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

and call it deletes_compacts_definitions? as in "100 'delete' operations compacts the definition file"

# By doing equality comparision we'll only start one fiber
# without having to keep track if it's started or not
if @definitions_dirt_counter == DEFINITIONS_DIRT_COMPACT_THREASHOLD
spawn(name: "VHost #{name} definitions compact") { compact! }
Copy link
Member

Choose a reason for hiding this comment

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

why in a separate fiber? makes it potentially thread unsafe

Copy link
Member Author

Choose a reason for hiding this comment

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

I think one reason was that store_definition is called from a @definitions_lock.synchronize context, and that compact! also want the lock, and the other was to not block the current fiber with this (even though it's probably fast, and it will block by holding the lock).

spuun and others added 2 commits September 8, 2023 15:59
With high churns (e.g. tons of shortlived queues) the definitions file
can grow indefinitely. This will add compactation every 10000th "delete"
frame. (10k was chosen completley arbitrary.)
@carlhoerberg carlhoerberg force-pushed the compact-definitions-during-runtime branch from d955928 to 9a03fa4 Compare September 8, 2023 13:59
@carlhoerberg carlhoerberg merged commit 42cf225 into main Sep 8, 2023
@carlhoerberg carlhoerberg deleted the compact-definitions-during-runtime branch September 8, 2023 14:00
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.

3 participants