Changeset 2164
- Timestamp:
- Jun 19, 2007, 6:01:30 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/makemeta.c
r2162 r2164 9 9 */ 10 10 11 #include <math.h> 11 12 #include <sys/types.h> 12 13 #include <sys/stat.h> … … 74 75 75 76 static int 76 bestPieceSize( uint64_t totalSize ) 77 { 78 const int MiB = 1048576; 79 const int GiB = totalSize / (uint64_t)1073741824; 80 81 /* almost always best to have a piee size of 512 or 256 kb. 82 common practice seems to be to bump up to 1MB pieces at 83 at total size of around 8GiB or so */ 84 85 if( GiB >= 8 ) 86 return MiB; 87 88 if( GiB >= 1 ) 89 return MiB / 2; 90 91 return MiB / 4; 77 bestPieceSize( uint64_t totalSize, uint64_t fileCount ) 78 { 79 int pieceSize = 1; 80 const int minPieceSize = 65536; /* arbitrary; 2^16 */ 81 const int maxPieceSize = 16777216; /* arbitrary; 2^24 */ 82 const int desiredMinPiecesPerFile = 15; /* arbitrary */ 83 uint64_t log; 84 85 /* start off in the range of (1024..2048] pieces 86 for "normal" torrents... */ 87 log = totalSize; 88 while( log > 2048 ) { 89 log >>= 1; 90 pieceSize <<= 1; 91 } 92 93 /* special case 1: torrents with a lot of small files. 94 try to have a reasonable number of pieces per file, 95 which will reduce overhead on selective downloading 96 and increase swarm speed. */ 97 while( totalSize/pieceSize < (fileCount * desiredMinPiecesPerFile) ) { 98 const int swap = pieceSize >> 1; 99 if( swap < minPieceSize ) 100 break; 101 pieceSize = swap; 102 } 103 104 /* special case 2: enormous single-file torrents. our normal 105 case creates unwieldly piece sizes in that case */ 106 while( pieceSize < maxPieceSize ) 107 pieceSize >>= 1; 108 109 return pieceSize; 92 110 } 93 111 … … 149 167 builderFileCompare ); 150 168 151 ret->pieceSize = bestPieceSize( ret->totalSize );169 ret->pieceSize = bestPieceSize( ret->totalSize, ret->fileCount ); 152 170 ret->pieceCount = (int)( ret->totalSize / ret->pieceSize); 153 171 if( ret->totalSize % ret->pieceSize )
Note: See TracChangeset
for help on using the changeset viewer.