Skip to content

Commit

Permalink
Stronger caching eviction during shutdown of socket due to error
Browse files Browse the repository at this point in the history
  • Loading branch information
durner committed Jul 12, 2023
1 parent 10b6b01 commit d1aecf5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/network/message_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions include/network/resolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions include/network/throughput_resolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
4 changes: 3 additions & 1 deletion src/network/io_uring_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/network/throughput_resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit d1aecf5

Please sign in to comment.