anurag bhowmick
anurag bhowmick

Reputation: 351

Aerospike Java Async client blocking

I am trying to use the async java client for async read. I am referring to the example mentioned in http://www.aerospike.com/docs/client/java/usage/async

I am using below get for read get(BatchPolicy policy, RecordArrayListener listener, Key[] keys)

This works fine with few requests, however after making almost ~50000 requests, the threads go into an indefinite wait state. Below is the stack trace for one of the threads.

"pool-11-thread-1" - Thread t@56
   java.lang.Thread.State: WAITING
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for <737890e3> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
    at java.util.concurrent.ArrayBlockingQueue.take(ArrayBlockingQueue.java:403)
    at com.aerospike.client.async.AsyncCluster$BlockBufferQueue.getByteBuffer(AsyncCluster.java:114)
    at com.aerospike.client.async.AsyncCluster.getByteBuffer(AsyncCluster.java:68)
    at com.aerospike.client.async.AsyncCommand.execute(AsyncCommand.java:59)
    at com.aerospike.client.async.AsyncMul    tiExecutor.execute(AsyncMultiExecutor.java:36)
    at com.aerospike.client.async.AsyncBatch$GetArrayExecutor.<init>(AsyncBatch.java:249)
    at com.aerospike.client.async.AsyncClient.get(AsyncClient.java:568)

Can anyone suggest why this might me happening or how to prevent this.

Upvotes: 2

Views: 552

Answers (1)

Meher
Meher

Reputation: 2939

The async client can deadlock when nested async commands are issued. To fix deadlock, define a task thread pool which offloads the async callback (onSuccess()) to a thread pool which frees up the selector thread to process other commands. Here is an example:

AsyncClientPolicy policy = new AsyncClientPolicy();
policy.asyncTaskThreadPool = Executors.newCachedThreadPool(new ThreadFactory() {
        public final Thread newThread(Runnable runnable) {
            Thread thread = new Thread(runnable);
            thread.setDaemon(true);
            return thread;
        }
    });
AsyncClient client = new AsyncClient(policy, host, port);

See online docs at https://github.com/citrusleaf/aerospike-client-java/blob/master/client/src/com/aerospike/client/async/AsyncClientPolicy.java

Upvotes: 1

Related Questions