Search in sources :

Example 1 with GridCumulativeAverage

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

the class GridBoundedConcurrentLinkedHashSetLoadTest method main.

/**
 * @param args Arguments.
 */
public static void main(String[] args) throws Exception {
    QueuePolicy qPlc = args.length > 0 ? QueuePolicy.valueOf(args[0]) : SINGLE_Q;
    int threadCnt = args.length > 1 ? Integer.valueOf(args[1]) : Runtime.getRuntime().availableProcessors();
    X.println("Queue policy: " + qPlc);
    X.println("Threads: " + threadCnt);
    ExecutorService pool = Executors.newFixedThreadPool(threadCnt);
    final Collection<IgniteUuid> set = new GridBoundedConcurrentLinkedHashSet<>(10240, 32, 0.75f, 128, qPlc);
    X.println("Set: " + set);
    final LongAdder execCnt = new LongAdder();
    final AtomicBoolean finish = new AtomicBoolean();
    // Thread that measures and outputs performance statistics.
    Thread collector = new Thread(new Runnable() {

        @SuppressWarnings({ "BusyWait", "InfiniteLoopStatement" })
        @Override
        public void run() {
            GridCumulativeAverage avgTasksPerSec = new GridCumulativeAverage();
            try {
                while (!finish.get()) {
                    Thread.sleep(UPDATE_INTERVAL_SEC * 1000);
                    long curTasksPerSec = execCnt.sumThenReset() / UPDATE_INTERVAL_SEC;
                    X.println(">>> Tasks/s: " + curTasksPerSec);
                    avgTasksPerSec.update(curTasksPerSec);
                }
            } catch (InterruptedException ignored) {
                X.println(">>> Interrupted.");
                Thread.currentThread().interrupt();
            }
        }
    });
    collector.start();
    Collection<Callable<Object>> producers = new ArrayList<>(threadCnt);
    for (int i = 0; i < threadCnt; i++) producers.add(new Callable<Object>() {

        @SuppressWarnings({ "unchecked", "InfiniteLoopStatement" })
        @Override
        public Object call() throws Exception {
            UUID id = UUID.randomUUID();
            try {
                while (!finish.get()) {
                    set.add(IgniteUuid.fromUuid(id));
                    execCnt.increment();
                }
                return null;
            } catch (Throwable t) {
                t.printStackTrace();
                throw new Exception(t);
            } finally {
                X.println("Thread finished.");
            }
        }
    });
    pool.invokeAll(producers);
}
Also used : ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) GridBoundedConcurrentLinkedHashSet(org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashSet) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LongAdder(java.util.concurrent.atomic.LongAdder) IgniteUuid(org.apache.ignite.lang.IgniteUuid) GridCumulativeAverage(org.apache.ignite.loadtests.util.GridCumulativeAverage) ExecutorService(java.util.concurrent.ExecutorService) UUID(java.util.UUID) QueuePolicy(org.jsr166.ConcurrentLinkedHashMap.QueuePolicy)

Example 2 with GridCumulativeAverage

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

the class GridJobExecutionLoadTestClient method main.

/**
 * @param args Args.
 * @throws Exception If failed.
 */
public static void main(String[] args) throws Exception {
    GridFileLock fileLock = GridLoadTestUtils.fileLock();
    fileLock.lock();
    try {
        final int noThreads = args.length > 0 ? Integer.parseInt(args[0]) : 64;
        final int duration = args.length > 1 ? Integer.parseInt(args[1]) : 0;
        final String outputFileName = args.length > 2 ? args[2] : null;
        X.println("Thread count: " + noThreads);
        g = G.start("modules/tests/config/jobs-load-client.xml");
        warmUp(noThreads);
        final Thread collector = new Thread(new Runnable() {

            @SuppressWarnings("BusyWait")
            @Override
            public void run() {
                GridCumulativeAverage avgTxPerSec = new GridCumulativeAverage();
                try {
                    while (!finish) {
                        Thread.sleep(UPDATE_INTERVAL_SEC * 1000);
                        long txPerSec = txCnt.sumThenReset() / UPDATE_INTERVAL_SEC;
                        X.println(">>>");
                        X.println(">>> Transactions/s: " + txPerSec);
                        avgTxPerSec.update(txPerSec);
                    }
                } catch (InterruptedException ignored) {
                    X.println(">>> Interrupted.");
                    Thread.currentThread().interrupt();
                }
                X.println(">>> Average Transactions/s: " + avgTxPerSec);
                if (outputFileName != null) {
                    try {
                        X.println("Writing results to file: " + outputFileName);
                        GridLoadTestUtils.appendLineToFile(outputFileName, "%s,%d", GridLoadTestUtils.DATE_TIME_FORMAT.format(new Date()), avgTxPerSec.get());
                    } catch (IOException e) {
                        X.error("Failed to output results to file.", e);
                    }
                }
            }
        });
        X.println("Running main test...");
        Thread timer = null;
        try {
            ExecutorService pool = Executors.newFixedThreadPool(noThreads);
            Collection<Callable<Object>> clients = new ArrayList<>(noThreads);
            for (int i = 0; i < noThreads; i++) clients.add(new GridJobExecutionLoadTestClient());
            collector.start();
            if (duration > 0) {
                timer = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            Thread.sleep(duration * 1000);
                            finish = true;
                        } catch (InterruptedException ignored) {
                            X.println(">>> Interrupted.");
                        }
                    }
                });
                timer.start();
            }
            pool.invokeAll(clients);
            collector.interrupt();
            pool.shutdown();
        } finally {
            if (collector != null && !collector.isInterrupted())
                collector.interrupt();
            if (timer != null)
                timer.interrupt();
            G.stopAll(true);
        }
    } finally {
        fileLock.close();
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) Date(java.util.Date) Callable(java.util.concurrent.Callable) GridCumulativeAverage(org.apache.ignite.loadtests.util.GridCumulativeAverage) ExecutorService(java.util.concurrent.ExecutorService) GridFileLock(org.apache.ignite.testframework.GridFileLock)

Example 3 with GridCumulativeAverage

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

the class GridJobExecutionSingleNodeSemaphoreLoadTest method main.

/**
 * @param args Command line arguments:
 *             1-st: Number of worker threads. Default equals to available CPU number / 2.
 *             2-nd: Concurrent tasks count. Default: 1024.
 *             3-rd: Test duration in seconds. 0 means infinite. Default: 0.
 *             4-th: File to output test results to.
 * @throws Exception If failed.
 */
public static void main(String[] args) throws Exception {
    GridFileLock fileLock = GridLoadTestUtils.fileLock();
    fileLock.lock();
    try {
        // Command line arguments.
        // 
        // NOTE: on MacOS better numbers are shown if public pool core and max sizes are
        // equal to CPU count. And producer threads count is equal to CPU count.
        // 
        int threadCnt = args.length > 0 ? Integer.parseInt(args[0]) : Runtime.getRuntime().availableProcessors() / 2;
        int taskCnt = args.length > 1 ? Integer.parseInt(args[1]) : 1024;
        final int duration = args.length > 2 ? Integer.parseInt(args[2]) : 0;
        final String outputFileName = args.length > 3 ? args[3] : null;
        final LongAdder execCnt = new LongAdder();
        try {
            final Ignite g = G.start("modules/tests/config/grid-job-load.xml");
            X.println("Thread count: " + threadCnt);
            X.println("Task count: " + taskCnt);
            X.println("Duration: " + duration);
            X.println("Warming up...");
            g.compute().execute(GridJobExecutionLoadTestTask.class, null);
            g.compute().execute(GridJobExecutionLoadTestTask.class, null);
            runTest(g, threadCnt, taskCnt, WARM_UP_DURATION, execCnt);
            System.gc();
            execCnt.reset();
            X.println("Running main test.");
            IgniteInternalFuture<Void> collectorFut = GridTestUtils.runAsync(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    GridCumulativeAverage avgTasksPerSec = new GridCumulativeAverage();
                    try {
                        while (!Thread.currentThread().isInterrupted()) {
                            U.sleep(UPDATE_INTERVAL_SEC * 1000);
                            long curTasksPerSec = execCnt.sumThenReset() / UPDATE_INTERVAL_SEC;
                            X.println(">>> Tasks/s: " + curTasksPerSec);
                            avgTasksPerSec.update(curTasksPerSec);
                        }
                    } catch (IgniteInterruptedCheckedException ignored) {
                        X.println(">>> Interrupted.");
                        Thread.currentThread().interrupt();
                    }
                    X.println(">>> Average tasks/s: " + avgTasksPerSec);
                    if (outputFileName != null) {
                        X.println("Writing test results to a file: " + outputFileName);
                        try {
                            GridLoadTestUtils.appendLineToFile(outputFileName, "%s,%d", GridLoadTestUtils.DATE_TIME_FORMAT.format(new Date()), avgTasksPerSec.get());
                        } catch (IOException e) {
                            X.error("Failed to output to a file", e);
                        }
                    }
                    return null;
                }
            });
            runTest(g, threadCnt, taskCnt, duration * 1000, execCnt);
            X.println("All done, stopping.");
            collectorFut.cancel();
        } finally {
            G.stopAll(true);
        }
    } finally {
        fileLock.close();
    }
}
Also used : IOException(java.io.IOException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException) Date(java.util.Date) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) LongAdder(java.util.concurrent.atomic.LongAdder) GridCumulativeAverage(org.apache.ignite.loadtests.util.GridCumulativeAverage) Ignite(org.apache.ignite.Ignite) GridFileLock(org.apache.ignite.testframework.GridFileLock)

Example 4 with GridCumulativeAverage

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

the class GridJobExecutionLoadTestClientSemaphore method main.

/**
 * @param args Args.
 * @throws Exception If failed.
 */
public static void main(String[] args) throws Exception {
    GridFileLock fileLock = GridLoadTestUtils.fileLock();
    fileLock.lock();
    try {
        final int noThreads = args.length > 0 ? Integer.parseInt(args[0]) : Runtime.getRuntime().availableProcessors();
        final int duration = args.length > 1 ? Integer.parseInt(args[1]) : 0;
        int tasksCnt = args.length > 2 ? Integer.parseInt(args[2]) : 4069;
        final String outputFileName = args.length > 3 ? args[3] : null;
        X.println("Thread count: " + noThreads);
        X.println("Tasks count: " + tasksCnt);
        tasksSem = new Semaphore(tasksCnt);
        g = G.start("modules/tests/config/jobs-load-client.xml");
        warmUp(noThreads);
        final Thread collector = new Thread(new Runnable() {

            @SuppressWarnings("BusyWait")
            @Override
            public void run() {
                GridCumulativeAverage avgTxPerSec = new GridCumulativeAverage();
                try {
                    while (!finish) {
                        Thread.sleep(UPDATE_INTERVAL_SEC * 1000);
                        long txPerSec = txCnt.sumThenReset() / UPDATE_INTERVAL_SEC;
                        X.println(">>>");
                        X.println(">>> Transactions/s: " + txPerSec);
                        avgTxPerSec.update(txPerSec);
                    }
                } catch (InterruptedException ignored) {
                    X.println(">>> Interrupted.");
                    Thread.currentThread().interrupt();
                }
                X.println(">>> Average Transactions/s: " + avgTxPerSec);
                if (outputFileName != null) {
                    try {
                        X.println("Writing results to file: " + outputFileName);
                        GridLoadTestUtils.appendLineToFile(outputFileName, "%s,%d", GridLoadTestUtils.DATE_TIME_FORMAT.format(new Date()), avgTxPerSec.get());
                    } catch (IOException e) {
                        X.error("Failed to output results to file.", e);
                    }
                }
            }
        });
        X.println("Running main test...");
        Thread timer = null;
        try {
            ExecutorService pool = Executors.newFixedThreadPool(noThreads);
            Collection<Callable<Object>> clients = new ArrayList<>(noThreads);
            for (int i = 0; i < noThreads; i++) clients.add(new GridJobExecutionLoadTestClientSemaphore());
            collector.start();
            if (duration > 0) {
                timer = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            Thread.sleep(duration * 1000);
                            finish = true;
                        } catch (InterruptedException ignored) {
                            X.println(">>> Interrupted.");
                        }
                    }
                });
                timer.start();
            }
            pool.invokeAll(clients);
            collector.interrupt();
            pool.shutdown();
        } finally {
            if (collector != null && !collector.isInterrupted())
                collector.interrupt();
            if (timer != null)
                timer.interrupt();
            G.stopAll(true);
        }
    } finally {
        fileLock.close();
    }
}
Also used : ArrayList(java.util.ArrayList) Semaphore(java.util.concurrent.Semaphore) IOException(java.io.IOException) Date(java.util.Date) Callable(java.util.concurrent.Callable) GridCumulativeAverage(org.apache.ignite.loadtests.util.GridCumulativeAverage) ExecutorService(java.util.concurrent.ExecutorService) GridFileLock(org.apache.ignite.testframework.GridFileLock)

Example 5 with GridCumulativeAverage

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

the class GridJobExecutionSingleNodeLoadTest method main.

/**
 * @param args Command line arguments:
 *             1-st: Number of worker threads. Default: 32.
 *             2-nd: Test duration in seconds. 0 means infinite. Default: 0.
 *             3-rd: File to output test results to.
 * @throws Exception If failed.
 */
public static void main(String[] args) throws Exception {
    GridFileLock fileLock = GridLoadTestUtils.fileLock();
    fileLock.lock();
    try {
        // Command line arguments.
        int threadCnt = args.length == 0 ? 64 : Integer.parseInt(args[0]);
        final int duration = args.length < 2 ? 0 : Integer.parseInt(args[1]);
        final String outputFileName = args.length < 3 ? null : args[2];
        final AtomicLong tasksCnt = new AtomicLong();
        final AtomicBoolean finish = new AtomicBoolean();
        ExecutorService pool = Executors.newFixedThreadPool(threadCnt);
        Collection<Callable<Object>> producers = new ArrayList<>(threadCnt);
        Thread collector = null;
        Thread timer = null;
        try {
            final Ignite g = G.start("modules/core/src/test/config/grid-job-load.xml");
            X.println("Warming up...");
            GridLoadTestUtils.runMultithreadedInLoop(new Callable<Object>() {

                @Override
                public Object call() {
                    g.compute().execute(GridJobExecutionLoadTestTask.class, null);
                    return null;
                }
            }, threadCnt, WARM_UP_DURATION);
            System.gc();
            X.println("Running main test.");
            for (int i = 0; i < threadCnt; i++) producers.add(new Callable<Object>() {

                @SuppressWarnings({ "unchecked", "InfiniteLoopStatement" })
                @Override
                public Object call() throws Exception {
                    while (!finish.get()) {
                        try {
                            g.compute().execute(GridJobExecutionLoadTestTask.class, null);
                            tasksCnt.incrementAndGet();
                        } catch (ComputeTaskCancelledException ignored) {
                        // No-op.
                        } catch (IgniteException e) {
                            e.printStackTrace();
                        }
                    }
                    return null;
                }
            });
            // Thread that measures and outputs performance statistics.
            collector = new Thread(new Runnable() {

                @SuppressWarnings({ "BusyWait", "InfiniteLoopStatement" })
                @Override
                public void run() {
                    GridCumulativeAverage avgTasksPerSec = new GridCumulativeAverage();
                    try {
                        while (!finish.get()) {
                            long cnt0 = tasksCnt.get();
                            Thread.sleep(UPDATE_INTERVAL_SEC * 1000);
                            long cnt1 = tasksCnt.get();
                            long curTasksPerSec = (cnt1 - cnt0) / UPDATE_INTERVAL_SEC;
                            X.println(">>> Tasks/s: " + curTasksPerSec);
                            avgTasksPerSec.update(curTasksPerSec);
                        }
                    } catch (InterruptedException ignored) {
                        X.println(">>> Interrupted.");
                        Thread.currentThread().interrupt();
                    }
                    X.println(">>> Average tasks/s: " + avgTasksPerSec);
                    if (outputFileName != null) {
                        X.println("Writing test results to a file: " + outputFileName);
                        try {
                            GridLoadTestUtils.appendLineToFile(outputFileName, "%s,%d", GridLoadTestUtils.DATE_TIME_FORMAT.format(new Date()), avgTasksPerSec.get());
                        } catch (IOException e) {
                            X.error("Failed to output to a file", e);
                        }
                    }
                }
            });
            collector.start();
            if (duration > 0) {
                // Thread that stops the test after a specified period of time.
                timer = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            Thread.sleep(duration * 1000);
                            finish.set(true);
                        } catch (InterruptedException ignored) {
                        // No-op.
                        }
                    }
                });
                timer.start();
            }
            pool.invokeAll(producers);
            X.println("All done, stopping.");
            collector.interrupt();
            pool.shutdown();
        } finally {
            if (collector != null && !collector.isInterrupted())
                collector.interrupt();
            if (timer != null)
                timer.interrupt();
            G.stopAll(true);
        }
    } finally {
        fileLock.close();
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) Date(java.util.Date) ComputeTaskCancelledException(org.apache.ignite.compute.ComputeTaskCancelledException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) IgniteException(org.apache.ignite.IgniteException) GridCumulativeAverage(org.apache.ignite.loadtests.util.GridCumulativeAverage) ExecutorService(java.util.concurrent.ExecutorService) Ignite(org.apache.ignite.Ignite) GridFileLock(org.apache.ignite.testframework.GridFileLock)

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