21.05.2014 Views

PostgreSQL as a secret weapon for high-performance ... - PGCon

PostgreSQL as a secret weapon for high-performance ... - PGCon

PostgreSQL as a secret weapon for high-performance ... - PGCon

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Rails Per<strong>for</strong>mance > Per<strong>for</strong>mance Tests<br />

Benchmarks <strong>as</strong> a special kind of tests:<br />

def benchmark(options = {})<br />

(0..100).each do |i|<br />

GC.start<br />

pid = <strong>for</strong>k do<br />

begin<br />

out = File.open("values", "a")<br />

ActiveRecord::B<strong>as</strong>e.transaction do<br />

elapsed_time = Benchmark::realtime do<br />

request_method = options[:post] ? :post : :get<br />

send(request_method, options[:route])<br />

end<br />

out.puts elapsed_time if i > 0<br />

out.close<br />

raise CustomTransactionError<br />

end<br />

rescue CustomTransactionError<br />

exit<br />

end<br />

end<br />

Process::waitpid pid<br />

ActiveRecord::B<strong>as</strong>e.connection.reconnect!<br />

end<br />

values = File.read("values")<br />

print "#{mean(values).to_02f} ± #{sigma(values).to_02f}\n"<br />

end<br />

Gleb Arshinov & Alex Dymo ● <strong>PostgreSQL</strong> <strong>as</strong> a <strong>secret</strong> <strong>weapon</strong> <strong>for</strong> <strong>high</strong>-per<strong>for</strong>mance Ruby on Rails applications ● <strong>PGCon</strong> 2010 26 / 58

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!