Database read throttle (#242)

Track current outstanding read requests to the database. When the configured limit is exceeded, reject new RPCs and return rpcTOO_BUSY
This commit is contained in:
CJ Cobb
2022-09-23 15:43:03 -05:00
committed by GitHub
parent 1764f3524e
commit eb1ea28e27
7 changed files with 113 additions and 70 deletions

View File

@@ -7,10 +7,12 @@
#include <backend/Types.h>
#include <thread>
#include <type_traits>
namespace Backend {
class DatabaseTimeout : public std::exception
{
public:
const char*
what() const throw() override
{
@@ -30,9 +32,10 @@ retryOnTimeout(F func, size_t waitMs = 500)
}
catch (DatabaseTimeout& t)
{
std::this_thread::sleep_for(std::chrono::milliseconds(waitMs));
BOOST_LOG_TRIVIAL(error)
<< __func__ << " function timed out. Retrying ... ";
<< __func__
<< " Database request timed out. Sleeping and retrying ... ";
std::this_thread::sleep_for(std::chrono::milliseconds(waitMs));
}
}
}
@@ -342,6 +345,9 @@ public:
virtual void
close(){};
virtual bool
isTooBusy() const = 0;
// *** private helper methods
private:
virtual void