Search in sources :

Example 1 with KetamaNodeLocator

use of net.spy.memcached.KetamaNodeLocator in project druid by druid-io.

the class CacheDistributionTest method testDistribution.

// run to get a sense of cache key distribution for different ketama reps / hash functions
@Test
public void testDistribution() throws Exception {
    KetamaNodeLocator locator = new KetamaNodeLocator(ImmutableList.of(dummyNode("druid-cache.0001", 11211), dummyNode("druid-cache.0002", 11211), dummyNode("druid-cache.0003", 11211), dummyNode("druid-cache.0004", 11211), dummyNode("druid-cache.0005", 11211)), hash, new DefaultKetamaNodeLocatorConfiguration() {

        @Override
        public int getNodeRepetitions() {
            return reps;
        }
    });
    Map<MemcachedNode, AtomicLong> counter = Maps.newHashMap();
    long t = 0;
    for (int i = 0; i < KEY_COUNT; ++i) {
        final String k = DigestUtils.sha1Hex("abc" + i) + ":" + DigestUtils.sha1Hex("xyz" + i);
        long t0 = System.nanoTime();
        MemcachedNode node = locator.getPrimary(k);
        t += System.nanoTime() - t0;
        if (counter.containsKey(node)) {
            counter.get(node).incrementAndGet();
        } else {
            counter.put(node, new AtomicLong(1));
        }
    }
    long min = Long.MAX_VALUE;
    long max = 0;
    System.out.printf("%25s\t%5d\t", hash, reps);
    for (AtomicLong count : counter.values()) {
        System.out.printf("%10d\t", count.get());
        min = Math.min(min, count.get());
        max = Math.max(max, count.get());
    }
    System.out.printf("%7.2f\t%5.0f\n", (double) min / (double) max, (double) t / KEY_COUNT);
}
Also used : DefaultKetamaNodeLocatorConfiguration(net.spy.memcached.util.DefaultKetamaNodeLocatorConfiguration) AtomicLong(java.util.concurrent.atomic.AtomicLong) KetamaNodeLocator(net.spy.memcached.KetamaNodeLocator) MemcachedNode(net.spy.memcached.MemcachedNode) Test(org.junit.Test)

Example 2 with KetamaNodeLocator

use of net.spy.memcached.KetamaNodeLocator in project druid by druid-io.

the class CacheDistributionTest method testDistribution.

// Run to get a sense of cache key distribution for different ketama reps / hash functions
// This test is disabled by default because it's a qualitative test not an unit test and thus it have a meaning only
// when being run and checked by humans.
@Ignore
@Test
public void testDistribution() {
    KetamaNodeLocator locator = new KetamaNodeLocator(ImmutableList.of(dummyNode("druid-cache.0001", 11211), dummyNode("druid-cache.0002", 11211), dummyNode("druid-cache.0003", 11211), dummyNode("druid-cache.0004", 11211), dummyNode("druid-cache.0005", 11211)), hash, new DefaultKetamaNodeLocatorConfiguration() {

        @Override
        public int getNodeRepetitions() {
            return reps;
        }
    });
    Map<MemcachedNode, AtomicLong> counter = new HashMap<>();
    long t = 0;
    for (int i = 0; i < KEY_COUNT; ++i) {
        final String k = DigestUtils.sha1Hex("abc" + i) + ":" + DigestUtils.sha1Hex("xyz" + i);
        long t0 = System.nanoTime();
        MemcachedNode node = locator.getPrimary(k);
        t += System.nanoTime() - t0;
        if (counter.containsKey(node)) {
            counter.get(node).incrementAndGet();
        } else {
            counter.put(node, new AtomicLong(1));
        }
    }
    long min = Long.MAX_VALUE;
    long max = 0;
    System.out.printf(Locale.ENGLISH, "%25s\t%5d\t", hash, reps);
    for (AtomicLong count : counter.values()) {
        System.out.printf(Locale.ENGLISH, "%10d\t", count.get());
        min = Math.min(min, count.get());
        max = Math.max(max, count.get());
    }
    System.out.printf(Locale.ENGLISH, "%7.2f\t%5.0f%n", (double) min / (double) max, (double) t / KEY_COUNT);
}
Also used : DefaultKetamaNodeLocatorConfiguration(net.spy.memcached.util.DefaultKetamaNodeLocatorConfiguration) AtomicLong(java.util.concurrent.atomic.AtomicLong) KetamaNodeLocator(net.spy.memcached.KetamaNodeLocator) HashMap(java.util.HashMap) MemcachedNode(net.spy.memcached.MemcachedNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

AtomicLong (java.util.concurrent.atomic.AtomicLong)2 KetamaNodeLocator (net.spy.memcached.KetamaNodeLocator)2 MemcachedNode (net.spy.memcached.MemcachedNode)2 DefaultKetamaNodeLocatorConfiguration (net.spy.memcached.util.DefaultKetamaNodeLocatorConfiguration)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 Ignore (org.junit.Ignore)1