Commit 2d0ceffb0977c6e0ac49c989de66788b1ae6edf0
1 parent
a75e2c0f
Exists in
master
and in
19 other branches
Updated benchmark scripts [skip ci]
Showing
5 changed files
with
142 additions
and
100 deletions
Show diff stats
Rakefile
benchmark/Gemfile
@@ -3,7 +3,7 @@ source "https://rubygems.org" | @@ -3,7 +3,7 @@ source "https://rubygems.org" | ||
3 | # Specify your gem's dependencies in searchkick.gemspec | 3 | # Specify your gem's dependencies in searchkick.gemspec |
4 | gemspec path: "../" | 4 | gemspec path: "../" |
5 | 5 | ||
6 | -# gem "sqlite3" | 6 | +gem "sqlite3" |
7 | gem "pg" | 7 | gem "pg" |
8 | gem "activerecord", "~> 5.2.0.rc1" | 8 | gem "activerecord", "~> 5.2.0.rc1" |
9 | gem "activerecord-import" | 9 | gem "activerecord-import" |
benchmark/benchmark.rb
@@ -1,98 +0,0 @@ | @@ -1,98 +0,0 @@ | ||
1 | -require "bundler/setup" | ||
2 | -Bundler.require(:default) | ||
3 | -require "active_record" | ||
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.round | ||
10 | -end | ||
11 | - | ||
12 | -ActiveJob::Base.queue_adapter = :sidekiq | ||
13 | - | ||
14 | -Searchkick.redis = Redis.new | ||
15 | - | ||
16 | -ActiveRecord::Base.default_timezone = :utc | ||
17 | -ActiveRecord::Base.time_zone_aware_attributes = true | ||
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) | ||
21 | - | ||
22 | -ActiveJob::Base.logger = nil | ||
23 | - | ||
24 | -class Product < ActiveRecord::Base | ||
25 | - searchkick batch_size: 1000 | ||
26 | - | ||
27 | - def search_data | ||
28 | - { | ||
29 | - name: name, | ||
30 | - color: color, | ||
31 | - store_id: store_id | ||
32 | - } | ||
33 | - end | ||
34 | -end | ||
35 | - | ||
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)] } | ||
45 | - | ||
46 | -# puts "Imported" | ||
47 | - | ||
48 | -result = nil | ||
49 | -report = nil | ||
50 | -stats = nil | ||
51 | - | ||
52 | -Product.searchkick_index.delete rescue nil | ||
53 | - | ||
54 | -GC.start | ||
55 | -GC.disable | ||
56 | -start_mem = GetProcessMem.new.mb | ||
57 | - | ||
58 | -time = | ||
59 | - Benchmark.realtime do | ||
60 | - # result = RubyProf.profile do | ||
61 | - # report = MemoryProfiler.report do | ||
62 | - # stats = AllocationStats.trace do | ||
63 | - reindex = Product.reindex #(async: true) | ||
64 | - # p reindex | ||
65 | - # end | ||
66 | - | ||
67 | - # 60.times do |i| | ||
68 | - # if reindex.is_a?(Hash) | ||
69 | - # docs = Searchkick::Index.new(reindex[:index_name]).total_docs | ||
70 | - # else | ||
71 | - # docs = Product.searchkick_index.total_docs | ||
72 | - # end | ||
73 | - # puts "#{i}: #{docs}" | ||
74 | - # if docs == total_docs | ||
75 | - # break | ||
76 | - # end | ||
77 | - # p Searchkick.reindex_status(reindex[:index_name]) if reindex.is_a?(Hash) | ||
78 | - # sleep(1) | ||
79 | - # # Product.searchkick_index.refresh | ||
80 | - # end | ||
81 | - end | ||
82 | - | ||
83 | -puts | ||
84 | -puts "Memory: #{(GetProcessMem.new.mb - start_mem).round(1)}mb" | ||
85 | -puts "Time: #{time.round(1)}s" | ||
86 | - | ||
87 | -if result | ||
88 | - printer = RubyProf::GraphPrinter.new(result) | ||
89 | - printer.print(STDOUT, min_percent: 5) | ||
90 | -end | ||
91 | - | ||
92 | -if report | ||
93 | - puts report.pretty_print | ||
94 | -end | ||
95 | - | ||
96 | -if stats | ||
97 | - puts result.allocations(alias_paths: true).group_by(:sourcefile, :class).to_text | ||
98 | -end |
@@ -0,0 +1,98 @@ | @@ -0,0 +1,98 @@ | ||
1 | +require "bundler/setup" | ||
2 | +Bundler.require(:default) | ||
3 | +require "active_record" | ||
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.round | ||
10 | +end | ||
11 | + | ||
12 | +ActiveJob::Base.queue_adapter = :sidekiq | ||
13 | + | ||
14 | +Searchkick.redis = Redis.new | ||
15 | + | ||
16 | +ActiveRecord::Base.default_timezone = :utc | ||
17 | +ActiveRecord::Base.time_zone_aware_attributes = true | ||
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) | ||
21 | + | ||
22 | +ActiveJob::Base.logger = nil | ||
23 | + | ||
24 | +class Product < ActiveRecord::Base | ||
25 | + searchkick batch_size: 1000 | ||
26 | + | ||
27 | + def search_data | ||
28 | + { | ||
29 | + name: name, | ||
30 | + color: color, | ||
31 | + store_id: store_id | ||
32 | + } | ||
33 | + end | ||
34 | +end | ||
35 | + | ||
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)] } | ||
45 | + | ||
46 | +# puts "Imported" | ||
47 | + | ||
48 | +result = nil | ||
49 | +report = nil | ||
50 | +stats = nil | ||
51 | + | ||
52 | +Product.searchkick_index.delete rescue nil | ||
53 | + | ||
54 | +GC.start | ||
55 | +GC.disable | ||
56 | +start_mem = GetProcessMem.new.mb | ||
57 | + | ||
58 | +time = | ||
59 | + Benchmark.realtime do | ||
60 | + # result = RubyProf.profile do | ||
61 | + # report = MemoryProfiler.report do | ||
62 | + # stats = AllocationStats.trace do | ||
63 | + reindex = Product.reindex #(async: true) | ||
64 | + # p reindex | ||
65 | + # end | ||
66 | + | ||
67 | + # 60.times do |i| | ||
68 | + # if reindex.is_a?(Hash) | ||
69 | + # docs = Searchkick::Index.new(reindex[:index_name]).total_docs | ||
70 | + # else | ||
71 | + # docs = Product.searchkick_index.total_docs | ||
72 | + # end | ||
73 | + # puts "#{i}: #{docs}" | ||
74 | + # if docs == total_docs | ||
75 | + # break | ||
76 | + # end | ||
77 | + # p Searchkick.reindex_status(reindex[:index_name]) if reindex.is_a?(Hash) | ||
78 | + # sleep(1) | ||
79 | + # # Product.searchkick_index.refresh | ||
80 | + # end | ||
81 | + end | ||
82 | + | ||
83 | +puts | ||
84 | +puts "Memory: #{(GetProcessMem.new.mb - start_mem).round(1)}mb" | ||
85 | +puts "Time: #{time.round(1)}s" | ||
86 | + | ||
87 | +if result | ||
88 | + printer = RubyProf::GraphPrinter.new(result) | ||
89 | + printer.print(STDOUT, min_percent: 5) | ||
90 | +end | ||
91 | + | ||
92 | +if report | ||
93 | + puts report.pretty_print | ||
94 | +end | ||
95 | + | ||
96 | +if stats | ||
97 | + puts result.allocations(alias_paths: true).group_by(:sourcefile, :class).to_text | ||
98 | +end |
@@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
1 | +require "bundler/setup" | ||
2 | +Bundler.require(:default) | ||
3 | +require "active_record" | ||
4 | +require "benchmark" | ||
5 | + | ||
6 | +ActiveRecord::Base.default_timezone = :utc | ||
7 | +ActiveRecord::Base.time_zone_aware_attributes = true | ||
8 | +ActiveRecord::Base.establish_connection adapter: "sqlite3", database: "/tmp/searchkick" | ||
9 | + | ||
10 | +class Product < ActiveRecord::Base | ||
11 | + searchkick batch_size: 1000 | ||
12 | + | ||
13 | + def search_data | ||
14 | + { | ||
15 | + name: name, | ||
16 | + color: color, | ||
17 | + store_id: store_id | ||
18 | + } | ||
19 | + end | ||
20 | +end | ||
21 | + | ||
22 | +# total_docs = 1000000 | ||
23 | + | ||
24 | +# ActiveRecord::Migration.create_table :products, force: :cascade do |t| | ||
25 | +# t.string :name | ||
26 | +# t.string :color | ||
27 | +# t.integer :store_id | ||
28 | +# end | ||
29 | + | ||
30 | +# Product.import ["name", "color", "store_id"], total_docs.times.map { |i| ["Product #{i}", ["red", "blue"].sample, rand(10)] } | ||
31 | + | ||
32 | +# puts "Imported" | ||
33 | + | ||
34 | +# Product.reindex | ||
35 | + | ||
36 | +time = | ||
37 | + Benchmark.realtime do | ||
38 | + Product.search("product", fields: [:name], where: {color: "red", store_id: 5}, load: false) | ||
39 | + end | ||
40 | + | ||
41 | +puts | ||
42 | +puts "Time: #{time.round(1)}s" |