use of org.apache.commons.math.stat.descriptive.DescriptiveStatistics in project cassandra by apache.
the class SimpleClientPerfTest method perfTest.
@SuppressWarnings({ "UnstableApiUsage", "UseOfSystemOutOrSystemErr", "ResultOfMethodCallIgnored" })
public void perfTest(SizeCaps requestCaps, SizeCaps responseCaps, AssertUtil.ThrowingSupplier<SimpleClient> clientSupplier, ProtocolVersion version) throws Throwable {
ResultMessage.Rows response = generateRows(0, responseCaps);
QueryMessage requestMessage = generateQueryMessage(0, requestCaps, version);
Envelope message = requestMessage.encode(version);
int requestSize = message.body.readableBytes();
message.release();
message = response.encode(version);
int responseSize = message.body.readableBytes();
message.release();
Server server = new Server.Builder().withHost(address).withPort(port).build();
ClientMetrics.instance.init(Collections.singleton(server));
server.start();
Message.Type.QUERY.unsafeSetCodec(new Message.Codec<QueryMessage>() {
public QueryMessage decode(ByteBuf body, ProtocolVersion version) {
QueryMessage queryMessage = QueryMessage.codec.decode(body, version);
return new QueryMessage(queryMessage.query, queryMessage.options) {
protected Message.Response execute(QueryState state, long queryStartNanoTime, boolean traceRequest) {
// unused
int idx = Integer.parseInt(queryMessage.query);
return generateRows(idx, responseCaps);
}
};
}
public void encode(QueryMessage queryMessage, ByteBuf dest, ProtocolVersion version) {
QueryMessage.codec.encode(queryMessage, dest, version);
}
public int encodedSize(QueryMessage queryMessage, ProtocolVersion version) {
return 0;
}
});
int threads = 1;
ExecutorService executor = Executors.newFixedThreadPool(threads);
AtomicReference<Throwable> error = new AtomicReference<>();
CountDownLatch signal = new CountDownLatch(1);
AtomicBoolean measure = new AtomicBoolean(false);
DescriptiveStatistics stats = new DescriptiveStatistics();
Lock lock = new ReentrantLock();
RateLimiter limiter = RateLimiter.create(2000);
AtomicLong overloadedExceptions = new AtomicLong(0);
// TODO: exercise client -> server large messages
for (int t = 0; t < threads; t++) {
executor.execute(() -> {
try (SimpleClient client = clientSupplier.get()) {
while (!executor.isShutdown() && error.get() == null) {
List<Message.Request> messages = new ArrayList<>();
for (int j = 0; j < 1; j++) messages.add(requestMessage);
if (measure.get()) {
try {
limiter.acquire();
long nanoStart = nanoTime();
client.execute(messages);
long elapsed = nanoTime() - nanoStart;
lock.lock();
try {
stats.addValue(TimeUnit.NANOSECONDS.toMicros(elapsed));
} finally {
lock.unlock();
}
} catch (RuntimeException e) {
if (Throwables.anyCauseMatches(e, cause -> cause instanceof OverloadedException)) {
overloadedExceptions.incrementAndGet();
} else {
throw e;
}
}
} else {
try {
limiter.acquire();
// warm-up
client.execute(messages);
} catch (RuntimeException e) {
// Ignore overloads during warmup...
if (!Throwables.anyCauseMatches(e, cause -> cause instanceof OverloadedException)) {
throw e;
}
}
}
}
} catch (Throwable e) {
e.printStackTrace();
error.set(e);
signal.countDown();
}
});
}
Assert.assertFalse(signal.await(30, TimeUnit.SECONDS));
measure.set(true);
Assert.assertFalse(signal.await(60, TimeUnit.SECONDS));
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
System.out.println("requestSize = " + requestSize);
System.out.println("responseSize = " + responseSize);
System.out.println("Latencies (in microseconds)");
System.out.println("Elements: " + stats.getN());
System.out.println("Mean: " + stats.getMean());
System.out.println("Variance: " + stats.getVariance());
System.out.println("Median: " + stats.getPercentile(0.5));
System.out.println("90p: " + stats.getPercentile(0.90));
System.out.println("95p: " + stats.getPercentile(0.95));
System.out.println("99p: " + stats.getPercentile(0.99));
System.out.println("Max: " + stats.getMax());
System.out.println("Failed due to overload: " + overloadedExceptions.get());
server.stop();
}
use of org.apache.commons.math.stat.descriptive.DescriptiveStatistics in project jackrabbit by apache.
the class AbstractPerformanceTest method runTest.
private void runTest(AbstractTest test, String name, byte[] conf) {
if (repoPattern.matcher(name).matches() && testPattern.matcher(test.toString()).matches()) {
// Create the repository directory
File dir = new File(new File("target", "repository"), name + "-" + test);
dir.mkdirs();
try {
// Copy the configuration file into the repository directory
File xml = new File(dir, "repository.xml");
OutputStream output = FileUtils.openOutputStream(xml);
try {
output.write(conf, 0, conf.length);
} finally {
output.close();
}
// Create the repository
RepositoryImpl repository = createRepository(dir, xml);
try {
// Run the test
DescriptiveStatistics statistics = runTest(test, repository);
if (statistics.getN() > 0) {
writeReport(test.toString(), name, statistics);
}
} finally {
repository.shutdown();
}
} catch (Throwable t) {
System.out.println("Unable to run " + test + ": " + t.getMessage());
} finally {
FileUtils.deleteQuietly(dir);
}
}
}
use of org.apache.commons.math.stat.descriptive.DescriptiveStatistics in project jackrabbit by apache.
the class AbstractPerformanceTest method runTest.
private DescriptiveStatistics runTest(AbstractTest test, Repository repository) throws Exception {
DescriptiveStatistics statistics = new DescriptiveStatistics();
test.setUp(repository, credentials);
try {
// Run a few iterations to warm up the system
long warmupEnd = System.currentTimeMillis() + warmup * 1000;
while (System.currentTimeMillis() < warmupEnd) {
test.execute();
}
// Run test iterations, and capture the execution times
long runtimeEnd = System.currentTimeMillis() + runtime * 1000;
while (System.currentTimeMillis() < runtimeEnd) {
statistics.addValue(test.execute());
}
} finally {
test.tearDown();
}
return statistics;
}
use of org.apache.commons.math.stat.descriptive.DescriptiveStatistics in project ACS by ACS-Community.
the class CdbCallStatistics method getCallFrequency.
/**
* @param operationName Can be null, to use calls to all operations.
*/
public void getCallFrequency(String operationName) throws FileNotFoundException {
OrbProfilerStatistics stat = new OrbProfilerStatistics(messages, logger);
final int binIntervalMillis = 1000;
List<TimeValue<Integer>> allCalls = stat.getFinishedRequests(operationName);
Collections.sort(allCalls);
DataBinner binner = new DataBinner();
List<BinnedTimeValues<Integer>> binnedAllCalls = binner.binTimedData(allCalls, binIntervalMillis);
String outFileName = getFileNameBase() + "_callFrequency" + (operationName != null ? operationName : "") + ".txt";
File outFile = new File(outFileName);
PrintStream pr = new PrintStream(outFile);
pr.println("time" + delim + "#calls/s" + delim + "duration max" + delim + "duration average");
for (BinnedTimeValues<Integer> binnedTimeValues : binnedAllCalls) {
List<TimeValue<Integer>> timeValuesPerBin = binnedTimeValues.binnedData;
DescriptiveStatistics callTimeStats = new DescriptiveStatistics();
for (TimeValue<Integer> timeValue : timeValuesPerBin) {
callTimeStats.addValue(timeValue.value);
}
// or timeValuesPerBin.size();
long numCallsPerBin = callTimeStats.getN();
pr.println(timeString(binnedTimeValues.timeMillis) + delim + numCallsPerBin + delim + (numCallsPerBin > 0 ? df2.format(callTimeStats.getMax()) : 0) + delim + (numCallsPerBin > 0 ? df2.format(callTimeStats.getMean()) : 0));
}
pr.close();
logger.info("Wrote " + outFile.getAbsolutePath());
}
use of org.apache.commons.math.stat.descriptive.DescriptiveStatistics in project ACS by ACS-Community.
the class CdbCallStatistics method getCallTimeByMethodGroup.
public void getCallTimeByMethodGroup() throws IOException {
OrbProfilerStatistics stat = new OrbProfilerStatistics(messages, logger);
Map<String, List<TimeValue<Integer>>> callGroups = new LinkedHashMap<String, List<TimeValue<Integer>>>();
// Corba object methods (TODO: add others)
callGroups.put("_is_a", stat.getFinishedRequests("_is_a"));
// methods for CDB change listening
List<TimeValue<Integer>> listenerCalls = new ArrayList<TimeValue<Integer>>();
listenerCalls.addAll(stat.getFinishedRequests("add_change_listener"));
listenerCalls.addAll(stat.getFinishedRequests("remove_change_listener"));
listenerCalls.addAll(stat.getFinishedRequests("listen_for_changes"));
Collections.sort(listenerCalls);
callGroups.put("listener methods", listenerCalls);
// the hefty XML requests
callGroups.put("get_DAO", stat.getFinishedRequests("get_DAO"));
// calls to a DAO remote object
List<TimeValue<Integer>> daoCalls = new ArrayList<TimeValue<Integer>>();
daoCalls.addAll(stat.getFinishedRequests("get_long"));
daoCalls.addAll(stat.getFinishedRequests("get_double"));
daoCalls.addAll(stat.getFinishedRequests("get_string"));
daoCalls.addAll(stat.getFinishedRequests("get_field_data"));
daoCalls.addAll(stat.getFinishedRequests("get_string_seq"));
daoCalls.addAll(stat.getFinishedRequests("get_long_seq"));
daoCalls.addAll(stat.getFinishedRequests("get_double_seq"));
daoCalls.addAll(stat.getFinishedRequests("destroy"));
Collections.sort(daoCalls);
callGroups.put("daoCalls", daoCalls);
// returns a DAO remote object
callGroups.put("get_DAO_Servant ", stat.getFinishedRequests("get_DAO_Servant"));
// listing of available nodes
List<TimeValue<Integer>> listingCalls = new ArrayList<TimeValue<Integer>>();
listingCalls.addAll(stat.getFinishedRequests("list_nodes"));
listingCalls.addAll(stat.getFinishedRequests("list_daos"));
Collections.sort(listingCalls);
callGroups.put("list methods", listingCalls);
// todo: Also use WDAL, WDAO methods
File outFile = new File(getFileNameBase() + "_callTimeByMethodGroup.txt");
PrintStream pr = new PrintStream(outFile);
pr.println("rdbCDB operation" + delim + "# calls" + delim + "average [ms]" + delim + "max(100%) [ms]" + delim + "max(99%) [ms]" + delim + "stdev [ms]");
for (String groupName : callGroups.keySet()) {
List<TimeValue<Integer>> calls = callGroups.get(groupName);
// call duration statistics
DescriptiveStatistics callTimeStats = new DescriptiveStatistics();
for (TimeValue<Integer> timeValue : calls) {
callTimeStats.addValue(timeValue.value);
}
pr.println(groupName + delim + calls.size() + delim + df2.format(callTimeStats.getMean()) + delim + (int) callTimeStats.getMax() + delim + (int) callTimeStats.getPercentile(99) + delim + df2.format(callTimeStats.getStandardDeviation()));
}
pr.close();
logger.info("Wrote " + outFile.getAbsolutePath());
}
Aggregations