Search in sources :

Example 1 with EventLoop

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();
}
Also used : EventLoop(com.aerospike.client.async.EventLoop)

Example 2 with EventLoop

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);
}
Also used : EventLoop(com.aerospike.client.async.EventLoop)

Example 3 with EventLoop

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();
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) ClientPolicy(com.aerospike.client.policy.ClientPolicy) NioEventLoops(com.aerospike.client.async.NioEventLoops) EventLoops(com.aerospike.client.async.EventLoops) NettyEventLoops(com.aerospike.client.async.NettyEventLoops) EventPolicy(com.aerospike.client.async.EventPolicy) Host(com.aerospike.client.Host) NioEventLoops(com.aerospike.client.async.NioEventLoops) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) EventLoop(com.aerospike.client.async.EventLoop) NettyEventLoops(com.aerospike.client.async.NettyEventLoops) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

EventLoop (com.aerospike.client.async.EventLoop)3 AerospikeClient (com.aerospike.client.AerospikeClient)1 Host (com.aerospike.client.Host)1 EventLoops (com.aerospike.client.async.EventLoops)1 EventPolicy (com.aerospike.client.async.EventPolicy)1 NettyEventLoops (com.aerospike.client.async.NettyEventLoops)1 NioEventLoops (com.aerospike.client.async.NioEventLoops)1 ClientPolicy (com.aerospike.client.policy.ClientPolicy)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1