milvus-sdk-java icon indicating copy to clipboard operation
milvus-sdk-java copied to clipboard

MilvusClientV2Pool.getClient is null sometimes when using client pool

Open dingle66 opened this issue 1 year ago • 2 comments

MilvusClientV2Pool milvusClientV2Pool = new MilvusClientV2Pool(poolConfig, connectConfig); milvusClientV2Pool.getClient is null occurs sometimes!

dingle66 avatar Oct 17 '24 12:10 dingle66

https://github.com/milvus-io/milvus-sdk-java/blob/14b9065db1ac5d0d9359a58ddc6e21565cb3a1ec/src/main/java/io/milvus/pool/ClientPool.java#L47

The ClientPool could return null for getClient() method:

    public T getClient(String key) {
        try {
            return clientPool.borrowObject(key);
        } catch (Exception e) {
            System.out.println("Failed to get client, exception: " + e.getMessage());
            return null;
        }
    }

I didn't throw an exception here, do you think it is necessary to throw the error? In my opinion, when user gets a null value, he can check the returned value and recall the getClient() again.

The client.Pool is a GenericKeyedObjectPool. The borrowObject() method internally has a timeout value to wait for a client to be created. The timeout value can be configured by PoolConfig.maxBlockWaitDuration: https://github.com/milvus-io/milvus-sdk-java/blob/14b9065db1ac5d0d9359a58ddc6e21565cb3a1ec/src/main/java/io/milvus/pool/ClientPool.java#L27

The default value of maxBlockWaitDuration is 3 seconds. Sometimes the client could not be created in 3 seconds, which might caused by network issues or milvus server being too busy to respond. You can increase this value to observe.

yhmo avatar Oct 18 '24 03:10 yhmo

https://github.com/milvus-io/milvus-sdk-java/blob/14b9065db1ac5d0d9359a58ddc6e21565cb3a1ec/src/main/java/io/milvus/pool/ClientPool.java#L47

The ClientPool could return null for getClient() method:

    public T getClient(String key) {
        try {
            return clientPool.borrowObject(key);
        } catch (Exception e) {
            System.out.println("Failed to get client, exception: " + e.getMessage());
            return null;
        }
    }

I didn't throw an exception here, do you think it is necessary to throw the error? In my opinion, when user gets a null value, he can check the returned value and recall the getClient() again.

The client.Pool is a GenericKeyedObjectPool. The borrowObject() method internally has a timeout value to wait for a client to be created. The timeout value can be configured by PoolConfig.maxBlockWaitDuration:

https://github.com/milvus-io/milvus-sdk-java/blob/14b9065db1ac5d0d9359a58ddc6e21565cb3a1ec/src/main/java/io/milvus/pool/ClientPool.java#L27

The default value of maxBlockWaitDuration is 3 seconds. Sometimes the client could not be created in 3 seconds, which might caused by network issues or milvus server being too busy to respond. You can increase this value to observe.

I think the right thing is to throw error. For all java users, exceptions is the only thing need to be handled and return null doesn't really make sense to me

xiaofan-luan avatar Oct 21 '24 16:10 xiaofan-luan

Fixed by this pr: https://github.com/milvus-io/milvus-sdk-java/pull/1170/files The exception thrown from GenericKeyedObjectPool is encapsulated by MilvusClientException and thrown out to users.

yhmo avatar Nov 05 '24 02:11 yhmo

The fix has been released with v2.4.9 and v2.5.0

yhmo avatar Nov 27 '24 02:11 yhmo