From 2eac0249063c7763266e581664134a48dff5b149 Mon Sep 17 00:00:00 2001 From: Dominik Durner Date: Wed, 27 Mar 2024 09:04:34 +0100 Subject: [PATCH] Updated naming of resolver to cache -> prepare to merge fd and dns cache --- example/benchmark/src/benchmark/bandwidth.cpp | 4 +- example/simple/main.cpp | 4 +- include/cloud/aws.hpp | 4 +- .../cloud/{aws_resolver.hpp => aws_cache.hpp} | 10 +-- include/cloud/provider.hpp | 4 +- include/network/{resolver.hpp => cache.hpp} | 6 +- include/network/connection_manager.hpp | 21 ++++-- include/network/tasked_send_receiver.hpp | 6 +- ...hput_resolver.hpp => throughput_cache.hpp} | 14 ++-- src/cloud/aws.cpp | 8 +-- src/cloud/{aws_resolver.cpp => aws_cache.cpp} | 8 +-- src/cloud/azure.cpp | 2 +- src/cloud/gcp.cpp | 2 +- src/network/{resolver.cpp => cache.cpp} | 8 +-- src/network/connection_manager.cpp | 64 ++++++++++++------- src/network/tasked_send_receiver.cpp | 6 +- ...hput_resolver.cpp => throughput_cache.cpp} | 12 ++-- test/unit/network/io_uring_socket_test.cpp | 2 +- test/unit/network/resolver_test.cpp | 4 +- 19 files changed, 109 insertions(+), 80 deletions(-) rename include/cloud/{aws_resolver.hpp => aws_cache.hpp} (84%) rename include/network/{resolver.hpp => cache.hpp} (95%) rename include/network/{throughput_resolver.hpp => throughput_cache.hpp} (84%) rename src/cloud/{aws_resolver.cpp => aws_cache.cpp} (92%) rename src/network/{resolver.cpp => cache.cpp} (92%) rename src/network/{throughput_resolver.cpp => throughput_cache.cpp} (90%) diff --git a/example/benchmark/src/benchmark/bandwidth.cpp b/example/benchmark/src/benchmark/bandwidth.cpp index 38ede04..3568803 100644 --- a/example/benchmark/src/benchmark/bandwidth.cpp +++ b/example/benchmark/src/benchmark/bandwidth.cpp @@ -1,6 +1,6 @@ #include "benchmark/bandwidth.hpp" #include "cloud/aws.hpp" -#include "cloud/aws_resolver.hpp" +#include "cloud/aws_cache.hpp" #include "cloud/azure.hpp" #include "cloud/gcp.hpp" #include "network/original_message.hpp" @@ -172,7 +172,7 @@ void Bandwidth::runUring(const Settings& benchmarkSettings, const string& uri) auto awsProvider = static_cast(cloudProvider.get()); if (!benchmarkSettings.resolver.compare("aws")) { for (auto i = 0u; i < benchmarkSettings.concurrentThreads; i++) { - awsProvider->initResolver(*sendReceiverHandles[i].get()); + awsProvider->initCache(*sendReceiverHandles[i].get()); } } } diff --git a/example/simple/main.cpp b/example/simple/main.cpp index bf500f1..e119740 100644 --- a/example/simple/main.cpp +++ b/example/simple/main.cpp @@ -28,8 +28,8 @@ int main(int /*argc*/, char** /*argv*/) { bool https = false; auto provider = anyblob::cloud::Provider::makeProvider(bucketName, https, "", "", &sendReceiverHandle); - // Optionally init the specialized aws resolver - // provider->initResolver(sendReceiverHandle); + // Optionally init the specialized aws cache + // provider->initCache(sendReceiverHandle); // Update the concurrency according to instance settings auto config = provider->getConfig(sendReceiverHandle); diff --git a/include/cloud/aws.hpp b/include/cloud/aws.hpp index 066b8cb..e33d678 100644 --- a/include/cloud/aws.hpp +++ b/include/cloud/aws.hpp @@ -84,8 +84,8 @@ class AWS : public Provider { [[nodiscard]] Provider::Instance getInstanceDetails(network::TaskedSendReceiverHandle& sendReceiver) override; /// Get the region of the instance [[nodiscard]] static std::string getInstanceRegion(network::TaskedSendReceiverHandle& sendReceiver); - /// Init the resolver - void initResolver(network::TaskedSendReceiverHandle& sendReceiverHandle) override; + /// Init the Cache + void initCache(network::TaskedSendReceiverHandle& sendReceiverHandle) override; /// The constructor explicit AWS(const RemoteInfo& info) : _settings({info.bucket, info.region, info.endpoint, info.port, info.zonal}), _mutex() { diff --git a/include/cloud/aws_resolver.hpp b/include/cloud/aws_cache.hpp similarity index 84% rename from include/cloud/aws_resolver.hpp rename to include/cloud/aws_cache.hpp index bd2c26f..4ded03c 100644 --- a/include/cloud/aws_resolver.hpp +++ b/include/cloud/aws_cache.hpp @@ -1,5 +1,5 @@ #pragma once -#include "network/resolver.hpp" +#include "network/cache.hpp" #include //--------------------------------------------------------------------------- // AnyBlob - Universal Cloud Object Storage Library @@ -13,18 +13,18 @@ namespace anyblob { //--------------------------------------------------------------------------- namespace cloud { //--------------------------------------------------------------------------- -/// Implements the AWS resolver logic -class AWSResolver : public network::Resolver { +/// Implements the AWS cache logic +class AWSCache : public network::Cache { /// The good mtu cache std::unordered_map _mtuCache; public: /// The constructor - explicit AWSResolver(unsigned cacheEntries); + explicit AWSCache(unsigned cacheEntries); /// The address resolving virtual const addrinfo* resolve(std::string hostname, std::string port, bool& reuse) override; /// The destructor - virtual ~AWSResolver() noexcept = default; + virtual ~AWSCache() noexcept = default; }; //--------------------------------------------------------------------------- }; // namespace cloud diff --git a/include/cloud/provider.hpp b/include/cloud/provider.hpp index b8d33c2..da34c12 100644 --- a/include/cloud/provider.hpp +++ b/include/cloud/provider.hpp @@ -135,8 +135,8 @@ class Provider { /// Create a provider (keyId is access email for GCP/Azure) [[nodiscard]] static std::unique_ptr makeProvider(const std::string& filepath, bool https = false, const std::string& keyId = "", const std::string& keyFile = "", network::TaskedSendReceiverHandle* sendReceiverHandle = nullptr); - /// Init the resolver for specific provider - virtual void initResolver(network::TaskedSendReceiverHandle& /*sendReceiverHandle*/) {} + /// Init the cache for specific provider + virtual void initCache(network::TaskedSendReceiverHandle& /*sendReceiverHandle*/) {} /// Get the instance infos [[nodiscard]] virtual Instance getInstanceDetails(network::TaskedSendReceiverHandle& sendReceiverHandle) = 0; /// Get the config diff --git a/include/network/resolver.hpp b/include/network/cache.hpp similarity index 95% rename from include/network/resolver.hpp rename to include/network/cache.hpp index 4928f19..92e2950 100644 --- a/include/network/resolver.hpp +++ b/include/network/cache.hpp @@ -20,7 +20,7 @@ namespace network { class IOUringSocket; //--------------------------------------------------------------------------- /// The addr resolver and cacher, which is not thread safe -class Resolver { +class Cache { protected: /// The addr info std::vector> _addr; @@ -31,7 +31,7 @@ class Resolver { public: /// The constructor - explicit Resolver(unsigned entries); + explicit Cache(unsigned entries); /// The address resolving virtual const addrinfo* resolve(std::string hostname, std::string port, bool& oldAddress); /// Reset the current cache bucket @@ -43,7 +43,7 @@ class Resolver { /// Shutdown of the socket should clear the same addresses virtual void shutdownSocket(int /*fd*/) {} /// The destructor - virtual ~Resolver() noexcept = default; + virtual ~Cache() noexcept = default; /// Get the tld static std::string_view tld(std::string_view domain); diff --git a/include/network/connection_manager.hpp b/include/network/connection_manager.hpp index 5a3111e..d65d7be 100644 --- a/include/network/connection_manager.hpp +++ b/include/network/connection_manager.hpp @@ -1,6 +1,7 @@ #pragma once -#include "network/resolver.hpp" +#include "network/cache.hpp" #include +#include #include #include #include @@ -73,6 +74,7 @@ class ConnectionManager { /// The hostname std::string hostname; + /// The constructor SocketEntry(int32_t fd, std::string hostname, unsigned port, std::unique_ptr tls); }; @@ -83,14 +85,21 @@ class ConnectionManager { std::unordered_map> _fdSockets; /// The fd socket cache, uses hostname as key std::unordered_multimap> _fdCache; - /// Resolver - std::unordered_map> _resolverCache; + /// The queue + std::deque _fdQueue; + /// Cache + std::unordered_map> _cache; /// The tls context std::unique_ptr _context; + /// The counter of current connection managers + static std::atomic _activeConnectionManagers; + /// The maximum number of cached fds, TODO: access ulimit for this + constexpr static unsigned _maxCachedFds = 512; + public: /// The constructor - explicit ConnectionManager(unsigned uringEntries, unsigned resolverCacheEntries); + explicit ConnectionManager(unsigned uringEntries, unsigned cacheEntries); /// The destructor ~ConnectionManager(); @@ -99,8 +108,8 @@ class ConnectionManager { /// Disconnects the socket void disconnect(int32_t fd, std::string hostname = "", uint32_t port = 0, const TCPSettings* tcpSettings = nullptr, uint64_t bytes = 0, bool forceShutdown = false); - /// Add resolver - void addResolver(const std::string& hostname, std::unique_ptr resolver); + /// Add domain-specific cache + void addCache(const std::string& hostname, std::unique_ptr cache); /// Checks for a timeout bool checkTimeout(int fd, const TCPSettings& settings); diff --git a/include/network/tasked_send_receiver.hpp b/include/network/tasked_send_receiver.hpp index 86dce24..6759672 100644 --- a/include/network/tasked_send_receiver.hpp +++ b/include/network/tasked_send_receiver.hpp @@ -33,7 +33,7 @@ namespace network { //--------------------------------------------------------------------------- class TaskedSendReceiver; class TaskedSendReceiverHandle; -class Resolver; +class Cache; struct OriginalMessage; //--------------------------------------------------------------------------- /// Shared submission and completions queue with multiple TaskedSendReceivers @@ -125,8 +125,8 @@ class TaskedSendReceiver { public: /// Get the group [[nodiscard]] const TaskedSendReceiverGroup* getGroup() const { return &_group; } - /// Adds a resolver - void addResolver(const std::string& hostname, std::unique_ptr resolver); + /// Adds a domain-specific cache + void addCache(const std::string& hostname, std::unique_ptr cache); /// Process local submissions (should be used for sync requests) inline void processSync(bool oneQueueInvocation = true) { sendReceive(true, oneQueueInvocation); } /// Set the timings diff --git a/include/network/throughput_resolver.hpp b/include/network/throughput_cache.hpp similarity index 84% rename from include/network/throughput_resolver.hpp rename to include/network/throughput_cache.hpp index b8bdb17..35e6493 100644 --- a/include/network/throughput_resolver.hpp +++ b/include/network/throughput_cache.hpp @@ -1,9 +1,9 @@ #pragma once -// The `ThroughputResolver` depends on gnu stdlib associative containers that are -// not supported by libcxx. We remove the throughput resolver in its entirety when +// The `ThroughputCache` depends on gnu stdlib associative containers that are +// not supported by libcxx. We remove the throughput cache in its entirety when // building with libcxx. #ifndef ANYBLOB_LIBCXX_COMPAT -#include "network/resolver.hpp" +#include "network/cache.hpp" #include #include #include @@ -20,8 +20,8 @@ namespace anyblob { //--------------------------------------------------------------------------- namespace network { //--------------------------------------------------------------------------- -/// Implements the AWS Resolver logic -class ThroughputResolver : public network::Resolver { +/// Implements the throughput-based cache logic +class ThroughputCache : public network::Cache { /// Order statistic tree typedef __gnu_pbds::tree< double, @@ -43,7 +43,7 @@ class ThroughputResolver : public network::Resolver { public: /// The constructor - explicit ThroughputResolver(unsigned cacheEntries); + explicit ThroughputCache(unsigned cacheEntries); /// The address resolving virtual const addrinfo* resolve(std::string hostname, std::string port, bool& reuse) override; /// Start the timing @@ -53,7 +53,7 @@ class ThroughputResolver : public network::Resolver { /// Clears the used server from the cache virtual void shutdownSocket(int fd) override; /// The destructor - virtual ~ThroughputResolver() noexcept = default; + virtual ~ThroughputCache() noexcept = default; }; //--------------------------------------------------------------------------- }; // namespace network diff --git a/src/cloud/aws.cpp b/src/cloud/aws.cpp index dbaf033..be2c167 100644 --- a/src/cloud/aws.cpp +++ b/src/cloud/aws.cpp @@ -1,5 +1,5 @@ #include "cloud/aws.hpp" -#include "cloud/aws_resolver.hpp" +#include "cloud/aws_cache.hpp" #include "cloud/http.hpp" #include "network/http_helper.hpp" #include "network/original_message.hpp" @@ -304,12 +304,12 @@ void AWS::getSecret() } } //--------------------------------------------------------------------------- -void AWS::initResolver(network::TaskedSendReceiverHandle& sendReceiverHandle) -// Inits the resolver +void AWS::initCache(network::TaskedSendReceiverHandle& sendReceiverHandle) +// Inits the cache { assert(sendReceiverHandle.get()); if (_type == Provider::CloudService::AWS) { - sendReceiverHandle.get()->addResolver("amazonaws.com", unique_ptr(new cloud::AWSResolver(sendReceiverHandle.getGroup()->getConcurrentRequests()))); + sendReceiverHandle.get()->addCache("amazonaws.com", unique_ptr(new cloud::AWSCache(sendReceiverHandle.getGroup()->getConcurrentRequests()))); } } //--------------------------------------------------------------------------- diff --git a/src/cloud/aws_resolver.cpp b/src/cloud/aws_cache.cpp similarity index 92% rename from src/cloud/aws_resolver.cpp rename to src/cloud/aws_cache.cpp index 0dc79af..fac151c 100644 --- a/src/cloud/aws_resolver.cpp +++ b/src/cloud/aws_cache.cpp @@ -1,4 +1,4 @@ -#include "cloud/aws_resolver.hpp" +#include "cloud/aws_cache.hpp" #include #include #include @@ -18,12 +18,12 @@ namespace cloud { //--------------------------------------------------------------------------- using namespace std; //--------------------------------------------------------------------------- -AWSResolver::AWSResolver(unsigned entries) : Resolver(entries), _mtuCache() +AWSCache::AWSCache(unsigned entries) : Cache(entries), _mtuCache() // Constructor { } //--------------------------------------------------------------------------- -const addrinfo* AWSResolver::resolve(string hostname, string port, bool& oldAddress) +const addrinfo* AWSCache::resolve(string hostname, string port, bool& oldAddress) // Resolve the request { auto addrPos = _addrCtr % static_cast(_addrString.size()); @@ -43,7 +43,7 @@ const addrinfo* AWSResolver::resolve(string hostname, string port, bool& oldAddr throw runtime_error("hostname getaddrinfo error"); } _addr[addrPos].reset(temp); - if (!Resolver::tld(hostname).compare("amazonaws.com")) { + if (!Cache::tld(hostname).compare("amazonaws.com")) { struct sockaddr_in* p = reinterpret_cast(_addr[addrPos]->ai_addr); auto ipAsInt = p->sin_addr.s_addr; auto it = _mtuCache.find(ipAsInt); diff --git a/src/cloud/azure.cpp b/src/cloud/azure.cpp index 4bda1e3..825f544 100644 --- a/src/cloud/azure.cpp +++ b/src/cloud/azure.cpp @@ -3,7 +3,7 @@ #include "cloud/http.hpp" #include "network/http_helper.hpp" #include "network/original_message.hpp" -#include "network/resolver.hpp" +#include "network/cache.hpp" #include "network/tasked_send_receiver.hpp" #include "utils/data_vector.hpp" #include diff --git a/src/cloud/gcp.cpp b/src/cloud/gcp.cpp index e2af3ae..1f7e48b 100644 --- a/src/cloud/gcp.cpp +++ b/src/cloud/gcp.cpp @@ -3,7 +3,7 @@ #include "cloud/gcp_signer.hpp" #include "network/http_helper.hpp" #include "network/original_message.hpp" -#include "network/resolver.hpp" +#include "network/cache.hpp" #include "network/tasked_send_receiver.hpp" #include "utils/data_vector.hpp" #include diff --git a/src/network/resolver.cpp b/src/network/cache.cpp similarity index 92% rename from src/network/resolver.cpp rename to src/network/cache.cpp index 185c8ce..e8f3ce8 100644 --- a/src/network/resolver.cpp +++ b/src/network/cache.cpp @@ -1,4 +1,4 @@ -#include "network/resolver.hpp" +#include "network/cache.hpp" #include #include #include @@ -17,7 +17,7 @@ namespace network { //--------------------------------------------------------------------------- using namespace std; //--------------------------------------------------------------------------- -string_view Resolver::tld(string_view domain) +string_view Cache::tld(string_view domain) // String prefix { auto pos = domain.find_last_of('.'); @@ -31,7 +31,7 @@ string_view Resolver::tld(string_view domain) return string_view(); } //--------------------------------------------------------------------------- -Resolver::Resolver(unsigned entries) +Cache::Cache(unsigned entries) // Constructor { _addr.reserve(entries); @@ -42,7 +42,7 @@ Resolver::Resolver(unsigned entries) _addrCtr = 0; } //--------------------------------------------------------------------------- -const addrinfo* Resolver::resolve(string hostname, string port, bool& oldAddress) +const addrinfo* Cache::resolve(string hostname, string port, bool& oldAddress) // Resolve the request { auto addrPos = _addrCtr % static_cast(_addrString.size()); diff --git a/src/network/connection_manager.cpp b/src/network/connection_manager.cpp index b198e65..eb97d3d 100644 --- a/src/network/connection_manager.cpp +++ b/src/network/connection_manager.cpp @@ -3,8 +3,9 @@ #include "network/tls_connection.hpp" #include "network/tls_context.hpp" #ifndef ANYBLOB_LIBCXX_COMPAT -#include "network/throughput_resolver.hpp" +#include "network/throughput_cache.hpp" #endif +#include #include #include #include @@ -28,22 +29,24 @@ namespace anyblob { namespace network { //--------------------------------------------------------------------------- using namespace std; +std::atomic ConnectionManager::_activeConnectionManagers{0}; //--------------------------------------------------------------------------- ConnectionManager::SocketEntry::SocketEntry(int32_t fd, std::string hostname, unsigned port, std::unique_ptr tls) : tls(move(tls)), fd(fd), port(port), hostname(move(hostname)) // The constructor {} //--------------------------------------------------------------------------- -ConnectionManager::ConnectionManager(unsigned uringEntries, unsigned resolverCacheEntries) : _socketWrapper(make_unique(uringEntries)), _resolverCache() +ConnectionManager::ConnectionManager(unsigned uringEntries, unsigned cacheEntries) : _socketWrapper(make_unique(uringEntries)), _cache() // The constructor { + _activeConnectionManagers++; _context = make_unique(); #ifndef ANYBLOB_LIBCXX_COMPAT - // By default, use the ThroughputResolver. - _resolverCache.emplace("", make_unique(resolverCacheEntries)); + // By default, use the ThroughputCache. + _cache.emplace("", make_unique(cacheEntries)); #else - // If we build in libcxx compatability mode, we need to use the default resolver. - // The ThroughputResolver currently does not build with libcxx. - _resolverCache.emplace("", make_unique(resolverCacheEntries)); + // If we build in libcxx compatability mode, we need to use the default cache. + // The ThroughputCache currently does not build with libcxx. + _cache.emplace("", make_unique(cacheEntries)); #endif } //--------------------------------------------------------------------------- @@ -51,26 +54,32 @@ int32_t ConnectionManager::connect(string hostname, uint32_t port, bool tls, con // Creates a new socket connection { if (useCache) { - for (auto it = _fdCache.find(hostname); it != _fdCache.end(); it++) { + for (auto it = _fdCache.find(hostname); it != _fdCache.end();) { + // loosely clean up the multimap cache + if (it->second->fd < 0) { + it = _fdCache.erase(it); + continue; + } if (it->second->port == port && ((tls && it->second->tls.get()) || (!tls && !it->second->tls.get()))) { auto fd = it->second->fd; _fdSockets.emplace(fd, move(it->second)); _fdCache.erase(it); return fd; } + it++; } } char port_str[16] = {}; sprintf(port_str, "%d", port); - Resolver* resCache; - auto tldName = string(Resolver::tld(hostname)); - auto it = _resolverCache.find(tldName); - if (it != _resolverCache.end()) { + Cache* resCache; + auto tldName = string(Cache::tld(hostname)); + auto it = _cache.find(tldName); + if (it != _cache.end()) { resCache = it->second.get(); } else { - resCache = _resolverCache.find("")->second.get(); + resCache = _cache.find("")->second.get(); } // Did we use @@ -265,13 +274,13 @@ int32_t ConnectionManager::connect(string hostname, uint32_t port, bool tls, con void ConnectionManager::disconnect(int32_t fd, string hostname, uint32_t port, const TCPSettings* tcpSettings, uint64_t bytes, bool forceShutdown) // Disconnects the socket { - Resolver* resCache; - auto tldName = string(Resolver::tld(hostname)); - auto it = _resolverCache.find(tldName); - if (it != _resolverCache.end()) { + Cache* resCache; + auto tldName = string(Cache::tld(hostname)); + auto it = _cache.find(tldName); + if (it != _cache.end()) { resCache = it->second.get(); } else { - resCache = _resolverCache.find("")->second.get(); + resCache = _cache.find("")->second.get(); } resCache->stopSocket(fd, bytes); if (forceShutdown) { @@ -281,6 +290,15 @@ void ConnectionManager::disconnect(int32_t fd, string hostname, uint32_t port, c } else if (tcpSettings && tcpSettings->reuse > 0 && hostname.length() > 0 && port) { auto it = _fdSockets.find(fd); assert(it != _fdSockets.end()); + auto* socketEntry = it->second.get(); + _fdQueue.push_back(socketEntry); + auto cacheEntries = (_maxCachedFds / _activeConnectionManagers) + 1; + while (_fdQueue.size() > cacheEntries) { + socketEntry = _fdQueue.front(); + close(socketEntry->fd); + socketEntry->fd = -1; + _fdQueue.pop_front(); + } _fdCache.emplace(hostname, move(it->second)); _fdSockets.erase(it); } else { @@ -289,10 +307,10 @@ void ConnectionManager::disconnect(int32_t fd, string hostname, uint32_t port, c } } //--------------------------------------------------------------------------- -void ConnectionManager::addResolver(const string& hostname, unique_ptr resolver) -// Add resolver +void ConnectionManager::addCache(const string& hostname, unique_ptr cache) +// Add cache { - _resolverCache.emplace(string(Resolver::tld(hostname)), move(resolver)); + _cache.emplace(string(Cache::tld(hostname)), move(cache)); } //--------------------------------------------------------------------------- bool ConnectionManager::checkTimeout(int fd, const TCPSettings& tcpSettings) @@ -321,7 +339,9 @@ ConnectionManager::~ConnectionManager() for (auto& f : _fdSockets) close(f.first); for (auto& f : _fdCache) - close(f.second->fd); + if (f.second->fd >= 0) + close(f.second->fd); + _activeConnectionManagers--; } //--------------------------------------------------------------------------- } // namespace network diff --git a/src/network/tasked_send_receiver.cpp b/src/network/tasked_send_receiver.cpp index e26027e..8e65007 100644 --- a/src/network/tasked_send_receiver.cpp +++ b/src/network/tasked_send_receiver.cpp @@ -164,10 +164,10 @@ unique_ptr> TaskedSendReceiver::getReused() return nullptr; } //-------------------------------------------------------------------------- -void TaskedSendReceiver::addResolver(const std::string& hostname, std::unique_ptr resolver) -// Adds a resolver +void TaskedSendReceiver::addCache(const std::string& hostname, std::unique_ptr cache) +// Adds a hostname-specific cache { - _connectionManager->addResolver(hostname, move(resolver)); + _connectionManager->addCache(hostname, move(cache)); } //-------------------------------------------------------------------------- void TaskedSendReceiver::sendReceive(bool local, bool oneQueueInvocation) diff --git a/src/network/throughput_resolver.cpp b/src/network/throughput_cache.cpp similarity index 90% rename from src/network/throughput_resolver.cpp rename to src/network/throughput_cache.cpp index fc2376d..d896895 100644 --- a/src/network/throughput_resolver.cpp +++ b/src/network/throughput_cache.cpp @@ -1,5 +1,5 @@ #ifndef ANYBLOB_LIBCXX_COMPAT -#include "network/throughput_resolver.hpp" +#include "network/throughput_cache.hpp" #include #include #include @@ -19,13 +19,13 @@ namespace network { //--------------------------------------------------------------------------- using namespace std; //--------------------------------------------------------------------------- -ThroughputResolver::ThroughputResolver(unsigned entries) : Resolver(entries), _throughputTree(), _throughput(), _throughputIterator() +ThroughputCache::ThroughputCache(unsigned entries) : Cache(entries), _throughputTree(), _throughput(), _throughputIterator() // Constructor { _throughput.resize(_maxHistory); } //--------------------------------------------------------------------------- -const addrinfo* ThroughputResolver::resolve(string hostname, string port, bool& reuse) +const addrinfo* ThroughputCache::resolve(string hostname, string port, bool& reuse) // Resolve the request { auto addrPos = _addrCtr % _addrString.size(); @@ -50,13 +50,13 @@ const addrinfo* ThroughputResolver::resolve(string hostname, string port, bool& return _addr[addrPos].get(); } //--------------------------------------------------------------------------- -void ThroughputResolver::startSocket(int fd) +void ThroughputCache::startSocket(int fd) // Start a socket { _fdMap.emplace(fd, make_pair(_addrCtr++ % _addrString.size(), chrono::steady_clock::now())); } //--------------------------------------------------------------------------- -void ThroughputResolver::shutdownSocket(int fd) +void ThroughputCache::shutdownSocket(int fd) // Shutdown a socket and clear the dns cache { auto it = _fdMap.find(fd); @@ -71,7 +71,7 @@ void ThroughputResolver::shutdownSocket(int fd) } } //--------------------------------------------------------------------------- -void ThroughputResolver::stopSocket(int fd, uint64_t bytes) +void ThroughputCache::stopSocket(int fd, uint64_t bytes) // Stop a socket { auto now = chrono::steady_clock::now(); diff --git a/test/unit/network/io_uring_socket_test.cpp b/test/unit/network/io_uring_socket_test.cpp index 82e6728..a875638 100644 --- a/test/unit/network/io_uring_socket_test.cpp +++ b/test/unit/network/io_uring_socket_test.cpp @@ -1,5 +1,5 @@ #include "catch2/single_include/catch2/catch.hpp" -#include "cloud/aws_resolver.hpp" +#include "cloud/aws_cache.hpp" #include "network/connection_manager.hpp" #include "perfevent/PerfEvent.hpp" //--------------------------------------------------------------------------- diff --git a/test/unit/network/resolver_test.cpp b/test/unit/network/resolver_test.cpp index 0ecabfd..30ff5fa 100644 --- a/test/unit/network/resolver_test.cpp +++ b/test/unit/network/resolver_test.cpp @@ -1,4 +1,4 @@ -#include "network/resolver.hpp" +#include "network/cache.hpp" #include "catch2/single_include/catch2/catch.hpp" //--------------------------------------------------------------------------- // AnyBlob - Universal Cloud Object Storage Library @@ -12,7 +12,7 @@ namespace anyblob { namespace network { namespace test { //--------------------------------------------------------------------------- -TEST_CASE("resolver") { +TEST_CASE("cache") { } //--------------------------------------------------------------------------- } // namespace test