Search in sources :

Example 11 with ProcedureCallback

use of org.voltdb.client.ProcedureCallback in project voltdb by VoltDB.

the class TestJSONInterface method testAJAXAndClientTogether.

public void testAJAXAndClientTogether() throws Exception {
    try {
        String simpleSchema = "CREATE TABLE foo (\n" + "    bar BIGINT NOT NULL,\n" + "    PRIMARY KEY (bar)\n" + ");";
        VoltProjectBuilder builder = new VoltProjectBuilder();
        builder.addLiteralSchema(simpleSchema);
        builder.setHTTPDPort(8095);
        boolean success = builder.compile(Configuration.getPathToCatalogForTest("json.jar"));
        assertTrue(success);
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = config.setPathToCatalogForTest("json.jar");
        config.m_pathToDeployment = builder.getPathToDeployment();
        server = new ServerThread(config);
        server.start();
        server.waitForInitialization();
        client = ClientFactory.createClient(new ClientConfig());
        client.createConnection("localhost");
        final AtomicLong fcnt = new AtomicLong(0);
        final AtomicLong scnt = new AtomicLong(0);
        final AtomicLong cfcnt = new AtomicLong(0);
        final AtomicLong cscnt = new AtomicLong(0);
        final int jsonRunnerCount = 50;
        final int clientRunnerCount = 50;
        final ParameterSet pset = ParameterSet.fromArrayNoCopy("select count(*) from foo");
        String responseJSON = callProcOverJSON("@AdHoc", pset, null, null, false);
        Response r = responseFromJSON(responseJSON);
        assertEquals(ClientResponse.SUCCESS, r.status);
        //Do replicated table read.
        class JSONRunner implements Runnable {

            @Override
            public void run() {
                try {
                    String rresponseJSON = callProcOverJSON("@AdHoc", pset, null, null, false);
                    System.out.println("Response: " + rresponseJSON);
                    Response rr = responseFromJSON(rresponseJSON);
                    assertEquals(ClientResponse.SUCCESS, rr.status);
                    scnt.incrementAndGet();
                } catch (Exception ex) {
                    fcnt.incrementAndGet();
                    ex.printStackTrace();
                }
            }
        }
        //Do replicated table read.
        class ClientRunner implements Runnable {

            class Callback implements ProcedureCallback {

                @Override
                public void clientCallback(ClientResponse clientResponse) throws Exception {
                    if (clientResponse.getStatus() == ClientResponse.SUCCESS) {
                        cscnt.incrementAndGet();
                    } else {
                        System.out.println("Client failed: " + clientResponse.getStatusString());
                        cfcnt.incrementAndGet();
                    }
                }
            }

            @Override
            public void run() {
                try {
                    if (!client.callProcedure(new Callback(), "@AdHoc", "SELECT count(*) from foo")) {
                        cfcnt.decrementAndGet();
                    }
                } catch (Exception ex) {
                    fcnt.incrementAndGet();
                    ex.printStackTrace();
                }
            }
        }
        //Start runners
        ExecutorService es = CoreUtils.getBoundedSingleThreadExecutor("runners", jsonRunnerCount);
        for (int i = 0; i < jsonRunnerCount; i++) {
            es.submit(new JSONRunner());
        }
        ExecutorService ces = CoreUtils.getBoundedSingleThreadExecutor("crunners", clientRunnerCount);
        for (int i = 0; i < clientRunnerCount; i++) {
            ces.submit(new ClientRunner());
        }
        es.shutdown();
        es.awaitTermination(1, TimeUnit.DAYS);
        assertEquals(jsonRunnerCount, scnt.get());
        ces.shutdown();
        ces.awaitTermination(1, TimeUnit.DAYS);
        client.drain();
        assertEquals(clientRunnerCount, cscnt.get());
        responseJSON = callProcOverJSON("@AdHoc", pset, null, null, false);
        r = responseFromJSON(responseJSON);
        assertEquals(ClientResponse.SUCCESS, r.status);
        //Make sure we are still good.
        ClientResponse resp = client.callProcedure("@AdHoc", "SELECT count(*) from foo");
        assertEquals(ClientResponse.SUCCESS, resp.getStatus());
    } finally {
        if (server != null) {
            server.shutdown();
            server.join();
        }
        server = null;
        if (client != null) {
            client.close();
        }
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Configuration(org.voltdb.VoltDB.Configuration) JSONException(org.json_voltpatches.JSONException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException) ClientResponse(org.voltdb.client.ClientResponse) HttpResponse(org.apache.http.HttpResponse) AtomicLong(java.util.concurrent.atomic.AtomicLong) ProcedureCallback(org.voltdb.client.ProcedureCallback) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) ExecutorService(java.util.concurrent.ExecutorService) ClientConfig(org.voltdb.client.ClientConfig)

Example 12 with ProcedureCallback

use of org.voltdb.client.ProcedureCallback in project voltdb by VoltDB.

the class TestCompactingViewsSuite method runCompactingViewsForTable.

void runCompactingViewsForTable(String insertName, String deleteName, String queryName) throws Exception {
    Client client = getClient();
    String filler = "a";
    for (int i = 0; i < 62; i++) {
        filler = filler + "a";
    }
    assert (filler.length() == 63);
    final int MAX_ROWS = 25000;
    ProcedureCallback modifyOneCheck = new ProcedureCallback() {

        @Override
        public void clientCallback(ClientResponse clientResponse) throws Exception {
            if (clientResponse.getStatus() != ClientResponse.SUCCESS) {
                System.err.println(clientResponse.getStatusString());
            }
            assertEquals(ClientResponse.SUCCESS, clientResponse.getStatus());
            assertEquals(1, clientResponse.getResults()[0].asScalarLong());
        }
    };
    // insert baseline rows
    System.out.printf("Inserting %d rows into the primary table and the view\n", MAX_ROWS);
    for (int i = 0; i < MAX_ROWS; i++) {
        client.callProcedure(modifyOneCheck, insertName, i, String.valueOf(i), filler, filler, filler, filler, filler, filler, filler, filler);
    }
    client.drain();
    // delete half of them - should trigger compaction
    System.out.printf("Deleting all even rows\n");
    for (int i = 0; i < MAX_ROWS; i += 2) {
        client.callProcedure(modifyOneCheck, deleteName, i);
    }
    client.drain();
    // do a query that hits the index hard
    System.out.printf("Doing a full select and using the index for ordering.\n");
    VoltTable table1 = client.callProcedure(queryName).getResults()[0];
    assertEquals(MAX_ROWS / 2, table1.getRowCount());
    // put the missing half back
    System.out.printf("Inserting even rows back into the table and view\n");
    for (int i = 0; i < MAX_ROWS; i += 2) {
        VoltTable table = client.callProcedure(insertName, i, String.valueOf(i), filler, filler, filler, filler, filler, filler, filler, filler).getResults()[0];
        assertEquals(1, table.asScalarLong());
    }
    // adding view duplicates for half of the rows
    System.out.printf("Inserting duplicates of half of the tuples (with unique primary keys)\n");
    for (int i = MAX_ROWS + 1; i < (MAX_ROWS * 2); i += 2) {
        VoltTable table = client.callProcedure(insertName, i, String.valueOf(i / 2), filler, filler, filler, filler, filler, filler, filler, filler).getResults()[0];
        assertEquals(1, table.asScalarLong());
    }
    // delete all of the rows again, but in three passes to trigger more compaction
    System.out.printf("Deleting all %d rows\n", MAX_ROWS);
    for (int i = 1; i < MAX_ROWS; i += 2) {
        VoltTable table = client.callProcedure(deleteName, i).getResults()[0];
        assertEquals(1, table.asScalarLong());
    }
    for (int i = 0; i < MAX_ROWS; i += 2) {
        VoltTable table = client.callProcedure(deleteName, i).getResults()[0];
        assertEquals(1, table.asScalarLong());
    }
    for (int i = MAX_ROWS + 1; i < (MAX_ROWS * 2); i += 2) {
        VoltTable table = client.callProcedure(deleteName, i).getResults()[0];
        assertEquals(1, table.asScalarLong());
    }
}
Also used : ProcedureCallback(org.voltdb.client.ProcedureCallback) ClientResponse(org.voltdb.client.ClientResponse) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable)

Example 13 with ProcedureCallback

use of org.voltdb.client.ProcedureCallback in project voltdb by VoltDB.

the class TestMPMultiRoundTripSuite method testSimultaneousMultiAndSinglePartTxns.

public void testSimultaneousMultiAndSinglePartTxns() throws Exception {
    int test_size = 100;
    final Client client = this.getClient();
    ProcedureCallback callback = new ProcedureCallback() {

        @Override
        public void clientCallback(ClientResponse clientResponse) throws Exception {
            if (clientResponse.getStatus() != ClientResponse.SUCCESS) {
                throw new RuntimeException("Failed with response: " + clientResponse.getStatusString());
            }
        }
    };
    client.callProcedure(callback, "MultiRoundMixReadsAndWrites", test_size, test_size * 2);
    // stall a little to try to avoid doing one of the SPs before the MP
    // takes control of the whole cluster
    Thread.sleep(1000);
    for (int i = 0; i < test_size; i++) {
        client.callProcedure(callback, "UpdateP1SP", i);
    }
    client.drain();
    ClientResponse resp2 = client.callProcedure("GetP1");
    ClientResponse resp = client.callProcedure("SumP1");
    assertEquals(resp2.getResults()[0].toString(), test_size * 2, resp.getResults()[0].asScalarLong());
}
Also used : ProcedureCallback(org.voltdb.client.ProcedureCallback) ClientResponse(org.voltdb.client.ClientResponse) Client(org.voltdb.client.Client)

Example 14 with ProcedureCallback

use of org.voltdb.client.ProcedureCallback in project voltdb by VoltDB.

the class TestFunctionsSuite method initialLoad.

private void initialLoad(Client client, String tableName) throws IOException, NoConnectionsException, InterruptedException {
    ProcedureCallback callback = new ProcedureCallback() {

        @Override
        public void clientCallback(ClientResponse clientResponse) throws Exception {
            if (clientResponse.getStatus() != ClientResponse.SUCCESS) {
                throw new RuntimeException("Failed with response: " + clientResponse.getStatusString());
            }
        }
    };
    /*
        CREATE TABLE ??? (
                ID INTEGER DEFAULT '0' NOT NULL,
                DESC VARCHAR(300),
                NUM INTEGER,
                RATIO FLOAT,
                PAST TIMESTAMP DEFAULT NULL,
                PRIMARY KEY (ID)
                );
        */
    for (int id = 7; id < 15; id++) {
        client.callProcedure(callback, tableName + ".insert", // ID
        -id, // DESC
        "X" + String.valueOf(id) + paddedToNonInlineLength, // NUM
        10, // RATIO
        1.1, // PAST
        new Timestamp(100000000L));
        client.drain();
    }
}
Also used : ProcedureCallback(org.voltdb.client.ProcedureCallback) ClientResponse(org.voltdb.client.ClientResponse) Timestamp(java.sql.Timestamp)

Example 15 with ProcedureCallback

use of org.voltdb.client.ProcedureCallback 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

ProcedureCallback (org.voltdb.client.ProcedureCallback)29 ClientResponse (org.voltdb.client.ClientResponse)28 JSONException (org.json_voltpatches.JSONException)9 ExecutionException (java.util.concurrent.ExecutionException)8 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)8 NodeExistsException (org.apache.zookeeper_voltpatches.KeeperException.NodeExistsException)8 JSONObject (org.json_voltpatches.JSONObject)7 IOException (java.io.IOException)6 Client (org.voltdb.client.Client)6 VoltTable (org.voltdb.VoltTable)5 NoConnectionsException (org.voltdb.client.NoConnectionsException)5 Date (java.util.Date)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 ByteBuffer (java.nio.ByteBuffer)2 TreeMap (java.util.TreeMap)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Timestamp (java.sql.Timestamp)1