Browse files

Add a mutex to the logger_ext and wrap the buffer. When I benchmarked…

… the app at high concurrency (eg: ab -c 100) I was getting errors nearly half the time. With this fix I see 149 req/s with 0 errors
  • Loading branch information...
1 parent 354f282 commit 229a76d99eb800da757ab044e123785fc72f5f1b @rgarver rgarver committed with Dec 12, 2009
Showing with 18 additions and 14 deletions.
  1. +18 −14 lib/logger_ext.rb
View
32 lib/logger_ext.rb
@@ -8,28 +8,32 @@
end
class Logger
-
+
module Extensions
+ def self.included(base)
+ base.send(:define_method, :mutex) {@mutex ||= Mutex.new}
+ end
def intend
@intend = true
yield
- ensure
+ ensure
@intend = false
end
def buffer
- @buffer = []
- begin
- yield
- ensure
- buffer = @buffer
- @buffer = nil
- buffer.each do |method, msg|
- self.send(method, msg)
- end
+ self.mutex.synchronize do
+ @buffer = []
+ begin
+ yield
+ ensure
+ buffer = @buffer
+ @buffer = nil
+ buffer.each do |method, msg|
+ self.send(method, msg)
+ end
+ end
end
-
end
def info_with_time(msg)
@@ -53,11 +57,11 @@ def info_with_time(msg)
end
end
-
+
def self.current
@logger
end
-
+
def self.current=(logger)
@logger = logger
end

0 comments on commit 229a76d

Please sign in to comment.