Class ClientPool<C,​T>

    • Field Detail

      • logger

        protected static final org.slf4j.Logger logger
      • clientPool

        protected org.apache.commons.pool2.impl.GenericKeyedObjectPool<String,​T> clientPool
    • Method Detail

      • configForKey

        public void configForKey​(String key,
                                 C config)
      • removeConfig

        public void removeConfig​(String key)
      • configKeys

        public Set<String> configKeys()
      • getConfig

        public C getConfig​(String key)
      • preparePool

        public void preparePool​(String key)
        Create minIdlePerKey clients for the pool of the key. Call this method before business can reduce the latency of the first time to getClient().
      • getClient

        public T getClient​(String key)
        Get a client object from the cache. If the cache is empty, it will fetch a client from the underlying pool. The cache maintains a list of clients. The cache will increase the ref-count of this client when it is fetched by getClient(), and decrease the ref-count when it is returned by returnClient(). The cache balances the caller to multiple clients according to the ref-count of each client. getClient() will return the client which has the minimum ref-count to the caller. If the average ref-count of clients is smaller than a threshold, the cache will retire a client which has the maximum ref-count, wait its ref-count to be zero and return it to the underlying pool. If the number of clients hits the MaxTotalPerKey value, this method will be blocked for MaxBlockWaitDuration. If no idle client available after MaxBlockWaitDuration, this method will return a null object to caller.
        Parameters:
        key - the key of a group where the client belong
        Returns:
        MilvusClient or MilvusClientV2
      • returnClient

        public void returnClient​(String key,
                                 T grpcClient)
        Return a client object. Once a client is returned, it becomes idle state and wait the next caller. The caller should ensure the client is returned. Otherwise, the client will keep in active state and cannot be used by the next caller. Throw exceptions if the key doesn't exist or the client is not belong to this key group.
        Parameters:
        key - the key of a group where the client belong
        grpcClient - the client object to return
      • close

        public void close()
        Release/disconnect all clients of all key groups, close the pool.
      • clear

        public void clear()
        Release/disconnect idle clients of all key groups.
      • clear

        public void clear​(String key)
        Release/disconnect idle clients of a key group.
        Parameters:
        key - the key of a group
      • getIdleClientNumber

        public int getIdleClientNumber​(String key)
        Return the number of idle clients of a key group Threadsafe method.
        Parameters:
        key - the key of a group
      • getActiveClientNumber

        public int getActiveClientNumber​(String key)
        Return the number of active clients of a key group Threadsafe method.
        Parameters:
        key - the key of a group
      • getTotalIdleClientNumber

        public int getTotalIdleClientNumber()
        Return the number of idle clients of all key group Threadsafe method.
      • getTotalActiveClientNumber

        public int getTotalActiveClientNumber()
        Return the number of active clients of all key group Threadsafe method.
      • fetchClientPerSecond

        public float fetchClientPerSecond​(String key)