2

Why BufferSize of RealBufferedSource(FixedLengthSource) changes from 65536 to 2048 bytes when there is an exception?

2 issues i m facing on Downloadmanager code which are as follows: (I m new to this forum. If any more inputs needed, please tell me)

Issue 1:

DownloadManager(a.k.a DownloadThread) of android is updated once for 4 times read of 65536 bytes. Where this implementation is done? Sorry, I could not find the place where its done. Any specific reason for this update DownloadThread once for 4 reads?

During an error scenario, what happens is, if i do a partial HTTP fetch request from DownloadManager, Range: request goes with the last updated currentBytes value. So if an error happens inbetween (say, 2nd out of the 4th read), Range: request goes with the previously updated currentBytes which may reread the same bytes again.

// HC: is HttpConnection.java, FixedLengthSource#read where the print is added.

19:09:10.374  System.out: (HTTPLog)-Thread-270-223795676: Content-Length : 70610220
19:09:10.684  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 70610220,65536
19:09:10.694  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 70593836,65536
19:09:10.704  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 70577452,65536
19:09:10.704  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 70561068,65536
19:09:10.714  DownloadManager: currentBytes : 65536,mLastUpdateBytes : 0

19:09:10.714  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 70544684,65536
19:09:10.714  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 70528300,65536
19:09:10.724  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 70511916,65536
19:09:10.754  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 70495532,65536
19:09:10.774  DownloadManager: currentBytes : 131072,mLastUpdateBytes : 131072

19:09:10.774  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 70479148,65536
19:09:10.784  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 70462764,65536
19:09:10.784  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 70446380,65536
19:09:10.784  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 70429996,65536
19:09:10.794  DownloadManager: currentBytes : 196608,mLastUpdateBytes : 131072

19:09:10.794  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 70413612,65536
19:09:10.814  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 70397228,65536
19:09:10.814  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 70380844,65536
19:09:10.824  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 70364460,65536
19:09:10.834  DownloadManager: currentBytes : 262144,mLastUpdateBytes : 131072

Example:

19:09:10.794  DownloadManager: currentBytes : 196608,mLastUpdateBytes : 131072
// 1st read
19:09:10.794  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 70413612,65536 
// 2nd read
19:09:10.814  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 70397228,65536 
// If error happens here, the range: request for partial fetch happens using the 
// currentBytes variable as follows
System.out: (HTTPLog)-Thread-270-51176450: Range : bytes=196608-

// Ideally, it should be { [currentBytes : 196608] + [1st Read : 65536] + [2nd Read : 65536]}
System.out: (HTTPLog)-Thread-270-51176450: Range : bytes=327680- 

Issue 2:

When an IOException like SSLException occurs, automatically the fetch size is reduced from 65536 to 2048. Where this implementation is done? Sorry, I could not find the place where its done. Any specific reason for this downgrade - congestion avoidance something like that?

19:10:11.244  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13905628,65536 19:10:11.244  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13889244,65536 19:10:11.254  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13872860,65536 19:10:11.254  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13856476,65536 19:10:11.254  DownloadManager: currentBytes : 56754176, mLastUpdateBytes : 56360960 19:10:11.254  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13840092,65536 19:10:11.264  System.out: (HTTPLog)-Static: FixedLengthSource#read:: SSLException caught... 19:10:11.264  System.out: (HTTPLog)-Static: FixedLengthSource#read, Bytes remaining to be  downloaded : 13840092 19:10:11.264  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13840092,2048 19:10:11.284  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13838044,2048 19:10:11.284  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13835996,2048 19:10:11.284  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13833948,2048 19:10:11.294  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13831900,2048 19:10:11.294  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13829852,2048 19:10:11.294  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13827804,2048 19:10:11.294  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13825756,2048 19:10:11.304  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13823708,2048 19:10:11.304  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13821660,2048 19:10:11.304  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13819612,2048 19:10:11.314  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13817564,2048 19:10:11.314  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13815516,2048 19:10:11.314  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13813468,2048 19:10:11.314  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13811420,2048 19:10:11.314  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13809372,2048 19:10:11.314  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13807324,2048 19:10:11.324  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13805276,2048 19:10:11.324  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13803228,2048 19:10:11.324  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13801180,2048 19:10:11.324  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13799132,2048 19:10:11.324  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13797084,2048 19:10:11.324  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13795036,2048 19:10:11.334  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13792988,2048 19:10:11.334  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13790940,2048 19:10:11.334  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13788892,2048 19:10:11.334  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13786844,2048 19:10:11.334  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13784796,2048 19:10:11.334  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13782748,2048 19:10:11.344  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13780700,2048 19:10:11.344  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13778652,2048 19:10:11.354  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13776604,2048 19:10:11.364  System.out: (HTTPLog)-Static:  HC:: bytesRemaining, byteCount ::: 13774556,2048

In this case as well, currentBytes of DownloadThread is not updated about this 2048XM bytes download.

So, if the DownloadThread does a partial fetch using the currentBytes available with it, it will eventually re-read the same bytes from the server resulting in more data usage.

Please help me to understand if i miss anything basic.

Thank you Ram

ramsarvan
  • 53
  • 1
  • 5

0 Answers0