File: active_record_threaded.rb

package info (click to toggle)
ruby-mysql2 0.5.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,096 kB
  • sloc: ansic: 3,459; ruby: 3,334; sh: 226; makefile: 3
file content (22 lines) | stat: -rw-r--r-- 549 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
require 'benchmark/ips'
require 'active_record'

number_of_threads = 25
opts = { database: 'test', pool: number_of_threads }

Benchmark.ips do |x|
  %w[mysql mysql2].each do |adapter|
    ActiveRecord::Base.establish_connection(opts.merge(adapter: adapter))

    x.report(adapter) do
      Array.new(number_of_threads) do
        Thread.new { ActiveRecord::Base.connection.execute('SELECT SLEEP(1)') }
      end.each(&:join)
    end
  end

  x.compare!
end