Skip to content
This repository

Remove the option for thread_safe #188

Merged
merged 1 commit into from about 2 years ago

5 participants

Cyril David Damian Janowski Michel Martens Pieter Noordhuis Pierre Chapuis
Cyril David
cyx commented March 12, 2012

I think the @synchronizer is just adding an indirection which isn't useful and
just adds a small performance penalty for 99% of the users doing Redis.connect.

Damian Janowski
Owner

I'm +1, let's hear from @soveran and @pietern.

Michel Martens
Owner

+1

Pieter Noordhuis
Owner

Yes, sounds good. If users still want to disable it they can #include a fake Monitor mixin.

Pieter Noordhuis pietern merged commit 578c01f into from March 12, 2012
Pieter Noordhuis pietern closed this March 12, 2012
Pierre Chapuis

So how do you disable thread safety now? Is it as simple as this or am I missing something?

Redis.class_eval do
  def synchronize; yield; end
end

@pietern Can you give an example of your fake MonitorMixin? I am never using threads and monitors degrade performance significantly [EDIT: this is wrong, see below].

Damian Janowski
Owner

You can do that, or subclass Redis.

But clearly – why would you want to do that?

Pierre Chapuis

@djanowski Performance. I have to benchmark that again but I used to disable thread safety because I had noticed an important decrease in performance due to Monitor.

Damian Janowski
Owner

Check again, both @cyx and I made benchmarks and the impact was negligible.

Pierre Chapuis

I just did a quick bench and I found that the impact was indeed negligible.

My switch to thread unsafe goes back to February 2011 according to git so maybe things have improved in the meantime or maybe I was doing something wrong back then.

Anyway I will use the thread safe version unless I encounter problems again, in which case I will create a dedicated issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 13, 2012
Cyril David Remove the option for :thread_safe. 619fe28
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 1 addition and 10 deletions. Show diff stats Hide diff stats

  1. 11  lib/redis.rb
11  lib/redis.rb
@@ -43,16 +43,7 @@ def self.current=(redis)
43 43
   def initialize(options = {})
44 44
     @client = Client.new(options)
45 45
 
46  
-    if options[:thread_safe] == false
47  
-      @synchronizer = lambda { |&block| block.call }
48  
-    else
49  
-      @synchronizer = lambda { |&block| mon_synchronize { block.call } }
50  
-      super() # Monitor#initialize
51  
-    end
52  
-  end
53  
-
54  
-  def synchronize
55  
-    @synchronizer.call { yield }
  46
+    super() # Monitor#initialize
56 47
   end
57 48
 
58 49
   # Run code without the client reconnecting
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.