GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing docs.voltdb.com — 5.3. Calling Procedures Guide to Performance and Customization5.3. Calling ProceduresOnce the application connects to the database you are ready to make procedure calls. At its simplest, you can make a synchronous call that returns the traditional response object: ClientResponse resp = client.callProcedureSync("AddUser", username, password);However, asynchronous calls are where the new Client2 excels. Asynchronous calls return a CompletableFuture (a standard Java object) which can then be used to process the response. For example, you can assign different actions based on the results of the call: CompletableFuture<ClientResponse> addUserCB;
addUserCB = client.callProcedure("AddUser",username,password);
addUserCB.whenComplete( (resp,th) -> processResponse( resp ) );Alternately, it is possible to hand off the response to a processing thread: client.callProcedureAsync("AddUser", username, password)
.thenAcceptAsync((resp) -> processResponse(resp))
.exceptionally((th) -> processException(th));5.3.1. Handling BackpressureThe Client2 interface improves the handling of backpressure; that is, when requests are submitted faster than they can be processed. It is possible for an application to submit requests faster than the client API or the VoltDB server can handle them, particularly when using asynchronous calls. To handle this situation, the API tracks all pending requests: this includes requests queued in the API, requests in the network layer, and requests sent to the VoltDB cluster but which have not been completed yet. The application can configure three limits on the number of requests pending in the client:
Additionally, there is a configurable limit on the number of transactions that can be outstanding at the VoltDB cluster, set using .outstandingTransactionLimit. For example: config.clientRequestBackpressureWarning(2500, 1000)
.clientRequestLimit(3000)
.outstandingTransactionLimit(1000);This example defines the following rules:
Notifications for the high and low watermarks are delivered to the application via a callback defined as part of the client configuration with the .requestBackpressureHandler() method: config.requestBackpressureHandler(myQueueWarning); If you want to provide additional context to the event handler, you can define the callback as a local function within a class and use the "this::" syntax, so the callback has access to any context available to the class: config.requestBackpressureHandler(this::myBackpressureHandler); The callback itself identifies the particular condition by way of a boolean argument it receives. For example: void myQueueWarning (boolean watermark) {
if(watermark) { // high watermark
[ ... ]
} else { // low watermark
[ ... ]
}
}The argument is true when the request count has risen above the high watermark and false when it subsequently drops below the low watermark. The client interface handles reaching the server limit internally. Once the server limit is reached, calls are queued locally until the high watermark is reached. Therefore, in the preceding example, the application can have a total of up to 2000 calls (3000 - 1000) pending transmission before the client refuses to queue any more. 5.3.2. Handling Request TimeoutsThere are configurable limits for how long a request can be queued before it "times out". Requests can time out at the client before being sent to the server or after being sent. The error responses generated for these cases each have distinct status codes, allowing the application to easily identify each failure condition. 5.3.3. Defining Options on a Per-Call BasisSome invocation attributes defined in the configuration by Client2Config can be overridden on a per-call basis by means of an options object. You create a new option object with Client2CallOptions, then apply it to a procedure call as the first argument. For example, the following code sets a call-specific timeout of 1,234 microseconds: Client2CallOptions opts = new Client2CallOptions()
.clientTimeout(1234, TimeUnit.MICROSECONDS);
addUserCB = callProcedureAsync(opts, "AddUser", username, password);Options that are not specified in Client2CallOptions are defined by the configuration settings (or their defaults), so the interface is extensible without forcing application code changes. |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |