Differences From:
File
src/xfer.c
part of check-in
[18fbb9c52d]
- Send native deltas when cloning. The reduces bandwidth and reduces
server load.
by
drh on
2007-12-03 19:17:45.
Also file
src/xfer.c
part of check-in
[d0305b305a]
- Merged mainline into my branch to get the newest application.
by
aku on
2007-12-05 08:07:46.
[view]
To:
File
src/xfer.c
part of check-in
[95fab8c60b]
- 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.
by
drh on
2008-01-31 21:54:48.
[view]
@@ -285,15 +285,15 @@
/*
** 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++;
}
@@ -646,9 +646,9 @@
}
blobarray_reset(xfer.aToken, xfer.nToken);
}
if( isPush ){
- request_phantoms(&xfer);
+ request_phantoms(&xfer, 500);
}
if( isPull ){
create_cluster();
send_unclustered(&xfer);
@@ -704,9 +704,11 @@
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 */
@@ -760,9 +762,9 @@
/* 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);
@@ -931,12 +933,13 @@
/* 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;