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

Multi worker setup #6

Merged
merged 13 commits into from
Jan 24, 2022
Merged

Multi worker setup #6

merged 13 commits into from
Jan 24, 2022

Conversation

julianrubisch
Copy link
Owner

Bug Fix

Description

Previously, blocks were fetched from a singleton which (obviously) cannot work across multiple processes.

This PR introduces a way to extract the actual ERB source of the cubism block via a Preprocessor and actually render it inline in Broadcaster. Since kredis is in the picture already, it is used to store the block location, source, as well as resource and user IDs under a combined hashed key.

@julianrubisch julianrubisch merged commit 620ebf6 into main Jan 24, 2022
@julianrubisch julianrubisch deleted the multi-worker-setup branch January 24, 2022 12:05
Comment on lines +7 to +15
resource_user_key = "#{resource.to_gid}:#{user.to_gid}"
digested_block_key = ActiveSupport::Digest.hexdigest("#{block_location}:#{resource_user_key}")

# the store item (identified by block location, resource, and user) might already be present
store_item = Cubism.store[digested_block_key] || Cubism::BlockStoreItem.new(
block_location: block_location,
resource_gid: resource.to_gid.to_s,
user_gid: user.to_gid.to_s
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps an almost meaningless "optimization", but we don't need to get the gid twice for resource and user:

Suggested change
resource_user_key = "#{resource.to_gid}:#{user.to_gid}"
digested_block_key = ActiveSupport::Digest.hexdigest("#{block_location}:#{resource_user_key}")
# the store item (identified by block location, resource, and user) might already be present
store_item = Cubism.store[digested_block_key] || Cubism::BlockStoreItem.new(
block_location: block_location,
resource_gid: resource.to_gid.to_s,
user_gid: user.to_gid.to_s
)
resource_gid = resource.to_gid.to_s
user_gid = user.to_gid.to_s
resource_user_key = [resource_gid, user_gid].join(":")
digested_block_key = ActiveSupport::Digest.hexdigest("#{block_location}:#{resource_user_key}")
# the store item (identified by block location, resource, and user) might already be present
store_item = Cubism.store[digested_block_key] || Cubism::BlockStoreItem.new(
block_location: block_location,
resource_gid: resource_gid,
user_gid: user_gid
)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thanks! Seemingly I can't commit to an already merged PR though 🙈

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