You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2019/09/16 22:13:19 UTC

[GitHub] [accumulo] lbschanno commented on issue #1122: Make thrift transport pool more concurrent

lbschanno commented on issue #1122: Make thrift transport pool more concurrent
URL: https://github.com/apache/accumulo/issues/1122#issuecomment-531978744
 
 
   @keith-turner I've been playing around with a couple of different approaches to this. One possible approach is using a separate ConcurrentHashMap of ThriftTransportKeys to ReentrantLocks to support key-pair granularity when fetching and modifying the connections for a particular tserver. The following example shows how the synchronized block is removed from `ThriftTransportKeys.getTransport()`. 
   
   ```java
   public class ThriftTransportPool {
     
     private ConcurrentHashMap<ThriftTransportKey, CachedConnections> cache = new ConcurrentHashMap<>();
     private ConcurrentHashMap<ThriftTransportKey, ReentrantLock> locks = new ConcurrentHashMap<>();
     
     private ReentrantLock getLock(final ThriftTransportKey key) {
       return locks.computeIfAbsent(key, k -> new ReentrantLock());
     }
     
     private TTransport getTransport(ThriftTransportKey cacheKey) throws TTransportException {
       // compute hash code outside of lock, this lowers the time the lock is held
       cacheKey.precomputeHashCode();
       
       Lock lock = getLock(cacheKey);
       lock.lock();
       
       try {
         // atomically reserve location if it exist in cache
         CachedConnection cachedConnection =
             getCache().computeIfAbsent(cacheKey, ck -> new CachedConnections()).reserveAny();
         if (cachedConnection != null) {
           log.trace("Using existing connection to {}", cacheKey.getServer());
           return cachedConnection.transport;
         }
       } finally {
         lock.unlock();
       }
   
       return createNewTransport(cacheKey);
     }
   }
   ```
   
   But before I go too far down this path, I wanted to check if you see any issues with this approach. 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services