-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.rb
executable file
·90 lines (76 loc) · 2.18 KB
/
benchmark.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# frozen_string_literal: true
# TODO: Modify for GCS
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
gem "activesupport", "6.1.3.1"
gem "redis"
gem "s3_cache_store", path: '../'
gem "aws-sdk-s3"
end
require "active_support"
require "active_support/core_ext/object/blank"
require "minitest/autorun"
require "active_support/cache/s3_cache_store"
require "aws-sdk-s3"
require "securerandom"
REDIS = "redis_bench_#{SecureRandom.alphanumeric(8)}"
MINIO = "minio_bench_#{SecureRandom.alphanumeric(8)}"
BUCKET = "test-bench-bucket"
COUNT = 1000
def setup
system("docker run --rm -p 6379:6379 --detach --name #{REDIS} redis:6.2.1")
system("docker run --rm -p 9000:9000 --detach --name #{MINIO} minio/minio server /data")
client = Aws::S3::Client.new({
access_key_id: 'minioadmin',
secret_access_key: 'minioadmin',
region: 'us-east-1',
endpoint: 'http://127.0.0.1:9000',
force_path_style: true,
})
client.create_bucket(bucket: BUCKET)
end
def bench_redis_cache_store
store = ActiveSupport::Cache::RedisCacheStore.new({
url: 'redis://localhost:6379'
})
redis_start = Time.now
(1..COUNT).each do |e|
store.write(e, e)
store.read(e)
end
redis_duration = Time.now - redis_start
puts "RedisCacheStore duration: #{redis_duration} sec (#{redis_duration / COUNT} s/key rw)"
end
def bench_s3_cache_store
store = ActiveSupport::Cache::S3CacheStore.new({
access_key_id: 'minioadmin',
secret_access_key: 'minioadmin',
region: 'us-east-1',
endpoint: 'http://127.0.0.1:9000',
force_path_style: true,
bucket: BUCKET
})
s3_start = Time.now
(1..COUNT).each do |e|
store.write(e, e)
store.read(e)
end
s3_duration = Time.now - s3_start
puts "S3CacheStore duration: #{s3_duration} sec (#{s3_duration / COUNT} s/key rw)"
end
def teardown
system("docker stop #{REDIS}")
system("docker stop #{MINIO}")
end
begin
setup()
puts "\n\n===== start benchmark =========="
bench_redis_cache_store()
bench_s3_cache_store()
puts "===== end benchmark ============\n\n"
ensure
teardown()
end