Commit d0716a0fb033e2be1db7ab1f619c98ea605d9d38

Authored by Andrew Kane
1 parent 929c4ce7

Updated benchmark script [skip ci]

Showing 2 changed files with 49 additions and 11 deletions   Show diff stats
benchmark/Gemfile
... ... @@ -3,9 +3,13 @@ source "https://rubygems.org"
3 3 # Specify your gem's dependencies in searchkick.gemspec
4 4 gemspec path: "../"
5 5  
6   -gem "sqlite3"
  6 +# gem "sqlite3"
  7 +gem "pg"
7 8 gem "activerecord", "~> 5.0.0"
8 9 gem "activerecord-import"
  10 +gem "activejob"
  11 +gem "redis"
  12 +gem "sidekiq"
9 13  
10 14 # performance
11 15 gem "typhoeus"
... ...
benchmark/benchmark.rb
... ... @@ -2,19 +2,27 @@ require "bundler/setup"
2 2 Bundler.require(:default)
3 3 require "active_record"
4 4 require "benchmark"
  5 +require "active_support/notifications"
  6 +
  7 +ActiveSupport::Notifications.subscribe "request.searchkick" do |*args|
  8 + event = ActiveSupport::Notifications::Event.new(*args)
  9 + p event.duration
  10 +end
  11 +
  12 +ActiveJob::Base.queue_adapter = :sidekiq
  13 +
  14 +Searchkick.redis = Redis.new
5 15  
6 16 ActiveRecord::Base.default_timezone = :utc
7 17 ActiveRecord::Base.time_zone_aware_attributes = true
8   -ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
  18 +# ActiveRecord::Base.establish_connection adapter: "sqlite3", database: "/tmp/searchkick"
  19 +ActiveRecord::Base.establish_connection "postgresql://localhost/searchkick_demo_development"
  20 +# ActiveRecord::Base.logger = Logger.new(STDOUT)
9 21  
10   -ActiveRecord::Migration.create_table :products do |t|
11   - t.string :name
12   - t.string :color
13   - t.integer :store_id
14   -end
  22 +ActiveJob::Base.logger = nil
15 23  
16 24 class Product < ActiveRecord::Base
17   - searchkick batch_size: 100
  25 + searchkick batch_size: 1000
18 26  
19 27 def search_data
20 28 {
... ... @@ -25,7 +33,15 @@ class Product &lt; ActiveRecord::Base
25 33 end
26 34 end
27 35  
28   -Product.import ["name", "color", "store_id"], 20000.times.map { |i| ["Product #{i}", ["red", "blue"].sample, rand(10)] }
  36 +total_docs = 100000
  37 +
  38 +# ActiveRecord::Migration.create_table :products, force: :cascade do |t|
  39 +# t.string :name
  40 +# t.string :color
  41 +# t.integer :store_id
  42 +# end
  43 +
  44 +# Product.import ["name", "color", "store_id"], total_docs.times.map { |i| ["Product #{i}", ["red", "blue"].sample, rand(10)] }
29 45  
30 46 puts "Imported"
31 47  
... ... @@ -35,19 +51,37 @@ stats = nil
35 51  
36 52 # p GetProcessMem.new.mb
37 53  
  54 +Product.searchkick_index.delete rescue nil
  55 +
38 56 time =
39 57 Benchmark.realtime do
40 58 # result = RubyProf.profile do
41 59 # report = MemoryProfiler.report do
42 60 # stats = AllocationStats.trace do
43   - Product.reindex
  61 + reindex = Product.reindex(async: true)
  62 + p reindex
44 63 # end
  64 +
  65 + 60.times do |i|
  66 + if reindex.is_a?(Hash)
  67 + docs = Searchkick::Index.new(reindex[:index_name]).total_docs
  68 + else
  69 + docs = Product.searchkick_index.total_docs
  70 + end
  71 + puts "#{i}: #{docs}"
  72 + if docs == total_docs
  73 + break
  74 + end
  75 + p Searchkick.reindex_status(reindex[:index_name]) if reindex.is_a?(Hash)
  76 + sleep(1)
  77 + # Product.searchkick_index.refresh
  78 + end
45 79 end
46 80  
47 81 # p GetProcessMem.new.mb
48 82  
49 83 puts time.round(1)
50   -puts Product.searchkick_index.total_docs
  84 +
51 85  
52 86 if result
53 87 printer = RubyProf::GraphPrinter.new(result)
... ...