turcsanyip commented on code in PR #6158:
URL: https://github.com/apache/nifi/pull/6158#discussion_r929289682


##########
nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/processors/azure/storage/utils/StorageClientFactory.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.azure.storage.utils;
+
+import com.azure.core.credential.AccessToken;
+import com.azure.core.credential.TokenCredential;
+import com.azure.core.http.HttpClient;
+import com.azure.core.http.ProxyOptions;
+import com.azure.core.http.netty.NettyAsyncHttpClientBuilder;
+import com.azure.identity.ClientSecretCredential;
+import com.azure.identity.ClientSecretCredentialBuilder;
+import com.azure.identity.ManagedIdentityCredential;
+import com.azure.identity.ManagedIdentityCredentialBuilder;
+import com.azure.storage.common.StorageSharedKeyCredential;
+import com.azure.storage.file.datalake.DataLakeServiceClient;
+import com.azure.storage.file.datalake.DataLakeServiceClientBuilder;
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.services.azure.storage.ADLSCredentialsDetails;
+import reactor.core.publisher.Mono;
+
+public class StorageClientFactory {
+
+    private static final long STORAGE_CLIENT_CACHE_SIZE = 10;
+
+    private final Cache<Integer, DataLakeServiceClient> storageClientCache;
+
+    public StorageClientFactory() {
+        this.storageClientCache = createCache();
+    }
+
+    private Cache<Integer, DataLakeServiceClient> createCache() {
+        return Caffeine.newBuilder()
+                .maximumSize(STORAGE_CLIENT_CACHE_SIZE)
+                .build();
+    }
+
+    public Cache<Integer, DataLakeServiceClient> getCache() {
+        return storageClientCache;
+    }
+
+    /**
+     * Retrieves a {@link DataLakeServiceClient}
+     *
+     * @param proxyOptions not used for caching, because proxy parameters are 
set in the ProxyConfiguration service
+     * @param credentialsDetails used for caching because it can contain 
properties that are results of an expression
+     * @return DataLakeServiceClient
+     */
+    public DataLakeServiceClient getStorageClient(ProxyOptions proxyOptions, 
ADLSCredentialsDetails credentialsDetails) {

Review Comment:
   @jfrazee Do you have any information whether 
`com.azure.storage.file.datalake.DataLakeServiceClient` is thread-safe or not?
   
   Currently, `DataLakeServiceClient` is instantiated/built in every 
`onTrigger()` which leads to some performance loss. It is more relevant when a 
proxy is used (added in 
[NIFI-9951](https://issues.apache.org/jira/browse/NIFI-9951) recently), because 
the new client establishes a new connection to the proxy every time.
   This PR is about caching the `DataLakeServiceClient` between `onTrigger()` 
calls but it is unclear if that client object can be used in parallel or not.
   For the .NET ADLS library the is a clear statement that it is thread-safe:
   
https://docs.microsoft.com/en-us/dotnet/api/overview/azure/storage.files.datalake-readme
   However, we cannot find a similar docs regarding the Java lib.
   
   Could you please check it? Thanks in advance!



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to