Search in sources :

Example 6 with AppHelper

use of org.voltdb.client.exampleutils.AppHelper in project voltdb by VoltDB.

the class AsyncExportClient method main.

// Application entry point
public static void main(String[] args) {
    try {
        // ---------------------------------------------------------------------------------------------------------------------------------------------------
        // Use the AppHelper utility class to retrieve command line application parameters
        // Define parameters and pull from command line
        AppHelper apph = new AppHelper(AsyncBenchmark.class.getCanonicalName()).add("displayinterval", "display_interval_in_seconds", "Interval for performance feedback, in seconds.", 10).add("duration", "run_duration_in_seconds", "Benchmark duration, in seconds.", 120).add("servers", "comma_separated_server_list", "List of VoltDB servers to connect to.", "localhost").add("port", "port_number", "Client port to connect to on cluster nodes.", 21212).add("poolsize", "pool_size", "Size of the record pool to operate on - larger sizes will cause a higher insert/update-delete rate.", 100000).add("procedure", "procedure_name", "Procedure to call.", "JiggleExportSinglePartition").add("ratelimit", "rate_limit", "Rate limit to start from (number of transactions per second).", 100000).add("autotune", "auto_tune", "Flag indicating whether the benchmark should self-tune the transaction rate for a target execution latency (true|false).", "true").add("latencytarget", "latency_target", "Execution latency to target to tune transaction rate (in milliseconds).", 10).add("catalogswap", "catlog_swap", "Swap catalogs from the client", "true").add("exportgroups", "export_groups", "Multiple export connections", "false").add("timeout", "export_timeout", "max seconds to wait for export to complete", 300).setArguments(args);
        config = new ConnectionConfig(apph);
        // Retrieve parameters
        final boolean catalogSwap = apph.booleanValue("catalogswap");
        final String csv = apph.stringValue("statsfile");
        TxnIdWriter writer = new TxnIdWriter("dude", "clientlog");
        // Validate parameters
        apph.validate("duration", (config.duration > 0)).validate("poolsize", (config.poolSize > 0)).validate("ratelimit", (config.rateLimit > 0)).validate("latencytarget", (config.latencyTarget > 0));
        // Display actual parameters, for reference
        apph.printActualUsage();
        // ---------------------------------------------------------------------------------------------------------------------------------------------------
        // Get a client connection - we retry for a while in case the server hasn't started yet
        createClient();
        connect();
        // ---------------------------------------------------------------------------------------------------------------------------------------------------
        // Create a Timer task to display performance data on the procedure
        Timer timer = new Timer(true);
        timer.scheduleAtFixedRate(new TimerTask() {

            @Override
            public void run() {
                printStatistics(periodicStatsContext, true);
            }
        }, config.displayInterval * 1000l, config.displayInterval * 1000l);
        // ---------------------------------------------------------------------------------------------------------------------------------------------------
        benchmarkStartTS = System.currentTimeMillis();
        AtomicLong rowId = new AtomicLong(0);
        // Run the benchmark loop for the requested duration
        final long endTime = benchmarkStartTS + (1000l * config.duration);
        int swap_count = 0;
        boolean first_cat = false;
        while (endTime > System.currentTimeMillis()) {
            long currentRowId = rowId.incrementAndGet();
            // Post the request, asynchronously
            try {
                clientRef.get().callProcedure(new AsyncCallback(writer, currentRowId), config.procedure, currentRowId, 0);
            } catch (Exception e) {
                System.err.println("Exception: " + e);
                e.printStackTrace();
                System.exit(-1);
            }
            swap_count++;
            if (((swap_count % CATALOG_SWAP_INTERVAL) == 0) && catalogSwap) {
                System.out.println("Changing catalogs...");
                clientRef.get().updateApplicationCatalog(catalogs[first_cat ? 0 : 1], deployment);
                first_cat = !first_cat;
            }
        }
        shutdown.compareAndSet(false, true);
        // ---------------------------------------------------------------------------------------------------------------------------------------------------
        // We're done - stop the performance statistics display task
        timer.cancel();
        // ---------------------------------------------------------------------------------------------------------------------------------------------------
        clientRef.get().drain();
        Thread.sleep(10000);
        waitForStreamedAllocatedMemoryZero(clientRef.get(), config.exportTimeout);
        System.out.println("Writing export count as: " + TrackingResults.get(0));
        //Write to export table to get count to be expected on other side.
        if (config.exportGroups) {
            clientRef.get().callProcedure("JiggleExportGroupDoneTable", TrackingResults.get(0));
        } else {
            clientRef.get().callProcedure("JiggleExportDoneTable", TrackingResults.get(0));
        }
        writer.close(true);
        // Now print application results:
        // 1. Tracking statistics
        System.out.printf("-------------------------------------------------------------------------------------\n" + " Benchmark Results\n" + "-------------------------------------------------------------------------------------\n\n" + "A total of %d calls was received...\n" + " - %,9d Succeeded\n" + " - %,9d Failed (Transaction Error)\n" + "\n\n" + "-------------------------------------------------------------------------------------\n", TrackingResults.get(0) + TrackingResults.get(1), TrackingResults.get(0), TrackingResults.get(1));
        // 3. Performance statistics (we only care about the procedure that we're benchmarking)
        System.out.println("\n\n-------------------------------------------------------------------------------------\n" + " System Statistics\n" + "-------------------------------------------------------------------------------------\n\n");
        printStatistics(fullStatsContext, false);
        // Dump statistics to a CSV file
        clientRef.get().writeSummaryCSV(fullStatsContext.getStatsByProc().get(config.procedure), csv);
        clientRef.get().close();
    // ---------------------------------------------------------------------------------------------------------------------------------------------------
    } catch (Exception x) {
        System.err.println("Exception: " + x);
        x.printStackTrace();
    }
}
Also used : IOException(java.io.IOException) AtomicLong(java.util.concurrent.atomic.AtomicLong) AppHelper(org.voltdb.client.exampleutils.AppHelper) Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Example 7 with AppHelper

use of org.voltdb.client.exampleutils.AppHelper in project voltdb by VoltDB.

the class AsyncBenchmark method main.

// Application entry point
public static void main(String[] args) {
    try {
        // ---------------------------------------------------------------------------------------------------------------------------------------------------
        // Use the AppHelper utility class to retrieve command line application parameters
        // Define parameters and pull from command line
        AppHelper apph = new AppHelper(AsyncBenchmark.class.getCanonicalName()).add("displayinterval", "display_interval_in_seconds", "Interval for performance feedback, in seconds.", 10).add("duration", "run_duration_in_seconds", "Benchmark duration, in seconds.", 120).add("servers", "comma_separated_server_list", "List of VoltDB servers to connect to.", "localhost").add("port", "port_number", "Client port to connect to on cluster nodes.", 21212).add("poolsize", "pool_size", "Size of the record pool to operate on - larger sizes will cause a higher insert/update-delete rate.", 100000).add("procedure", "procedure_name", "Procedure to call.", "JiggleSinglePartition").add("wait", "wait_duration", "Wait duration (only when calling one of the Wait procedures), in milliseconds.", 0).add("ratelimit", "rate_limit", "Rate limit to start from (number of transactions per second).", 100000).add("autotune", "auto_tune", "Flag indicating whether the benchmark should self-tune the transaction rate for a target execution latency (true|false).", "true").add("latencytarget", "latency_target", "Execution latency to target to tune transaction rate (in milliseconds).", 10.0d).setArguments(args);
        // Retrieve parameters
        final long displayInterval = apph.longValue("displayinterval");
        final long duration = apph.longValue("duration");
        final String servers = apph.stringValue("servers");
        final int port = apph.intValue("port");
        final int poolSize = apph.intValue("poolsize");
        final String procedure = apph.stringValue("procedure");
        final long wait = apph.intValue("wait");
        final long rateLimit = apph.longValue("ratelimit");
        final boolean autoTune = apph.booleanValue("autotune");
        final double latencyTarget = apph.doubleValue("latencytarget");
        final String csv = apph.stringValue("statsfile");
        // Validate parameters
        apph.validate("duration", (duration > 0)).validate("poolsize", (duration > 0)).validate("wait", (wait >= 0)).validate("ratelimit", (rateLimit > 0)).validate("latencytarget", (latencyTarget > 0));
        // Display actual parameters, for reference
        apph.printActualUsage();
        // ---------------------------------------------------------------------------------------------------------------------------------------------------
        // Get a client connection - we retry for a while in case the server hasn't started yet
        Con = ClientConnectionPool.getWithRetry(servers, port);
        // ---------------------------------------------------------------------------------------------------------------------------------------------------
        // Create a Timer task to display performance data on the procedure
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {

            @Override
            public void run() {
                System.out.print(Con.getStatistics(procedure));
            }
        }, displayInterval * 1000l, displayInterval * 1000l);
        // ---------------------------------------------------------------------------------------------------------------------------------------------------
        // Pick the transaction rate limiter helping object to use based on user request (rate limiting or latency targeting)
        IRateLimiter limiter = null;
        if (autoTune)
            limiter = new LatencyLimiter(Con, procedure, latencyTarget, rateLimit);
        else
            limiter = new RateLimiter(rateLimit);
        // Run the benchmark loop for the requested duration
        final long endTime = System.currentTimeMillis() + (1000l * duration);
        Random rand = new Random();
        while (endTime > System.currentTimeMillis()) {
            // Post the request, asynchronously
            Con.executeAsync(new ProcedureCallback() {

                @Override
                public void clientCallback(ClientResponse response) throws Exception {
                    // Track the result of the request (Success, Failure)
                    if (response.getStatus() == ClientResponse.SUCCESS)
                        TrackingResults.incrementAndGet(0);
                    else
                        TrackingResults.incrementAndGet(1);
                }
            }, procedure, (long) rand.nextInt(poolSize), wait);
            // Use the limiter to throttle client activity
            limiter.throttle();
        }
        // ---------------------------------------------------------------------------------------------------------------------------------------------------
        // We're done - stop the performance statistics display task
        timer.cancel();
        // ---------------------------------------------------------------------------------------------------------------------------------------------------
        // Now print application results:
        // 1. Tracking statistics
        System.out.printf("-------------------------------------------------------------------------------------\n" + " Benchmark Results\n" + "-------------------------------------------------------------------------------------\n\n" + "A total of %d calls was received...\n" + " - %,9d Succeeded\n" + " - %,9d Failed (Transaction Error)\n" + "\n\n" + "-------------------------------------------------------------------------------------\n", TrackingResults.get(0) + TrackingResults.get(1), TrackingResults.get(0), TrackingResults.get(1));
        // 3. Performance statistics (we only care about the procedure that we're benchmarking)
        System.out.println("\n\n-------------------------------------------------------------------------------------\n" + " System Statistics\n" + "-------------------------------------------------------------------------------------\n\n");
        System.out.print(Con.getStatistics(procedure).toString(false));
        // Dump statistics to a CSV file
        Con.saveStatistics(csv);
        Con.close();
    // ---------------------------------------------------------------------------------------------------------------------------------------------------
    } catch (Exception x) {
        System.out.println("Exception: " + x);
        x.printStackTrace();
    }
}
Also used : ProcedureCallback(org.voltdb.client.ProcedureCallback) ClientResponse(org.voltdb.client.ClientResponse) LatencyLimiter(org.voltdb.client.exampleutils.LatencyLimiter) RateLimiter(org.voltdb.client.exampleutils.RateLimiter) IRateLimiter(org.voltdb.client.exampleutils.IRateLimiter) IRateLimiter(org.voltdb.client.exampleutils.IRateLimiter) AppHelper(org.voltdb.client.exampleutils.AppHelper) Timer(java.util.Timer) TimerTask(java.util.TimerTask) Random(java.util.Random)

Aggregations

AppHelper (org.voltdb.client.exampleutils.AppHelper)7 Timer (java.util.Timer)5 TimerTask (java.util.TimerTask)5 Random (java.util.Random)3 IRateLimiter (org.voltdb.client.exampleutils.IRateLimiter)3 RateLimiter (org.voltdb.client.exampleutils.RateLimiter)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ClientResponse (org.voltdb.client.ClientResponse)2 LatencyLimiter (org.voltdb.client.exampleutils.LatencyLimiter)2 AdhocSmash (adhocsmash.AdhocSmash)1 File (java.io.File)1 UnknownHostException (java.net.UnknownHostException)1 SQLException (java.sql.SQLException)1 LinkedList (java.util.LinkedList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Client (org.voltdb.client.Client)1 ClientConfig (org.voltdb.client.ClientConfig)1 ClientStatsContext (org.voltdb.client.ClientStatsContext)1 ProcedureCallback (org.voltdb.client.ProcedureCallback)1