Check-in [95fab8c60b]
Not logged in
Overview

SHA1 Hash:95fab8c60b5c02205dd1d4ec2bd97e11958d5fe4
Date: 2008-01-31 21:54:48
User: drh
Comment:The client-side of a sync uses an adaptive approach to limit the number of "gimme" requests on each HTTP round-trip. This reduces traffic on a large clone. The number of "gimmes" on each round-trip is the larger of 100 or twice the number of files received on the previous cycle.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/xfer.c from [fe8089aded] to [83f986fb90].

@@ -284,17 +284,17 @@
 }
 
 /*
 ** Send a gimme message for every phantom.
 */
-static void request_phantoms(Xfer *pXfer){
+static void request_phantoms(Xfer *pXfer, int maxReq){
   Stmt q;
   db_prepare(&q,
     "SELECT uuid FROM phantom JOIN blob USING(rid)"
     " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)"
   );
-  while( db_step(&q)==SQLITE_ROW ){
+  while( db_step(&q)==SQLITE_ROW && maxReq-- > 0 ){
     const char *zUuid = db_column_text(&q, 0);
     blob_appendf(pXfer->pOut, "gimme %s\n", zUuid);
     pXfer->nGimmeSent++;
   }
   db_finalize(&q);
@@ -645,11 +645,11 @@
       @ error bad\scommand:\s%F(blob_str(&xfer.line))
     }
     blobarray_reset(xfer.aToken, xfer.nToken);
   }
   if( isPush ){
-    request_phantoms(&xfer);
+    request_phantoms(&xfer, 500);
   }
   if( isPull ){
     create_cluster();
     send_unclustered(&xfer);
   }
@@ -703,11 +703,13 @@
   const char *zSCode = db_get("server-code", "x");
   const char *zPCode = db_get("project-code", 0);
   int nMsg = 0;          /* Number of messages sent or received */
   int nCycle = 0;        /* Number of round trips to the server */
   int nFileSend = 0;
-  const char *zCookie;   /* Server cookie */
+  int nFileRecv;          /* Number of files received */
+  int mxPhantomReq = 200; /* Max number of phantoms to request per comm */
+  const char *zCookie;    /* Server cookie */
   Blob send;        /* Text we are sending to the server */
   Blob recv;        /* Reply we got back from the server */
   Xfer xfer;        /* Transfer data */
 
   memset(&xfer, 0, sizeof(xfer));
@@ -759,11 +761,11 @@
 
     /* Generate gimme messages for phantoms and leaf messages
     ** for all leaves.
     */
     if( pullFlag || cloneFlag ){
-      request_phantoms(&xfer);
+      request_phantoms(&xfer, mxPhantomReq);
     }
     if( pushFlag ){
       send_unsent(&xfer);
       nMsg += send_unclustered(&xfer);
     }
@@ -930,14 +932,15 @@
     go = 0;
 
     /* If we received one or more files on the previous exchange but
     ** there are still phantoms, then go another round.
     */
-    if( (xfer.nFileRcvd+xfer.nDeltaRcvd+xfer.nDanglingFile>0 || newPhantom)
-         && db_exists("SELECT 1 FROM phantom")
-    ){
+    nFileRecv = xfer.nFileRcvd + xfer.nDeltaRcvd + xfer.nDanglingFile;
+    if( (nFileRecv>0 || newPhantom) && db_exists("SELECT 1 FROM phantom") ){
       go = 1;
+      mxPhantomReq = nFileRecv*2;
+      if( mxPhantomReq<100 ) mxPhantomReq = 100;
     }
     nMsg = 0;
     xfer.nFileRcvd = 0;
     xfer.nDeltaRcvd = 0;
     xfer.nDanglingFile = 0;