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

QueueAdapters now does lazy lookup #19311

Merged
merged 1 commit into from
Mar 13, 2015
Merged

Conversation

tamird
Copy link
Contributor

@tamird tamird commented Mar 12, 2015

mutex.synchronize do
return instances.fetch(hash) if instances.key?(hash)

@instances[hash] ||= lookup(name).new(*adapter_args, &block)
Copy link
Member

Choose a reason for hiding this comment

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

Does we need to cache?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so - in particular, we may have an adapter that carries a connection object on it - we would not want to create multiple identical connections

@thedarkone
Copy link
Contributor

Correct me, if I am mistaken: isn't QueueAdapter.interpret_adapter not a hot path? Why are we rolling out a custom caching mechanism, why not simply use a plain mutex around the whole #interpret_adapter method?

Also, does setting QueueAdapterClass.queue_adapter= need to be thread-safe? The general rule of thumb in Rails is that class-level configuration assignments are on only to done during a single-threaded boot sequence?

Is there a reason you're not using ThreadSafe::Cache (ie: cache = ThreadSafe::Cache.new; cache.compute_if_absent(some_key) {lookup(name).new(*adapter_args, &block)})?

@tamird
Copy link
Contributor Author

tamird commented Mar 13, 2015

Correct me, if I am mistaken: isn't QueueAdapter.interpret_adapter not a hot path? Why are we rolling out a custom caching mechanism, why not simply use a plain mutex around the whole #interpret_adapter method?

Probably true - just erring on the side of caution.

Also, does setting QueueAdapterClass.queue_adapter= need to be thread-safe? The general rule of thumb in Rails is that class-level configuration assignments are on only to done during a single-threaded boot sequence?

Again, probably true - just erring on the side of caution.

Is there a reason you're not using ThreadSafe::Cache (ie: cache = ThreadSafe::Cache.new; cache.compute_if_absent(some_key) {lookup(name).new(*adapter_args, &block)})?

Just plain ignorance. I'll switch to that.


private

attr_accessor :cache
Copy link
Member

Choose a reason for hiding this comment

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

We can use a @cache ivar, no need for private reader/writer methods

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

@tamird
Copy link
Contributor Author

tamird commented Mar 13, 2015

Removed the caching - I'll save it for a future PR.

rafaelfranca added a commit that referenced this pull request Mar 13, 2015
`QueueAdapters` now does lazy lookup
@rafaelfranca rafaelfranca merged commit 03148ec into rails:master Mar 13, 2015
@tamird tamird deleted the aj-adapter-lookup branch March 13, 2015 14:45
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.

None yet

6 participants