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);
}
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);
}
}
}
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);
}
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;
}
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;
}
Aggregations