/usr/share/doc/libkyototycoon2/example/ktmemcmqex.rb is in kyototycoon-doc 0.9.56-1build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | require 'memcache'
host = "127.0.0.1:11211"
options = {
:timeout => 3600,
}
thnum = 4
rnum = 100
gcache = MemCache.new([host], options)
gcache.flush_all
producers = Array::new
for thid in 0...thnum
th = Thread::new(thid) { |id|
cache = MemCache.new([host], options)
mid = rnum / 4
for i in 0...rnum
name = (i % 10).to_s
value = i.to_s
printf("set: %s: %s\n", name, value)
cache.set(name, value, 0, { :raw => true })
wt = rand() * 0.1
sleep(wt) if i >= mid && wt >= 0.01
end
}
producers.push(th)
end
workers = Array::new
for thid in 0...thnum
th = Thread::new(thid) { |id|
cache = MemCache.new([host], options)
for i in 0...rnum
name = (i % 10).to_s
value = cache.get(name, { :raw => true })
printf("get: %s: %s\n", name, value ? value : "(miss)")
cache.delete(name)
end
}
workers.push(th)
end
workers.each { |th|
th.join
}
producers.each { |th|
th.join
}
GC.start
printf("count: %s\n", gcache.stats[host]["curr_items"])
|