Switch to rate-limiting strategy

This commit is contained in:
Sasha Krassovsky
2023-12-15 12:35:38 -08:00
committed by Sasha Krassovsky
parent ea9fad419e
commit 091a0cda9d
2 changed files with 15 additions and 27 deletions

View File

@@ -133,6 +133,9 @@ pageserver_connect(int elevel)
const char *values[3];
int n;
static TimestampTz last_connect_time = 0;
TimestampTz now;
Assert(!connected);
if (CheckConnstringUpdated())
@@ -140,6 +143,17 @@ pageserver_connect(int elevel)
ReloadConnstring();
}
now = GetCurrentTimestamp();
if ((now - last_connect_time) < RECONNECT_INTERVAL_USEC)
{
pg_usleep(RECONNECT_INTERVAL_USEC);
last_connect_time = GetCurrentTimestamp();
}
else
{
last_connect_time = now;
}
/*
* Connect using the connection string we got from the
* neon.pageserver_connstring GUC. If the NEON_AUTH_TOKEN environment
@@ -333,7 +347,6 @@ pageserver_send(NeonRequest *request)
{
HandleMainLoopInterrupts();
n_reconnect_attempts += 1;
pg_usleep(RECONNECT_INTERVAL_USEC);
}
n_reconnect_attempts = 0;
}

View File

@@ -275,26 +275,6 @@ static inline void prefetch_set_unused(uint64 ring_index);
static XLogRecPtr neon_get_request_lsn(bool *latest, NRelFileInfo rinfo,
ForkNumber forknum, BlockNumber blkno);
#define INITIAL_EXPONENTIAL_BACKOFF_DELAY 1000
#define EXPONENTIAL_BACKOFF_EXPONENT 2
#define MAX_EXPONENTIAL_BACKOFF_DELAY (1000*1000)
static void
InitExponentialBackoff(long *delay)
{
*delay = INITIAL_EXPONENTIAL_BACKOFF_DELAY;
}
static void
PerformExponentialBackoff(long *delay)
{
pg_usleep(*delay);
*delay *= EXPONENTIAL_BACKOFF_EXPONENT;
if(*delay >= MAX_EXPONENTIAL_BACKOFF_DELAY)
*delay = MAX_EXPONENTIAL_BACKOFF_DELAY;
}
static bool
compact_prefetch_buffers(void)
{
@@ -682,7 +662,6 @@ prefetch_do_request(PrefetchRequest *slot, bool *force_latest, XLogRecPtr *force
.forknum = slot->buftag.forkNum,
.blkno = slot->buftag.blockNum,
};
long backoff_delay_us;
if (force_lsn && force_latest)
{
@@ -725,11 +704,7 @@ prefetch_do_request(PrefetchRequest *slot, bool *force_latest, XLogRecPtr *force
Assert(slot->response == NULL);
Assert(slot->my_ring_index == MyPState->ring_unused);
InitExponentialBackoff(&backoff_delay_us);
while (!page_server->send((NeonRequest *) &request))
{
PerformExponentialBackoff(&backoff_delay_us);
}
while (!page_server->send((NeonRequest *) &request));
/* update prefetch state */
MyPState->n_requests_inflight += 1;