You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2021/05/25 16:41:57 UTC

[celix] branch feature/use_async_api_for_rsa updated: Makes the use of curl share handle configurable for RSA DFI.

This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch feature/use_async_api_for_rsa
in repository https://gitbox.apache.org/repos/asf/celix.git


The following commit(s) were added to refs/heads/feature/use_async_api_for_rsa by this push:
     new d9129a7  Makes the use of curl share handle configurable for RSA DFI.
d9129a7 is described below

commit d9129a793b03a8c889e174edfb9b91ce13114517
Author: Pepijn Noltes <pe...@gmail.com>
AuthorDate: Tue May 25 18:41:43 2021 +0200

    Makes the use of curl share handle configurable for RSA DFI.
---
 .../remote_service_admin_dfi/README.md             |  7 ++++++-
 .../gtest/src/rsa_client_server_tests.cc           | 24 ++++++++++++++++++++--
 .../src/remote_service_admin_dfi.c                 |  8 ++++++--
 .../src/remote_service_admin_dfi_constants.h       | 17 ++++++++++++---
 4 files changed, 48 insertions(+), 8 deletions(-)

diff --git a/bundles/remote_services/remote_service_admin_dfi/README.md b/bundles/remote_services/remote_service_admin_dfi/README.md
index 06082b1..e1db893 100644
--- a/bundles/remote_services/remote_service_admin_dfi/README.md
+++ b/bundles/remote_services/remote_service_admin_dfi/README.md
@@ -31,7 +31,12 @@ Libffi is configured using descriptor files in the bundles.
     RSA_INTERFACE               If specified, the ip adress of interface (i.g. eth0) will be used.
     
     RSA_LOG_CALLS              If set to true, the RSA will Log calls info (including serialized data) to the file in RSA_LOG_CALLS_FILE. Default is false.
-    RSA_LOG_CALLS_FILE         If RSA_LOG_CALLS is enabled to file to log to (starting rsa will truncate file). Default is stdout.          
+    RSA_LOG_CALLS_FILE         If RSA_LOG_CALLS is enabled to file to log to (starting rsa will truncate file). Default is stdout.   
+
+    RSA_DFI_USE_CURL_SHARE_HANDLE   If set to true the RSA will use curl's share handle. 
+                                    The curl share handle has a significant performance boost by sharing DNS, COOKIE en CONNECTIONS over multiple calls, 
+                                    but can also introduce some issues (based on experience).
+                                    Default is false
 
 ###### CMake option
     RSA_REMOTE_SERVICE_ADMIN_DFI=ON
diff --git a/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_client_server_tests.cc b/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_client_server_tests.cc
index 32f1dd9..a47e3ed 100644
--- a/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_client_server_tests.cc
+++ b/bundles/remote_services/remote_service_admin_dfi/gtest/src/rsa_client_server_tests.cc
@@ -41,7 +41,7 @@ extern "C" {
     static celix_framework_t *clientFramework = NULL;
     static celix_bundle_context_t *clientContext = NULL;
 
-    static void setupFm(void) {
+    static void setupFm(bool useCurlShare) {
         //server
         celix_properties_t *serverProps = celix_properties_load("server.properties");
         ASSERT_TRUE(serverProps != NULL);
@@ -52,6 +52,7 @@ extern "C" {
 
         //client
         celix_properties_t *clientProperties = celix_properties_load("client.properties");
+        celix_properties_setBool(clientProperties, "RSA_DFI_USE_CURL_SHARE_HANDLE", useCurlShare);
         ASSERT_TRUE(clientProperties != NULL);
         clientFramework = celix_frameworkFactory_createFramework(clientProperties);
         ASSERT_TRUE(clientFramework != NULL);
@@ -164,7 +165,7 @@ static void test(F&& f) {
 class RsaDfiClientServerTests : public ::testing::Test {
 public:
     RsaDfiClientServerTests() {
-        setupFm();
+        setupFm(false);
     }
     ~RsaDfiClientServerTests() override {
         teardownFm();
@@ -172,15 +173,34 @@ public:
 
 };
 
+class RsaDfiClientServerWithCurlShareTests : public ::testing::Test {
+public:
+    RsaDfiClientServerWithCurlShareTests() {
+        setupFm(true);
+    }
+    ~RsaDfiClientServerWithCurlShareTests() override {
+        teardownFm();
+    }
+
+};
+
 
 TEST_F(RsaDfiClientServerTests, TestRemoteCalculator) {
     test(testCalculator);
 }
 
+TEST_F(RsaDfiClientServerWithCurlShareTests, TestRemoteCalculator) {
+    test(testCalculator);
+}
+
 TEST_F(RsaDfiClientServerTests, TestRemoteComplex) {
     test(testComplex);
 }
 
+TEST_F(RsaDfiClientServerWithCurlShareTests, TestRemoteComplex) {
+    test(testComplex);
+}
+
 TEST_F(RsaDfiClientServerTests, TestRemoteNumbers) {
     test(testNumbers);
 }
diff --git a/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c b/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c
index cbfc9a0..ced1a08 100644
--- a/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c
+++ b/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c
@@ -91,6 +91,8 @@ struct remote_service_admin {
     struct mg_context *ctx;
 
     FILE *logFile;
+
+    bool curlShareEnabled;
     void *curlShare;
     pthread_mutex_t curlMutexConnect;
     pthread_mutex_t curlMutexCookie;
@@ -200,6 +202,7 @@ celix_status_t remoteServiceAdmin_create(celix_bundle_context_t *context, remote
         long port = celix_bundleContext_getPropertyAsLong(context, RSA_PORT_KEY, RSA_PORT_DEFAULT);
         const char *ip = celix_bundleContext_getProperty(context, RSA_IP_KEY, RSA_IP_DEFAULT);
         const char *interface = celix_bundleContext_getProperty(context, RSA_INTERFACE_KEY, NULL);
+        (*admin)->curlShareEnabled = celix_bundleContext_getPropertyAsBool(context, RSA_DFI_USE_CURL_SHARE_HANDLE, RSA_DFI_USE_CURL_SHARE_HANDLE_DEFAULT);
 
         char *detectedIp = NULL;
         if ((interface != NULL) && (remoteServiceAdmin_getIpAddress((char*)interface, &detectedIp) != CELIX_SUCCESS)) {
@@ -946,8 +949,9 @@ static celix_status_t remoteServiceAdmin_send(void *handle, endpoint_description
         curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, remoteServiceAdmin_write);
         curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&get);
         curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)post.size);
-        curl_easy_setopt(curl, CURLOPT_SHARE, rsa->curlShare);
-        //celix_logHelper_log(rsa->loghelper, CELIX_LOG_LEVEL_DEBUG, "RSA: Performing curl post\n");
+        if (rsa->curlShareEnabled) {
+            curl_easy_setopt(curl, CURLOPT_SHARE, rsa->curlShare);
+        }
         res = curl_easy_perform(curl);
 
         fputc('\0', get.stream);
diff --git a/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi_constants.h b/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi_constants.h
index ceabf13..1f31702 100644
--- a/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi_constants.h
+++ b/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi_constants.h
@@ -33,12 +33,23 @@
 #define RSA_LOG_CALLS_FILE_KEY          "RSA_LOG_CALLS_FILE"
 #define RSA_LOG_CALLS_FILE_DEFAULT      "stdout"
 
-
-
-
 #define RSA_DFI_CONFIGURATION_TYPE      "org.amdatu.remote.admin.http"
 #define RSA_DFI_ENDPOINT_URL            "org.amdatu.remote.admin.http.url"
 
+/**
+ * @brief Remote Service Admin DFI environment property (named "RSA_DFI_USE_CURL_SHARE_HANDLE") which specified
+ * whether the RSA DFI should use curl's share handle.
+ *
+ * The curl share handle has a significant performance boost by sharing DNS, COOKIE en CONNECTIONS over multiple calls,
+ * but can also introduce some issues (based on experience)
+ *
+ * The property is of the type boolean and the default is false
+ */
+#define RSA_DFI_USE_CURL_SHARE_HANDLE           "RSA_DFI_USE_CURL_SHARE_HANDLE"
 
+/**
+ * @brief Default value for the enviroment property RSA_DFI_USE_CURL_SHARE_HANDLE
+ */
+#define RSA_DFI_USE_CURL_SHARE_HANDLE_DEFAULT   false
 
 #endif //CELIX_REMOTE_SERVICE_ADMIN_DFI_CONSTANTS_H