Skip to content

Instantly share code, notes, and snippets.

@jbgutierrez
Last active October 29, 2015 21:10
Show Gist options
  • Save jbgutierrez/d96382fdcfcebf90cdf0 to your computer and use it in GitHub Desktop.
Save jbgutierrez/d96382fdcfcebf90cdf0 to your computer and use it in GitHub Desktop.
Lazy logging errors to bost performace
# Meassure the difference:
# $ ab -r -n 10 http://127.0.0.1:4567/ | grep "Requests per second"
require 'sinatra'
require 'logger'
ERRLOG = Logger.new "#{__FILE__}.err"
ERRQ = Queue.new
Thread.new do
loop do
while msg = ERRQ.pop do
ERRLOG.error msg
end
sleep 2
end
end
disable :logging
get '/' do
ERRQ << "That thing happened again"
send_file __FILE__, disposition: 'inline'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment