Changeset 2165


Ignore:
Timestamp:
Jun 19, 2007, 4:36:15 PM (15 years ago)
Author:
charles
Message:

more improvements to makemeta's piece size heuristics (SoftwareElves? & charles_)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/makemeta.c

    r2164 r2165  
    7575
    7676static int
    77 bestPieceSize( uint64_t totalSize, uint64_t fileCount )
    78 {
    79     int pieceSize = 1;
     77bestPieceSize( uint64_t totalSize, int fileCount )
     78{
    8079    const int minPieceSize = 65536; /* arbitrary; 2^16 */
    8180    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;
     81    const int desiredMinPiecesPerFile = 10; /* arbitrary */
     82    const unsigned int desiredPieces = fileCount * desiredMinPiecesPerFile;
     83
     84    /* a good starting range is to have (1024..2048] pieces... */
     85    int pieceSize = 1;
     86    uint64_t log = totalSize;
    8887    while( log > 2048 ) {
    8988        log >>= 1;
     
    9190    }
    9291
    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
     92    /* now try to have N pieces per average file size...
     93       this will reduce overhead on selective downloading
    9694       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 )
     95    while( ( totalSize / pieceSize ) < desiredPieces )
    10796        pieceSize >>= 1;
     97
     98    /* clamp to our desired range to make sure we
     99       haven't gone too far astray... */
     100    if( pieceSize < minPieceSize ) pieceSize = minPieceSize;
     101    if( pieceSize > maxPieceSize ) pieceSize = maxPieceSize;
    108102
    109103    return pieceSize;
Note: See TracChangeset for help on using the changeset viewer.