Search in sources :

Example 1 with IRateLimiter

use of org.voltdb.client.exampleutils.IRateLimiter 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)

Example 2 with IRateLimiter

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

the class AdhocSmash method main.

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(AdhocSmash.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("ratelimit", "rate_limit", "Rate limit to start from (number of transactions per second).", 100000).setArguments(args);
        // Retrieve parameters
        long displayInterval = apph.longValue("displayinterval");
        long duration = apph.longValue("duration");
        String servers = apph.stringValue("servers");
        int port = apph.intValue("port");
        long rateLimit = apph.longValue("ratelimit");
        Random rand = new Random();
        // Validate parameters
        apph.validate("duration", (duration > 0)).validate("displayinterval", (displayInterval > 0)).validate("ratelimit", (rateLimit > 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);
        // ---------------------------------------------------------------------------------------------------------------------------------------------------
        // Pick the transaction rate limiter helping object to use based on user request (rate limiting or latency targeting)
        IRateLimiter limiter = null;
        limiter = new RateLimiter(rateLimit);
        int cycle = 0;
        // Run the benchmark loop for the requested duration
        final long endTime = System.currentTimeMillis() + (1000l * duration);
        while (endTime > System.currentTimeMillis()) {
            // First, Insert
            if (rand.nextInt(1000) < 5) {
                //System.out.println("Insert adhoc");
                String query = "insert into votes (phone_number, state, contestant_number) values (" + cycle + ", 'MA', 999);";
                ClientResponse response = Con.execute("@AdHoc", query);
                InsertCallback blah = new InsertCallback(true, cycle);
                blah.clientCallback(response);
            } else {
                //System.out.println("Insert regular");
                Con.executeAsync(new InsertCallback(false, cycle), "VOTES.insert", cycle, "MA", 999);
            }
            // Then, update
            if (rand.nextInt(1000) < 5) {
                //System.out.println("Update adhoc");
                ClientResponse response = Con.execute("@AdHoc", "update votes set state='RI', contestant_number=" + cycle + " where phone_number=" + cycle + ";");
                UpdateCallback blah = new UpdateCallback(true, cycle);
                blah.clientCallback(response);
            } else {
                //System.out.println("Update regular");
                Con.executeAsync(new UpdateCallback(false, cycle), "VOTES.update", cycle, "MA", cycle, cycle);
            }
            // Finally, delete
            if (rand.nextInt(1000) < 5) {
                //System.out.println("Delete adhoc");
                ClientResponse response = Con.execute("@AdHoc", "delete from votes where contestant_number=" + cycle + ";");
                DeleteCallback blah = new DeleteCallback(true, cycle);
                blah.clientCallback(response);
            } else {
                //System.out.println("Delete regular");
                Con.executeAsync(new DeleteCallback(false, cycle), "Delete", cycle);
            }
            cycle++;
            // Use the limiter to throttle client activity
            limiter.throttle();
        }
        // --------------------------------------------------------------------------------------------------------
        Con.close();
    // ---------------------------------------------------------------------------------------------------------------------------------------------------
    } catch (Exception x) {
        System.out.println("Exception: " + x);
        x.printStackTrace();
    }
}
Also used : AdhocSmash(adhocsmash.AdhocSmash) ClientResponse(org.voltdb.client.ClientResponse) RateLimiter(org.voltdb.client.exampleutils.RateLimiter) IRateLimiter(org.voltdb.client.exampleutils.IRateLimiter) IRateLimiter(org.voltdb.client.exampleutils.IRateLimiter) AppHelper(org.voltdb.client.exampleutils.AppHelper) Random(java.util.Random)

Example 3 with IRateLimiter

use of org.voltdb.client.exampleutils.IRateLimiter 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("pool-size", "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.", "UpdateKey").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("latency-target", "latency_target", "Execution latency to target to tune transaction rate (in milliseconds).", 10.0d).add("run-loader", "Run the leveldb loader", "true").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("pool-size");
        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("latency-target");
        final String csv = apph.stringValue("stats");
        final boolean runLoader = apph.booleanValue("run-loader");
        // Validate parameters
        apph.validate("duration", (duration > 0)).validate("pool-size", (duration > 0)).validate("wait", (wait >= 0)).validate("ratelimit", (rateLimit > 0)).validate("latency-target", (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 = autoTune ? new LatencyLimiter(Con, procedure, latencyTarget, rateLimit) : new RateLimiter(rateLimit);
        // Run the loader first.
        if (runLoader) {
            doLoader(poolSize);
        }
        // Run the benchmark loop for the requested duration
        final long endTime = System.currentTimeMillis() + (1000l * duration);
        Random rand = new Random();
        while (endTime > System.currentTimeMillis()) {
            doBenchmark(procedure, poolSize, rand, 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 : 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

Random (java.util.Random)3 AppHelper (org.voltdb.client.exampleutils.AppHelper)3 IRateLimiter (org.voltdb.client.exampleutils.IRateLimiter)3 RateLimiter (org.voltdb.client.exampleutils.RateLimiter)3 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 ClientResponse (org.voltdb.client.ClientResponse)2 LatencyLimiter (org.voltdb.client.exampleutils.LatencyLimiter)2 AdhocSmash (adhocsmash.AdhocSmash)1 ProcedureCallback (org.voltdb.client.ProcedureCallback)1