Permalink
Browse files

Updated benchmark script [skip ci]

  • Loading branch information...
ankane committed Jan 12, 2017
1 parent 929c4ce commit d0716a0fb033e2be1db7ab1f619c98ea605d9d38
Showing with 49 additions and 11 deletions.
  1. +5 −1 benchmark/Gemfile
  2. +44 −10 benchmark/benchmark.rb
View
@@ -3,9 +3,13 @@ source "https://rubygems.org"
# Specify your gem's dependencies in searchkick.gemspec
gemspec path: "../"
gem "sqlite3"
# gem "sqlite3"
gem "pg"
gem "activerecord", "~> 5.0.0"
gem "activerecord-import"
gem "activejob"
gem "redis"
gem "sidekiq"
# performance
gem "typhoeus"
View
@@ -2,19 +2,27 @@
Bundler.require(:default)
require "active_record"
require "benchmark"
require "active_support/notifications"
ActiveSupport::Notifications.subscribe "request.searchkick" do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
p event.duration
end
ActiveJob::Base.queue_adapter = :sidekiq
Searchkick.redis = Redis.new
ActiveRecord::Base.default_timezone = :utc
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
# ActiveRecord::Base.establish_connection adapter: "sqlite3", database: "/tmp/searchkick"
ActiveRecord::Base.establish_connection "postgresql://localhost/searchkick_demo_development"
# ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Migration.create_table :products do |t|
t.string :name
t.string :color
t.integer :store_id
end
ActiveJob::Base.logger = nil
class Product < ActiveRecord::Base
searchkick batch_size: 100
searchkick batch_size: 1000
def search_data
{
@@ -25,7 +33,15 @@ def search_data
end
end
Product.import ["name", "color", "store_id"], 20000.times.map { |i| ["Product #{i}", ["red", "blue"].sample, rand(10)] }
total_docs = 100000
# ActiveRecord::Migration.create_table :products, force: :cascade do |t|
# t.string :name
# t.string :color
# t.integer :store_id
# end
# Product.import ["name", "color", "store_id"], total_docs.times.map { |i| ["Product #{i}", ["red", "blue"].sample, rand(10)] }
puts "Imported"
@@ -35,19 +51,37 @@ def search_data
# p GetProcessMem.new.mb
Product.searchkick_index.delete rescue nil
time =
Benchmark.realtime do
# result = RubyProf.profile do
# report = MemoryProfiler.report do
# stats = AllocationStats.trace do
Product.reindex
reindex = Product.reindex(async: true)
p reindex
# end
60.times do |i|
if reindex.is_a?(Hash)
docs = Searchkick::Index.new(reindex[:index_name]).total_docs
else
docs = Product.searchkick_index.total_docs
end
puts "#{i}: #{docs}"
if docs == total_docs
break
end
p Searchkick.reindex_status(reindex[:index_name]) if reindex.is_a?(Hash)
sleep(1)
# Product.searchkick_index.refresh
end
end
# p GetProcessMem.new.mb
puts time.round(1)
puts Product.searchkick_index.total_docs
if result
printer = RubyProf::GraphPrinter.new(result)

0 comments on commit d0716a0

Please sign in to comment.