Commit 2a752a06 authored by Leigh B. Stoller's avatar Leigh B. Stoller

Add client side backoff. If the daemon crashes, we will get a client

flood (say, if there were 40 clients wanting chunks). I added some
backoff code that will slow the rate at which the clients make
requests in the face of a non asnwering daemon. Backs off in
increments of the PKTRCV timeout value (30ms at present), until it
gets to one second. Then it holds at one second intervals.
parent c3198437
......@@ -147,12 +147,31 @@ void *
ClientRecvThread(void *arg)
{
Packet_t packet, *p = &packet;
int BackOff;
if (debug)
log("Receive pthread starting up ...");
/*
* Use this to control the rate at which we request blocks.
* The IdleCounter is how many ticks we let pass without a
* useful block, before we make another request. We want that to
* be short, but not too short; we do not want to pummel the
* server.
*/
IdleCounter = CLIENT_IDLETIMER_COUNT;
/*
* This is another throttling mechanism; avoid making repeated
* requests to a server that is not running. That is, if the server
* is not responding, slowly back off our request rate (to about
* one a second) until the server starts responding. This will
* prevent a large group of clients from pummeling the server
* machine, when there is no server running to respond (say, if the
* server process died).
*/
BackOff = 0;
while (1) {
/*
* If we go too long without getting a block, we want
......@@ -164,6 +183,12 @@ ClientRecvThread(void *arg)
if (! IdleCounter) {
RequestChunk(1);
IdleCounter = CLIENT_IDLETIMER_COUNT;
if (BackOff++) {
IdleCounter += BackOff;
if (BackOff > TIMEOUT_HZ)
BackOff = TIMEOUT_HZ;
}
}
continue;
}
......@@ -171,6 +196,7 @@ ClientRecvThread(void *arg)
switch (p->hdr.subtype) {
case PKTSUBTYPE_BLOCK:
BackOff = 0;
GotBlock(p);
break;
......@@ -535,7 +561,7 @@ PlayFrisbee(void)
p->hdr.datalen = sizeof(p->msg.join);
p->msg.join.clientid = myid;
PacketSend(p);
countdown = 10;
countdown = TIMEOUT_HALFHZ;
}
/*
......
......@@ -37,6 +37,8 @@
*/
#define PKTRCV_TIMEOUT 30000
#define CLIENT_IDLETIMER_COUNT 3
#define TIMEOUT_HZ (1000000 / PKTRCV_TIMEOUT)
#define TIMEOUT_HALFHZ (TIMEOUT_HZ / 2)
/*
* Timeout (in seconds!) server will hang around with no active clients.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment