From f0b168e8944af41c4161249040f01ece227cfc0c Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 11 Dec 2015 18:10:40 +0100 Subject: [PATCH] Cluster: redis-trib: use variadic MIGRATE. We use the new variadic/pipelined MIGRATE for faster migration. Testing is not easy because to see the time it takes for a slot to be migrated requires a very large data set, but even with all the overhead of migrating multiple slots and to setup them properly, what used to take 4 seconds (1 million keys, 200 slots migrated) is now 1.6 which is a good improvement. However the improvement can be a lot larger if: 1. We use large datasets where a single slot has many keys. 2. By moving more than 10 keys per iteration, making this configurable, which is planned. Close #2710 Close #2711 --- src/redis-trib.rb | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/redis-trib.rb b/src/redis-trib.rb index 7ab4221c..74f3e214 100755 --- a/src/redis-trib.rb +++ b/src/redis-trib.rb @@ -818,22 +818,20 @@ class RedisTrib while true keys = source.r.cluster("getkeysinslot",slot,10) break if keys.length == 0 - keys.each{|key| - begin - source.r.client.call(["migrate",target.info[:host],target.info[:port],key,0,@timeout]) - rescue => e - if o[:fix] && e.to_s =~ /BUSYKEY/ - xputs "*** Target key #{key} exists. Replacing it for FIX." - source.r.client.call(["migrate",target.info[:host],target.info[:port],key,0,@timeout,:replace]) - else - puts "" - xputs "[ERR] #{e}" - exit 1 - end + begin + source.r.client.call(["migrate",target.info[:host],target.info[:port],"",0,@timeout,:keys,*keys]) + rescue => e + if o[:fix] && e.to_s =~ /BUSYKEY/ + xputs "*** Target key #{key} exists. Replacing it for FIX." + source.r.client.call(["migrate",target.info[:host],target.info[:port],"",0,@timeout,:replace,:keys,*keys]) + else + puts "" + xputs "[ERR] #{e}" + exit 1 end - print "." if o[:verbose] - STDOUT.flush - } + end + print "."*keys.length if o[:verbose] + STDOUT.flush end puts