Search in sources :

Example 6 with GridFileLock

use of org.apache.ignite.testframework.GridFileLock 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 7 with GridFileLock

use of org.apache.ignite.testframework.GridFileLock 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)

Example 8 with GridFileLock

use of org.apache.ignite.testframework.GridFileLock in project ignite by apache.

the class ClientCacheBenchmark method main.

/**
 * Runs benchmark.
 * @param args Command-line arguments.
 * @throws GridClientException If failed.
 */
public static void main(String[] args) throws GridClientException, IgniteCheckedException {
    GridFileLock fileLock = GridLoadTestUtils.fileLock();
    fileLock.lock();
    try {
        System.out.printf("%8s, %12s, %12s, %12s\n", "Threads", "It./s.", "It./s.*th.", "Iters.");
        if (args.length == 0) {
            for (int i = 1; i <= 16; i *= 2) {
                ClientCacheBenchmark benchmark = new ClientCacheBenchmark(i, 10000);
                benchmark.run(false);
                System.gc();
            }
            for (int i = 1; i <= 64; i *= 2) {
                ClientCacheBenchmark benchmark = new ClientCacheBenchmark(i, 10000);
                benchmark.run(true);
                System.gc();
            }
        } else {
            int nThreads = Integer.parseInt(args[0]);
            String outputFileName = (args.length >= 2 ? args[1] : null);
            ClientCacheBenchmark benchmark = null;
            for (int i = 0; i < 2; i++) {
                benchmark = new ClientCacheBenchmark(nThreads, 10000);
                benchmark.run(true);
            }
            if (outputFileName != null) {
                X.println("Writing test results to a file: " + outputFileName);
                assert benchmark != null;
                try {
                    GridLoadTestUtils.appendLineToFile(outputFileName, "%s,%d", GridLoadTestUtils.DATE_TIME_FORMAT.format(new Date()), Math.round(benchmark.getItersPerSec()));
                } catch (IOException e) {
                    X.error("Failed to output to a file", e);
                }
            }
        }
    } finally {
        fileLock.close();
    }
}
Also used : GridFileLock(org.apache.ignite.testframework.GridFileLock) IOException(java.io.IOException) Date(java.util.Date)

Aggregations

Date (java.util.Date)8 GridFileLock (org.apache.ignite.testframework.GridFileLock)8 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)4 Callable (java.util.concurrent.Callable)4 ExecutorService (java.util.concurrent.ExecutorService)4 Ignite (org.apache.ignite.Ignite)4 GridCumulativeAverage (org.apache.ignite.loadtests.util.GridCumulativeAverage)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Semaphore (java.util.concurrent.Semaphore)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 LongAdder (java.util.concurrent.atomic.LongAdder)1 IgniteException (org.apache.ignite.IgniteException)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 ComputeTaskCancelledException (org.apache.ignite.compute.ComputeTaskCancelledException)1 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)1