use of com.aerospike.client.async.EventLoop in project aerospike-client-java by aerospike.
the class Main method doAsyncInserts.
private void doAsyncInserts(AerospikeClient client) throws Exception {
// Generate asyncMaxCommand writes to seed the event loops.
// Then start a new command in each command callback.
// This effectively throttles new command generation, by only allowing
// asyncMaxCommands at any point in time.
long maxConcurrentCommands = this.asyncMaxCommands;
if (maxConcurrentCommands > this.nKeys) {
maxConcurrentCommands = this.nKeys;
}
long keysPerCommand = this.nKeys / maxConcurrentCommands;
long keysRem = this.nKeys - (keysPerCommand * maxConcurrentCommands);
long keyStart = this.startKey;
for (int i = 0; i < maxConcurrentCommands; i++) {
// Allocate separate tasks for each seed command and reuse them in callbacks.
long keyCount = (i < keysRem) ? keysPerCommand + 1 : keysPerCommand;
// Start seed commands on random event loops.
EventLoop eventLoop = this.eventLoops.next();
InsertTaskAsync task = new InsertTaskAsync(client, eventLoop, args, counters, keyStart, keyCount);
task.runCommand();
keyStart += keyCount;
}
Thread.sleep(900);
collectInsertStats();
}
use of com.aerospike.client.async.EventLoop in project aerospike-client-java by aerospike.
the class Main method doAsyncRWTest.
private void doAsyncRWTest(AerospikeClient client) throws Exception {
// Generate asyncMaxCommand commands to seed the event loops.
// Then start a new command in each command callback.
// This effectively throttles new command generation, by only allowing
// asyncMaxCommands at any point in time.
int maxConcurrentCommands = this.asyncMaxCommands;
if (maxConcurrentCommands > this.nKeys) {
maxConcurrentCommands = (int) this.nKeys;
}
RWTask[] tasks = new RWTask[maxConcurrentCommands];
for (int i = 0; i < maxConcurrentCommands; i++) {
// Start seed commands on random event loops.
EventLoop eventLoop = this.clientPolicy.eventLoops.next();
RWTaskAsync task = new RWTaskAsync(client, eventLoop, args, counters, this.startKey, this.nKeys);
task.runNextCommand();
}
Thread.sleep(900);
collectRWStats(tasks);
}
use of com.aerospike.client.async.EventLoop in project aerospike-client-java by aerospike.
the class AsyncExample method runExamples.
/**
* Connect and run one or more asynchronous client examples.
*/
public static void runExamples(Console console, Parameters params, List<String> examples) throws Exception {
EventPolicy eventPolicy = new EventPolicy();
eventPolicy.maxCommandsInProcess = params.maxCommandsInProcess;
eventPolicy.maxCommandsInQueue = params.maxCommandsInQueue;
EventLoops eventLoops;
switch(params.eventLoopType) {
default:
case DIRECT_NIO:
{
eventLoops = new NioEventLoops(eventPolicy, 1);
break;
}
case NETTY_NIO:
{
EventLoopGroup group = new NioEventLoopGroup(1);
eventLoops = new NettyEventLoops(eventPolicy, group);
break;
}
case NETTY_EPOLL:
{
EventLoopGroup group = new EpollEventLoopGroup(1);
eventLoops = new NettyEventLoops(eventPolicy, group);
break;
}
}
try {
ClientPolicy policy = new ClientPolicy();
policy.eventLoops = eventLoops;
policy.user = params.user;
policy.password = params.password;
policy.tlsPolicy = params.tlsPolicy;
params.policy = policy.readPolicyDefault;
params.writePolicy = policy.writePolicyDefault;
Host[] hosts = Host.parseHosts(params.host, params.port);
AerospikeClient client = new AerospikeClient(policy, hosts);
try {
EventLoop eventLoop = eventLoops.get(0);
params.setServerSpecific(client);
for (String exampleName : examples) {
runExample(exampleName, client, eventLoop, params, console);
}
} finally {
client.close();
}
} finally {
eventLoops.close();
}
}
Aggregations