use of java.util.LongSummaryStatistics in project lucene-solr by apache.
the class TestDocValuesStatsCollector method testDocsWithMultipleLongValues.
public void testDocsWithMultipleLongValues() throws IOException {
try (Directory dir = newDirectory();
IndexWriter indexWriter = new IndexWriter(dir, newIndexWriterConfig())) {
String field = "numeric";
int numDocs = TestUtil.nextInt(random(), 1, 100);
long[][] docValues = new long[numDocs][];
long nextVal = 1;
for (int i = 0; i < numDocs; i++) {
Document doc = new Document();
if (random().nextBoolean()) {
// not all documents have a value
int numValues = TestUtil.nextInt(random(), 1, 5);
docValues[i] = new long[numValues];
for (int j = 0; j < numValues; j++) {
doc.add(new SortedNumericDocValuesField(field, nextVal));
docValues[i][j] = nextVal;
++nextVal;
}
doc.add(new StringField("id", "doc" + i, Store.NO));
}
indexWriter.addDocument(doc);
}
// 20% of cases delete some docs
if (random().nextDouble() < 0.2) {
for (int i = 0; i < numDocs; i++) {
if (random().nextBoolean()) {
indexWriter.deleteDocuments(new Term("id", "doc" + i));
docValues[i] = null;
}
}
}
try (DirectoryReader reader = DirectoryReader.open(indexWriter)) {
IndexSearcher searcher = new IndexSearcher(reader);
SortedLongDocValuesStats stats = new SortedLongDocValuesStats(field);
searcher.search(new MatchAllDocsQuery(), new DocValuesStatsCollector(stats));
assertEquals(nonNull(docValues).count(), stats.count());
int numDocsWithoutField = (int) isNull(docValues).count();
assertEquals(computeExpMissing(numDocsWithoutField, numDocs, reader), stats.missing());
if (stats.count() > 0) {
LongSummaryStatistics sumStats = filterAndFlatValues(docValues, (v) -> v != null).summaryStatistics();
assertEquals(sumStats.getMax(), stats.max().longValue());
assertEquals(sumStats.getMin(), stats.min().longValue());
assertEquals(sumStats.getAverage(), stats.mean(), 0.00001);
assertEquals(sumStats.getSum(), stats.sum().longValue());
assertEquals(sumStats.getCount(), stats.valuesCount());
double variance = computeVariance(filterAndFlatValues(docValues, (v) -> v != null), stats.mean, stats.count());
assertEquals(variance, stats.variance(), 0.00001);
assertEquals(Math.sqrt(variance), stats.stdev(), 0.00001);
}
}
}
}
use of java.util.LongSummaryStatistics in project nifi by apache.
the class ThreadPoolRequestReplicator method logTimingInfo.
private void logTimingInfo(final AsyncClusterResponse response) {
// Calculate min, max, mean for the requests
final LongSummaryStatistics stats = response.getNodesInvolved().stream().map(p -> response.getNodeResponse(p).getRequestDuration(TimeUnit.MILLISECONDS)).collect(Collectors.summarizingLong(Long::longValue));
final StringBuilder sb = new StringBuilder();
sb.append("Node Responses for ").append(response.getMethod()).append(" ").append(response.getURIPath()).append(" (Request ID ").append(response.getRequestIdentifier()).append("):\n");
for (final NodeIdentifier node : response.getNodesInvolved()) {
sb.append(node).append(": ").append(response.getNodeResponse(node).getRequestDuration(TimeUnit.MILLISECONDS)).append(" millis\n");
}
logger.debug("For {} {} (Request ID {}), minimum response time = {}, max = {}, average = {} ms", response.getMethod(), response.getURIPath(), response.getRequestIdentifier(), stats.getMin(), stats.getMax(), stats.getAverage());
logger.debug(sb.toString());
}
use of java.util.LongSummaryStatistics in project hono by eclipse.
the class SendReceiveIT method testTelemetryUpload.
/**
* Verifies that telemetry messages uploaded to the Hono server are all received
* by a downstream consumer.
*
* @throws Exception if the test fails.
*/
@Test
public void testTelemetryUpload() throws Exception {
givenAReceiver();
givenASender();
getRegistrationClient().register(DEVICE_ID, Duration.ofMillis(DEFAULT_TEST_TIMEOUT));
final CountDownLatch latch = new CountDownLatch(IntegrationTestSupport.MSG_COUNT);
final LongSummaryStatistics stats = new LongSummaryStatistics();
// get registration assertion
final String registrationAssertion = getRegistrationAssertion(DEVICE_ID);
// prepare consumer
final MessageConsumer messageConsumer = receiver.getTelemetryConsumer();
messageConsumer.setMessageListener(message -> {
latch.countDown();
gatherStatistics(stats, message);
if (LOG.isTraceEnabled()) {
final long messagesReceived = IntegrationTestSupport.MSG_COUNT - latch.getCount();
if (messagesReceived % 100 == 0) {
LOG.trace("Received {} messages.", messagesReceived);
}
}
});
final MessageProducer messageProducer = sender.getTelemetryProducer();
IntStream.range(0, IntegrationTestSupport.MSG_COUNT).forEach(i -> {
try {
final Message message = sender.newMessage("msg " + i, DEVICE_ID, registrationAssertion);
messageProducer.send(message, DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
if (LOG.isTraceEnabled() && i > 0 && i % 100 == 0) {
LOG.trace("Sent message {}", i);
}
} catch (final JMSException e) {
LOG.error("Error occurred while sending message: {}", e.getMessage(), e);
}
});
long timeToWait = Math.max(DEFAULT_TEST_TIMEOUT, Math.round(IntegrationTestSupport.MSG_COUNT * 1.2));
// wait for messages to arrive
assertTrue("did not receive all " + IntegrationTestSupport.MSG_COUNT + " messages", latch.await(timeToWait, TimeUnit.MILLISECONDS));
LOG.info("Delivery statistics: {}", stats);
}
use of java.util.LongSummaryStatistics in project xian by happyyangyuan.
the class DistributedLockTest method QPS.
@Test
public void QPS() {
final CountDownLatch startCountDownLatch = new CountDownLatch(1);
final int number = 1000;
final CountDownLatch finishCountDownLatch = new CountDownLatch(number);
final List<Long> consumeTimes = new CopyOnWriteArrayList<>();
for (int i = 0; i < number; i++) {
int _i = i;
ThreadPoolManager.execute(() -> {
try {
startCountDownLatch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
long startTime = System.nanoTime();
// Redis Lock
DistributedLockSynchronizer.call("QPS_" + _i, 3, () -> {
return null;
}, 3);
// ZK Lock
// try
// {
// Synchronizer.call("QPS_" + _i, () -> {
// return null;
// }, 3L);
// }
// catch (Exception e)
// {
// LOG.error(e);
// }
finishCountDownLatch.countDown();
long endTime = System.nanoTime();
consumeTimes.add(endTime - startTime);
});
}
try {
startCountDownLatch.countDown();
finishCountDownLatch.await();
long totalConsumeTime = 0;
for (long consumeTime : consumeTimes) totalConsumeTime += consumeTime;
long avgConsumeTime = totalConsumeTime / number;
LongSummaryStatistics intSummaryStatistics = consumeTimes.stream().collect(Collectors.summarizingLong(value -> value));
LOG.info(String.format("QPS, 加锁解锁, 任务数量: %s, 累计耗时: %s, %s, 平均耗时:%s, %s, %s", number, totalConsumeTime, totalConsumeTime / 1000000, avgConsumeTime, avgConsumeTime / 1000000, intSummaryStatistics));
} catch (Exception e) {
LOG.error(e);
}
UnitResponse unitResponseObject = Xian.call(CacheService.CACHE_SERVICE, "cacheKeys", new JSONObject() {
{
put("pattern", "LOCK_QPS_*");
}
});
if (unitResponseObject.succeeded() && unitResponseObject.getData() != null) {
Set<String> keys = unitResponseObject.getData();
LOG.info(String.format("分布锁剩余数量: %s", keys.size()));
}
Xian.call("diyMonitor", "jedisLockMonitor", new JSONObject());
}
use of java.util.LongSummaryStatistics in project xian by happyyangyuan.
the class JedisTestDistributedLock method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
int number = msg.get("number", int.class, 10000);
final CountDownLatch startCountDownLatch = new CountDownLatch(1);
final CountDownLatch finishCountDownLatch = new CountDownLatch(number);
final List<Long> consumeTimes = new CopyOnWriteArrayList<>();
for (int i = 0; i < number; i++) {
int _i = i;
ThreadPoolManager.execute(() -> {
try {
startCountDownLatch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
long startTime = System.nanoTime();
// Redis Lock
DistributedLockSynchronizer.call("QPS_" + _i, 3, () -> {
return null;
}, 3);
// ZK Lock
// try
// {
// Synchronizer.call("QPS_" + _i, () -> {
// return null;
// }, 3L);
// }
// catch (Exception e)
// {
// LOG.error(e);
// }
finishCountDownLatch.countDown();
long endTime = System.nanoTime();
consumeTimes.add(endTime - startTime);
});
}
try {
startCountDownLatch.countDown();
finishCountDownLatch.await();
} catch (Exception e) {
LOG.error(e);
}
long totalConsumeTime = 0;
for (long consumeTime : consumeTimes) totalConsumeTime += consumeTime;
long avgConsumeTime = totalConsumeTime / number;
LongSummaryStatistics intSummaryStatistics = consumeTimes.stream().collect(Collectors.summarizingLong(value -> value));
String log = String.format("QPS, 加锁解锁, 任务数量: %s, 累计耗时: %s, %s, 平均耗时:%s, %s, %s", number, totalConsumeTime, totalConsumeTime / 1000000, avgConsumeTime, avgConsumeTime / 1000000, intSummaryStatistics);
LOG.info(log);
UnitResponse unitResponseObject = SyncXian.call("cache", "cacheKeys", new JSONObject() {
{
put("pattern", "LOCK_QPS_*");
}
});
if (unitResponseObject.succeeded() && unitResponseObject.getData() != null) {
Set<String> keys = unitResponseObject.getData();
LOG.info(String.format("分布锁剩余数量: %s", keys.size()));
}
SyncXian.call("diyMonitor", "jedisLockMonitor", new JSONObject() {
{
}
});
return UnitResponse.success(log);
}
Aggregations