44require 'redis_cluster_client'
55require 'testing_constants'
66
7- module BenchPipeline
7+ module IpsPipeline
88 module_function
99
1010 ATTEMPTS = 100
1111
1212 def run
1313 on_demand = make_client ( :on_demand )
1414 pooled = make_client ( :pooled )
15- prepare ( on_demand , pooled )
16- bench ( on_demand , pooled )
15+ envoy = make_client_for_envoy
16+ cluster_proxy = make_client_for_cluster_proxy
17+ prepare ( on_demand , pooled , envoy , cluster_proxy )
18+ print_letter ( 'pipelined' )
19+ bench (
20+ ondemand : on_demand ,
21+ pooled : pooled ,
22+ envoy : envoy ,
23+ cproxy : cluster_proxy
24+ )
1725 end
1826
1927 def make_client ( model )
@@ -25,32 +33,53 @@ def make_client(model)
2533 ) . new_client
2634 end
2735
28- def prepare ( on_demand , pooled )
29- on_demand . pipelined do |pi |
30- ATTEMPTS . times { |i | pi . call ( 'SET' , "key#{ i } " , "val#{ i } " ) }
31- end
36+ def make_client_for_envoy
37+ ::RedisClient . config (
38+ **TEST_GENERIC_OPTIONS . merge ( BENCH_ENVOY_OPTIONS )
39+ ) . new_client
40+ end
41+
42+ def make_client_for_cluster_proxy
43+ ::RedisClient . config (
44+ **TEST_GENERIC_OPTIONS . merge ( BENCH_REDIS_CLUSTER_PROXY_OPTIONS )
45+ ) . new_client
46+ end
3247
33- pooled . pipelined do |pi |
34- ATTEMPTS . times { |i | pi . call ( 'SET' , "key#{ i } " , "val#{ i } " ) }
48+ def print_letter ( title )
49+ print "################################################################################\n "
50+ print "# #{ title } \n "
51+ print "################################################################################\n "
52+ print "\n "
53+ end
54+
55+ def prepare ( *clients )
56+ clients . each do |client |
57+ client . pipelined do |pi |
58+ ATTEMPTS . times do |i |
59+ pi . call ( 'SET' , "key#{ i } " , "val#{ i } " )
60+ end
61+ end
3562 end
3663 end
3764
38- def bench ( on_demand , pooled )
65+ def bench ( ** kwargs )
3966 Benchmark . ips do |x |
4067 x . time = 5
4168 x . warmup = 1
4269
43- x . report ( 'on_demand' ) do
44- on_demand . pipelined { |pi | ATTEMPTS . times { |i | pi . call ( 'GET' , "key#{ i } " ) } }
45- end
46-
47- x . report ( 'pooled' ) do
48- pooled . pipelined { |pi | ATTEMPTS . times { |i | pi . call ( 'GET' , "key#{ i } " ) } }
70+ kwargs . each do |key , client |
71+ x . report ( "pipelined: #{ key } " ) do
72+ client . pipelined do |pi |
73+ ATTEMPTS . times do |i |
74+ pi . call ( 'GET' , "key#{ i } " )
75+ end
76+ end
77+ end
4978 end
5079
5180 x . compare!
5281 end
5382 end
5483end
5584
56- BenchPipeline . run
85+ IpsPipeline . run
0 commit comments