ElastiCache(Redis) に redis-rb からアクセスし、接続モード(cluster or host)によるフェイルオーバー時のリカバリ時間を計測してみた。
検証結果
$ CONN_OPT=host bash exec_redis-rb_sample.sh > redis-rb_sample_cluster_`date '+%Y-%m-%d-%H%M%S'`.log & $ CONN_OPT=cluster bash exec_redis-rb_sample.sh > redis-rb_sample_host_`date '+%Y-%m-%d-%H%M%S'`.log &
検証用スクリプト
- exec_redis-rb_sample.sh
#!/usr/bin/env bash export LC_ALL=C CONN_OPT=${CONN_OPT:-host} REDIS_ENDPOINT=${REDIS_ENDPOINT:-redis-cluster-no-auth2.******.clustercfg.apne1.cache.amazonaws.com} REDIS_PORT=${REDIS_PORT:-6379} while : do CURRENT_DATE=`date '+%Y-%m-%d-%H:%M:%S'` echo ${CURRENT_DATE} 2>&1 ruby redis-rb_sample.rb ${CONN_OPT} ${REDIS_ENDPOINT} ${REDIS_PORT} 2>&1 done
- redis-rb_sample.rb
#!/usr/bin/env ruby require "redis" require "date" STDOUT.sync = true conn_opt = ARGV[0] redis_endpoint = ARGV[1] redis_port = ARGV[2] if conn_opt == 'cluster' and ARGV.size() == 3 redis = Redis.new(cluster: ['redis://' + redis_endpoint + ':' + redis_port]) puts 'connect to endpoint with cluster option "cluster:"' elsif conn_opt == 'host' and ARGV.size() == 3 redis = Redis.new(url: 'redis://' + redis_endpoint + ':' + redis_port) puts 'connect to endpoint with non-cluster option "url:"' else puts 'Usage: ruby redis-rb.rb <host|cluster> <endpoint url> <port>' puts 'Exapmle: ruby redis-rb.rb cluster redis-cluster-no-auth.******.clustercfg.apne1.cache.amazonaws.com 6379' exit! end num = 0 loop do num += 1 redis.set('key_' + num.to_s, 'value_' + num.to_s) time = DateTime.now if num % 1000 == 0 puts time.to_s + " " + num.to_s end end