Search in sources :

Example 6 with DescriptiveStatistics

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();
}
Also used : BurnTestUtil.generateQueryMessage(org.apache.cassandra.transport.BurnTestUtil.generateQueryMessage) QueryMessage(org.apache.cassandra.transport.messages.QueryMessage) java.util(java.util) SizeCaps(org.apache.cassandra.transport.BurnTestUtil.SizeCaps) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EncryptionOptions(org.apache.cassandra.config.EncryptionOptions) Global.nanoTime(org.apache.cassandra.utils.Clock.Global.nanoTime) AtomicReference(java.util.concurrent.atomic.AtomicReference) RateLimiter(com.google.common.util.concurrent.RateLimiter) BurnTestUtil.generateQueryMessage(org.apache.cassandra.transport.BurnTestUtil.generateQueryMessage) InetAddress(java.net.InetAddress) ServerSocket(java.net.ServerSocket) AllowAllNetworkAuthorizer(org.apache.cassandra.auth.AllowAllNetworkAuthorizer) AllowAllAuthorizer(org.apache.cassandra.auth.AllowAllAuthorizer) OverloadedException(org.apache.cassandra.exceptions.OverloadedException) AssertUtil(org.apache.cassandra.utils.AssertUtil) ByteBuf(io.netty.buffer.ByteBuf) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Parameterized(org.junit.runners.Parameterized) Before(org.junit.Before) ResultMessage(org.apache.cassandra.transport.messages.ResultMessage) AllowAllAuthenticator(org.apache.cassandra.auth.AllowAllAuthenticator) ReentrantLock(java.util.concurrent.locks.ReentrantLock) QueryState(org.apache.cassandra.service.QueryState) java.util.concurrent(java.util.concurrent) Test(org.junit.Test) Collectors(java.util.stream.Collectors) DescriptiveStatistics(org.apache.commons.math.stat.descriptive.DescriptiveStatistics) ClientMetrics(org.apache.cassandra.metrics.ClientMetrics) AtomicLong(java.util.concurrent.atomic.AtomicLong) Lock(java.util.concurrent.locks.Lock) BurnTestUtil.generateRows(org.apache.cassandra.transport.BurnTestUtil.generateRows) QueryMessage(org.apache.cassandra.transport.messages.QueryMessage) Throwables(org.apache.cassandra.utils.Throwables) Assert(org.junit.Assert) DescriptiveStatistics(org.apache.commons.math.stat.descriptive.DescriptiveStatistics) BurnTestUtil.generateQueryMessage(org.apache.cassandra.transport.BurnTestUtil.generateQueryMessage) ResultMessage(org.apache.cassandra.transport.messages.ResultMessage) QueryMessage(org.apache.cassandra.transport.messages.QueryMessage) ByteBuf(io.netty.buffer.ByteBuf) ReentrantLock(java.util.concurrent.locks.ReentrantLock) AtomicReference(java.util.concurrent.atomic.AtomicReference) QueryState(org.apache.cassandra.service.QueryState) OverloadedException(org.apache.cassandra.exceptions.OverloadedException) ResultMessage(org.apache.cassandra.transport.messages.ResultMessage) RateLimiter(com.google.common.util.concurrent.RateLimiter) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 7 with DescriptiveStatistics

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);
        }
    }
}
Also used : DescriptiveStatistics(org.apache.commons.math.stat.descriptive.DescriptiveStatistics) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RepositoryImpl(org.apache.jackrabbit.core.RepositoryImpl) File(java.io.File)

Example 8 with DescriptiveStatistics

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;
}
Also used : DescriptiveStatistics(org.apache.commons.math.stat.descriptive.DescriptiveStatistics)

Example 9 with DescriptiveStatistics

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());
}
Also used : PrintStream(java.io.PrintStream) DescriptiveStatistics(org.apache.commons.math.stat.descriptive.DescriptiveStatistics) DataBinner(alma.acs.algorithms.DataBinner) BinnedTimeValues(alma.acs.algorithms.DataBinner.BinnedTimeValues) File(java.io.File) TimeValue(alma.acs.algorithms.DataBinner.TimeValue)

Example 10 with DescriptiveStatistics

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());
}
Also used : PrintStream(java.io.PrintStream) DescriptiveStatistics(org.apache.commons.math.stat.descriptive.DescriptiveStatistics) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) TimeValue(alma.acs.algorithms.DataBinner.TimeValue)

Aggregations

DescriptiveStatistics (org.apache.commons.math.stat.descriptive.DescriptiveStatistics)14 ArrayList (java.util.ArrayList)5 File (java.io.File)4 TimeValue (alma.acs.algorithms.DataBinner.TimeValue)3 DataBinner (alma.acs.algorithms.DataBinner)2 BinnedTimeValues (alma.acs.algorithms.DataBinner.BinnedTimeValues)2 PrintStream (java.io.PrintStream)2 List (java.util.List)2 ComponentRequest (alma.acs.manager.logparser.ManagerStdoutParser.ComponentRequest)1 RateLimiter (com.google.common.util.concurrent.RateLimiter)1 GenericResponse (com.linkedin.thirdeye.dashboard.views.GenericResponse)1 ByteBuf (io.netty.buffer.ByteBuf)1 BufferedReader (java.io.BufferedReader)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 StringWriter (java.io.StringWriter)1 Method (java.lang.reflect.Method)1 InetAddress (java.net.InetAddress)1