Search in sources :

Example 1 with MemcachedNode

use of net.spy.memcached.MemcachedNode 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 MemcachedNode

use of net.spy.memcached.MemcachedNode in project pinpoint by naver.

the class FutureGetInterceptor method doInAfterTrace.

@Override
protected void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
    recorder.recordApi(methodDescriptor);
    recorder.recordDestinationId("MEMCACHED");
    recorder.recordServiceType(ArcusConstants.MEMCACHED_FUTURE_GET);
    if (!(target instanceof OperationAccessor)) {
        logger.info("operation not found");
        return;
    }
    // find the target node
    final Operation op = ((OperationAccessor) target)._$PINPOINT$_getOperation();
    if (op == null) {
        logger.info("operation is null");
        return;
    }
    recorder.recordException(op.getException());
    final MemcachedNode handlingNode = op.getHandlingNode();
    if (handlingNode != null) {
        final String endPoint = getEndPoint(handlingNode);
        if (endPoint != null) {
            recorder.recordEndPoint(endPoint);
        }
        recorder.recordException(op.getException());
    } else {
        logger.info("no handling node");
    }
    if (op instanceof ServiceCodeAccessor) {
        // determine the service type
        String serviceCode = ((ServiceCodeAccessor) op)._$PINPOINT$_getServiceCode();
        if (serviceCode != null) {
            recorder.recordDestinationId(serviceCode);
            recorder.recordServiceType(ArcusConstants.ARCUS_FUTURE_GET);
        }
    }
}
Also used : OperationAccessor(com.navercorp.pinpoint.plugin.arcus.OperationAccessor) MemcachedNode(net.spy.memcached.MemcachedNode) Operation(net.spy.memcached.ops.Operation) ServiceCodeAccessor(com.navercorp.pinpoint.plugin.arcus.ServiceCodeAccessor)

Example 3 with MemcachedNode

use of net.spy.memcached.MemcachedNode 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)

Example 4 with MemcachedNode

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

the class CacheDistributionTest method dummyNode.

private static MemcachedNode dummyNode(String host, int port) {
    SocketAddress address = InetSocketAddress.createUnresolved(host, port);
    MemcachedNode node = EasyMock.createNiceMock(MemcachedNode.class);
    EasyMock.expect(node.getSocketAddress()).andReturn(address).anyTimes();
    EasyMock.replay(node);
    return node;
}
Also used : MemcachedNode(net.spy.memcached.MemcachedNode) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 5 with MemcachedNode

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

the class CacheDistributionTest method dummyNode.

private static MemcachedNode dummyNode(String host, int port) {
    SocketAddress address = InetSocketAddress.createUnresolved(host, port);
    MemcachedNode node = EasyMock.createNiceMock(MemcachedNode.class);
    EasyMock.expect(node.getSocketAddress()).andReturn(address).anyTimes();
    EasyMock.replay(node);
    return node;
}
Also used : MemcachedNode(net.spy.memcached.MemcachedNode) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

MemcachedNode (net.spy.memcached.MemcachedNode)6 OperationAccessor (com.navercorp.pinpoint.plugin.arcus.OperationAccessor)2 ServiceCodeAccessor (com.navercorp.pinpoint.plugin.arcus.ServiceCodeAccessor)2 InetSocketAddress (java.net.InetSocketAddress)2 SocketAddress (java.net.SocketAddress)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 KetamaNodeLocator (net.spy.memcached.KetamaNodeLocator)2 Operation (net.spy.memcached.ops.Operation)2 DefaultKetamaNodeLocatorConfiguration (net.spy.memcached.util.DefaultKetamaNodeLocatorConfiguration)2 Test (org.junit.Test)2 AsyncContextAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor)1 AsyncContext (com.navercorp.pinpoint.bootstrap.context.AsyncContext)1 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)1 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)1 HashMap (java.util.HashMap)1 Future (java.util.concurrent.Future)1 Ignore (org.junit.Ignore)1