diff options
Diffstat (limited to 'examples/redis-unstable/utils/srandmember')
| -rw-r--r-- | examples/redis-unstable/utils/srandmember/README.md | 14 | ||||
| -rw-r--r-- | examples/redis-unstable/utils/srandmember/showdist.rb | 33 | ||||
| -rw-r--r-- | examples/redis-unstable/utils/srandmember/showfreq.rb | 23 |
3 files changed, 70 insertions, 0 deletions
diff --git a/examples/redis-unstable/utils/srandmember/README.md b/examples/redis-unstable/utils/srandmember/README.md new file mode 100644 index 0000000..d3da1e8 --- /dev/null +++ b/examples/redis-unstable/utils/srandmember/README.md | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | The utilities in this directory plot the distribution of SRANDMEMBER to | ||
| 2 | evaluate how fair it is. | ||
| 3 | |||
| 4 | See http://theshfl.com/redis_sets for more information on the topic that lead | ||
| 5 | to such investigation fix. | ||
| 6 | |||
| 7 | showdist.rb -- shows the distribution of the frequency elements are returned. | ||
| 8 | The x axis is the number of times elements were returned, and | ||
| 9 | the y axis is how many elements were returned with such | ||
| 10 | frequency. | ||
| 11 | |||
| 12 | showfreq.rb -- shows the frequency each element was returned. | ||
| 13 | The x axis is the element number. | ||
| 14 | The y axis is the times it was returned. | ||
diff --git a/examples/redis-unstable/utils/srandmember/showdist.rb b/examples/redis-unstable/utils/srandmember/showdist.rb new file mode 100644 index 0000000..2435857 --- /dev/null +++ b/examples/redis-unstable/utils/srandmember/showdist.rb | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | require 'redis' | ||
| 2 | |||
| 3 | r = Redis.new | ||
| 4 | r.select(9) | ||
| 5 | r.del("myset"); | ||
| 6 | r.sadd("myset",(0..999).to_a) | ||
| 7 | freq = {} | ||
| 8 | 100.times { | ||
| 9 | res = r.pipelined { | ||
| 10 | 1000.times { | ||
| 11 | r.srandmember("myset") | ||
| 12 | } | ||
| 13 | } | ||
| 14 | res.each{|ele| | ||
| 15 | freq[ele] = 0 if freq[ele] == nil | ||
| 16 | freq[ele] += 1 | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | # Convert into frequency distribution | ||
| 21 | dist = {} | ||
| 22 | freq.each{|item,count| | ||
| 23 | dist[count] = 0 if dist[count] == nil | ||
| 24 | dist[count] += 1 | ||
| 25 | } | ||
| 26 | |||
| 27 | min = dist.keys.min | ||
| 28 | max = dist.keys.max | ||
| 29 | (min..max).each{|x| | ||
| 30 | count = dist[x] | ||
| 31 | count = 0 if count == nil | ||
| 32 | puts "#{x} -> #{"*"*count}" | ||
| 33 | } | ||
diff --git a/examples/redis-unstable/utils/srandmember/showfreq.rb b/examples/redis-unstable/utils/srandmember/showfreq.rb new file mode 100644 index 0000000..625519c --- /dev/null +++ b/examples/redis-unstable/utils/srandmember/showfreq.rb | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | require 'redis' | ||
| 2 | |||
| 3 | r = Redis.new | ||
| 4 | r.select(9) | ||
| 5 | r.del("myset"); | ||
| 6 | r.sadd("myset",(0..999).to_a) | ||
| 7 | freq = {} | ||
| 8 | 500.times { | ||
| 9 | res = r.pipelined { | ||
| 10 | 1000.times { | ||
| 11 | r.srandmember("myset") | ||
| 12 | } | ||
| 13 | } | ||
| 14 | res.each{|ele| | ||
| 15 | freq[ele] = 0 if freq[ele] == nil | ||
| 16 | freq[ele] += 1 | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | # Print the frequency each element was yield to process it with gnuplot | ||
| 21 | freq.each{|item,count| | ||
| 22 | puts "#{item} #{count}" | ||
| 23 | } | ||
