From d1aecf5ac651683a38294a9c12c73d4d271e152a Mon Sep 17 00:00:00 2001 From: Dominik Durner Date: Wed, 12 Jul 2023 10:26:51 +0200 Subject: [PATCH] Stronger caching eviction during shutdown of socket due to error --- include/network/message_task.hpp | 2 +- include/network/resolver.hpp | 2 ++ include/network/throughput_resolver.hpp | 2 ++ src/network/io_uring_socket.cpp | 4 +++- src/network/throughput_resolver.cpp | 15 +++++++++++++++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/network/message_task.hpp b/include/network/message_task.hpp index b4b8e61..f604b46 100644 --- a/include/network/message_task.hpp +++ b/include/network/message_task.hpp @@ -46,7 +46,7 @@ struct MessageTask { Type type; /// The failure limit - static constexpr uint16_t failuresMax = 8; + static constexpr uint16_t failuresMax = 32; /// The pure virtual callback virtual MessageState execute(IOUringSocket& socket) = 0; diff --git a/include/network/resolver.hpp b/include/network/resolver.hpp index 8dfa6f0..1fe529b 100644 --- a/include/network/resolver.hpp +++ b/include/network/resolver.hpp @@ -42,6 +42,8 @@ class Resolver { virtual void startSocket(int /*fd*/, unsigned /*ipAsInt*/) {} /// Stop the timing virtual void stopSocket(int /*fd*/, uint64_t /*bytes*/) {} + /// Shutdown of the socket should clear the same addresses + virtual void shutdownSocket(int /*fd*/) {} /// The destructor virtual ~Resolver() noexcept = default; diff --git a/include/network/throughput_resolver.hpp b/include/network/throughput_resolver.hpp index cb09933..b043d00 100644 --- a/include/network/throughput_resolver.hpp +++ b/include/network/throughput_resolver.hpp @@ -46,6 +46,8 @@ class ThroughputResolver : public network::Resolver { virtual void startSocket(int fd, unsigned ipAsInt) override; /// Stop the timing virtual void stopSocket(int fd, uint64_t bytes) override; + /// Clears the used server from the cache + virtual void shutdownSocket(int fd) override; /// The destructor virtual ~ThroughputResolver() noexcept = default; }; diff --git a/src/network/io_uring_socket.cpp b/src/network/io_uring_socket.cpp index fbe8a53..a80e099 100644 --- a/src/network/io_uring_socket.cpp +++ b/src/network/io_uring_socket.cpp @@ -263,8 +263,10 @@ void IOUringSocket::disconnect(int32_t fd, string hostname, uint32_t port, TCPSe resCache = _resolverCache.find("")->second.get(); } resCache->stopSocket(fd, bytes); - if (forceShutdown) + if (forceShutdown) { shutdown(fd, SHUT_RDWR); + resCache->shutdownSocket(fd); + } if (tcpSettings && tcpSettings->reuse > 0 && hostname.length() > 0 && port) { _fdCache.emplace(hostname, fd); _fdSockets.erase(fd); diff --git a/src/network/throughput_resolver.cpp b/src/network/throughput_resolver.cpp index 6b4d53c..881c914 100644 --- a/src/network/throughput_resolver.cpp +++ b/src/network/throughput_resolver.cpp @@ -56,6 +56,21 @@ void ThroughputResolver::startSocket(int fd, unsigned addrPos) _fdMap.emplace(fd, make_pair(addrPos, chrono::steady_clock::now())); } //--------------------------------------------------------------------------- +void ThroughputResolver::shutdownSocket(int fd) +// Start a socket +{ + auto it = _fdMap.find(fd); + if (it != _fdMap.end()) { + auto pos = it->second.first; + auto& ip = _addr[pos]; + for (auto compPos = 0u; compPos < _addr.size(); compPos++) { + if (!strncmp(ip->ai_addr->sa_data, _addr[compPos]->ai_addr->sa_data, 14)) { + _addrString[compPos].second = 0; + } + } + } +} +//--------------------------------------------------------------------------- void ThroughputResolver::stopSocket(int fd, uint64_t bytes) // Stop a socket {