diff options
author | Carson Labrado <clabrado@google.com> | 2022-03-23 21:50:15 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-05-11 19:33:50 +0300 |
commit | f52c03c1bc89590965720664567381cc74a3cefc (patch) | |
tree | ceb3baa07da50457a3642729b0077244489703e9 /redfish-core/include | |
parent | d01e32c3786f2fbbb70c9724a87cf979b4a06232 (diff) | |
download | bmcweb-f52c03c1bc89590965720664567381cc74a3cefc.tar.xz |
Refactor HttpClient Class
Refactors HttpClient with the following changes:
- Convert class to singleton
- Replace circular buffers with devectors
- Sending queued requests and closing connections handled
within their own callback
- Add connection pooling (max size 4)
- HttpClient supports multiple connections to multiple clients
- Retry policies can be set for specific use cases
Also modifies its use in the Subscription class to be compatible
with the refactored code.
It is assumed that a BMC will be able to handle 4 parallel
connections and thus the max pool size is set as 4. The max
number of queued messages was left unchanged at 50. Eventually
we may want to allow tuning of these limits to boost performance.
That would come in a future patch.
Tested:
Launched two Event Listener servers that created 6 and 2
subscriptions. Sending a test event created a connection pool
for each server. 4 and 2 connections were added to each pool,
respectively and were used to send the test request. For the first
pool the 2 extra requests were placed into a queue until
connections became available. After a request completed, its
associated connection was used to send the next request in
the queue. Resending the test event caused those prior connections
to be reused instead of new connections being added to the pools.
Signed-off-by: Carson Labrado <clabrado@google.com>
Change-Id: Iba72b3e342cdc05d1fb972e2e9856763a0a1b3c5
Diffstat (limited to 'redfish-core/include')
-rw-r--r-- | redfish-core/include/event_service_manager.hpp | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp index bc5af85060..58bf25786f 100644 --- a/redfish-core/include/event_service_manager.hpp +++ b/redfish-core/include/event_service_manager.hpp @@ -381,7 +381,7 @@ class Subscription : public persistent_data::UserSubscription ~Subscription() = default; - bool sendEvent(const std::string& msg) + bool sendEvent(std::string& msg) { persistent_data::EventServiceConfig eventServiceConfig = persistent_data::EventServiceStore::getInstance() @@ -391,15 +391,9 @@ class Subscription : public persistent_data::UserSubscription return false; } - if (conn == nullptr) - { - // create the HttpClient connection - conn = std::make_shared<crow::HttpClient>( - crow::connections::systemBus->get_io_context(), id, host, port, - path, httpHeaders); - } - - conn->sendData(msg); + // A connection pool will be created if one does not already exist + crow::HttpClient::getInstance().sendData(msg, id, host, port, path, + httpHeaders, retryPolicyName); eventSeqNum++; if (sseConn != nullptr) @@ -430,8 +424,9 @@ class Subscription : public persistent_data::UserSubscription {"Name", "Event Log"}, {"Events", logEntryArray}}; - return this->sendEvent( - msg.dump(2, ' ', true, nlohmann::json::error_handler_t::replace)); + std::string strMsg = + msg.dump(2, ' ', true, nlohmann::json::error_handler_t::replace); + return this->sendEvent(strMsg); } #ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES @@ -497,8 +492,9 @@ class Subscription : public persistent_data::UserSubscription {"Name", "Event Log"}, {"Events", logEntryArray}}; - this->sendEvent( - msg.dump(2, ' ', true, nlohmann::json::error_handler_t::replace)); + std::string strMsg = + msg.dump(2, ' ', true, nlohmann::json::error_handler_t::replace); + this->sendEvent(strMsg); } #endif @@ -529,25 +525,22 @@ class Subscription : public persistent_data::UserSubscription return; } - this->sendEvent( - msg.dump(2, ' ', true, nlohmann::json::error_handler_t::replace)); + std::string strMsg = + msg.dump(2, ' ', true, nlohmann::json::error_handler_t::replace); + this->sendEvent(strMsg); } void updateRetryConfig(const uint32_t retryAttempts, const uint32_t retryTimeoutInterval) { - if (conn != nullptr) - { - conn->setRetryConfig(retryAttempts, retryTimeoutInterval); - } + crow::HttpClient::getInstance().setRetryConfig( + retryAttempts, retryTimeoutInterval, retryPolicyName); } void updateRetryPolicy() { - if (conn != nullptr) - { - conn->setRetryPolicy(retryPolicy); - } + crow::HttpClient::getInstance().setRetryPolicy(retryPolicy, + retryPolicyName); } uint64_t getEventSeqNum() const @@ -561,8 +554,8 @@ class Subscription : public persistent_data::UserSubscription uint16_t port = 0; std::string path; std::string uriProto; - std::shared_ptr<crow::HttpClient> conn = nullptr; std::shared_ptr<crow::ServerSentEvents> sseConn = nullptr; + std::string retryPolicyName = "SubscriptionEvent"; }; class EventServiceManager @@ -1040,8 +1033,10 @@ class EventServiceManager {"Name", "Event Log"}, {"Id", eventId}, {"Events", eventRecord}}; - entry->sendEvent(msgJson.dump( - 2, ' ', true, nlohmann::json::error_handler_t::replace)); + + std::string strMsg = msgJson.dump( + 2, ' ', true, nlohmann::json::error_handler_t::replace); + entry->sendEvent(strMsg); eventId++; // increament the eventId } else @@ -1060,8 +1055,10 @@ class EventServiceManager {"OriginOfCondition", "/ibm/v1/HMC/BroadcastService"}, {"Name", "Broadcast Message"}, {"Message", broadcastMsg}}; - entry->sendEvent(msgJson.dump( - 2, ' ', true, nlohmann::json::error_handler_t::replace)); + + std::string strMsg = msgJson.dump( + 2, ' ', true, nlohmann::json::error_handler_t::replace); + entry->sendEvent(strMsg); } } |