Search in sources :

Example 6 with GridCumulativeAverage

use of org.apache.ignite.loadtests.util.GridCumulativeAverage in project ignite by apache.

the class GridIoManagerBenchmark method sendMessages.

/**
 * @param g Kernal.
 * @param threads Number of send threads.
 * @param duration Test duration.
 * @param outputFilename Output file name.
 */
@SuppressWarnings("deprecation")
private static void sendMessages(IgniteKernal g, int threads, int duration, @Nullable final String outputFilename) {
    X.println(">>> Sending messages.");
    g.context().io().addMessageListener(TEST_TOPIC, new SenderMessageListener());
    Thread collector = startDaemon(new Runnable() {

        @Override
        public void run() {
            final long initTs = System.currentTimeMillis();
            long ts = initTs;
            long queries = msgCntr.sum();
            GridCumulativeAverage qpsAvg = new GridCumulativeAverage();
            try {
                while (!Thread.currentThread().isInterrupted()) {
                    U.sleep(10000);
                    long newTs = System.currentTimeMillis();
                    long newQueries = msgCntr.sum();
                    long executed = newQueries - queries;
                    long time = newTs - ts;
                    long qps = executed * 1000 / time;
                    boolean recordAvg = ts - initTs > WARM_UP_DUR;
                    if (recordAvg)
                        qpsAvg.update(qps);
                    X.println("Communication benchmark [qps=" + qps + (recordAvg ? ", qpsAvg=" + qpsAvg : "") + ", executed=" + executed + ", time=" + time + ']');
                    ts = newTs;
                    queries = newQueries;
                }
            } catch (IgniteInterruptedCheckedException ignored) {
            // No-op.
            }
            X.println("Average QPS: " + qpsAvg);
            if (outputFilename != null) {
                try {
                    X.println("Saving results to output file: " + outputFilename);
                    appendLineToFile(outputFilename, "%s,%d", GridLoadTestUtils.DATE_TIME_FORMAT.format(new Date()), qpsAvg.get());
                } catch (IOException e) {
                    X.println("Failed to record results to a file: " + e.getMessage());
                }
            }
        }
    });
    Collection<SendThread> sndThreads = new ArrayList<>(threads);
    for (int i = 0; i < threads; i++) {
        SendThread t = new SendThread(g);
        sndThreads.add(t);
        t.start();
    }
    try {
        U.sleep(duration > 0 ? duration * 1000 + WARM_UP_DUR : Long.MAX_VALUE);
    } catch (IgniteInterruptedCheckedException ignored) {
    // No-op.
    }
    collector.interrupt();
    for (SendThread t : sndThreads) t.interrupt();
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridCumulativeAverage(org.apache.ignite.loadtests.util.GridCumulativeAverage) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Date(java.util.Date)

Aggregations

GridCumulativeAverage (org.apache.ignite.loadtests.util.GridCumulativeAverage)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 Callable (java.util.concurrent.Callable)4 ExecutorService (java.util.concurrent.ExecutorService)4 GridFileLock (org.apache.ignite.testframework.GridFileLock)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 LongAdder (java.util.concurrent.atomic.LongAdder)2 Ignite (org.apache.ignite.Ignite)2 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)2 UUID (java.util.UUID)1 Semaphore (java.util.concurrent.Semaphore)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IgniteException (org.apache.ignite.IgniteException)1 ComputeTaskCancelledException (org.apache.ignite.compute.ComputeTaskCancelledException)1 GridBoundedConcurrentLinkedHashSet (org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashSet)1 IgniteUuid (org.apache.ignite.lang.IgniteUuid)1 QueuePolicy (org.jsr166.ConcurrentLinkedHashMap.QueuePolicy)1