2017-07-25 131 views
3

我正在使用aeropike異步客戶端執行udf。客戶端已被初始化爲: -Aerospike Java異步庫似乎卡住了

try { 
     asyncClientPolicy.maxThreads = 40; 
     asyncClientPolicy.asyncMaxCommands = 20; 
     asyncClientPolicy.maxSocketIdle = 13; 
     asyncClientPolicy.asyncMaxCommandAction = MaxCommandAction.BLOCK; 
     asyncClientPolicy.asyncSelectorThreads = 7; 
     asyncClientPolicy.asyncTaskThreadPool = Executors.newFixedThreadPool(20, new ThreadFactory() { 
      public final Thread newThread(Runnable runnable) { 
       Thread thread = new Thread(runnable); 
       thread.setDaemon(true); 
       return thread; 
      } 
     }); 
    } 

所以我有20個線程來處理回調。過了一段時間,我發現我的程序沒有取得任何進展,表明僵局/飢餓。 Jstack給了我下面的結果: -

java.lang.Thread.State: WAITING (parking) 
    at sun.misc.Unsafe.park(Native Method) 
    - parking to wait for <0x000000064048f338> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) 
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) 
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043) 
    at java.util.concurrent.ArrayBlockingQueue.take(ArrayBlockingQueue.java:374) 
    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.AsyncClient.execute(AsyncClient.java:949) 
    at main.java.labs.RuleEngineAerospikeConnection.updatePositiveSegmentsUDF(RuleEngineAerospikeConnection.java:217) 
    at main.java.labs.Segment$ProductChecker.onSuccess(Segment.java:346) 
    at com.aerospike.client.async.AsyncRead.onSuccess(AsyncRead.java:149) 
    at com.aerospike.client.async.AsyncCommand.finish(AsyncCommand.java:293) 
    at com.aerospike.client.async.AsyncSingleCommand.read(AsyncSingleCommand.java:59) 
    at com.aerospike.client.async.AsyncCommand.run(AsyncCommand.java:261) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:745) 

我在等待狀態都在execute命令正好20個線程。我是否做了錯誤的設置,因爲我期望客戶端返回,即使在我的UDF中有任何異常,如果有無限循環會發生什麼?它會導致這種行爲嗎?

+0

更改爲同步客戶端解決了問題 –

回答

3

如果沒有查看源代碼,很難說是什麼導致了死鎖。你的AsyncClientPolicy看起來足夠了。

無論如何,自從version 4以來,舊的AsyncClient類已經過時。 AerospikeClient類現在包含新的異步方法,其執行速度必須比舊的AsyncClient快。新的異步方法也支持Netty事件循環,並始終以非阻塞模式運行。

+0

感謝Brian,我會盡力而爲。它看起來像一個錯誤,其中asyncTaskThreadPool正在等待任務到達並阻止執行函數調用。它快速地在4.0中解決。我會盡快更新 –