Calculation of the minimum tree for file transfer

I am creating a file sharing system that needs to transfer a single file to many peers. One peer to peer has the entire file and must transfer it to all other peers. How can I better build the file transfer tree so that total latency is minimized?

For instance:

alt text

In this tree, we need to wait 4 times until the transfer is complete.

alt textalt text

These two options are better, since we need to wait three times to complete the transfer.

+3
source share
4 answers

, , node node, , ,

     O
    /|\
   / | \
  /  |  \
 O   O   O

     O
    /
   /
  /
 O===O===O

( " " ===). node 2 : , . ( , .) , OP,

         O
        / \
       /   \
      /     \
     O       O
    / \
   /   \
  /     \
 O       O

"sibling-edge"

         O
        /
       /
      /
     O=======O
    /
   /
  /
 O=======O

, node . , , , . :

0            O
            /
           /
          /
1        O
        / \\
       /   \\
      /     \\
2    O       O
      \\
       \\
        \\
3        O

, t, , (t th) . m(t). t > 1 , t-1 2 (= 1 1 ) node. m(t) :

t      Total        Rightmost
       nodes        nodes

0      1            1
1      1+1*1=2      1 (only multiply by 1 because the root can't have siblings)
2      2+1*2=4      2
3      4+2*2=8      4
4      8+4*2=16     8

, m(t) = 2^(t-1), , - "" node.

, n 2, n = 2^t t+1, , 1 , 2. , , n, roundup(log2(n)) + 1.

, "sibling-of" node node. , -2 node , , , (roundup(log2(n)) + 1). , 1- node, , , , .

+1

, ( , ) log2(n) . node , (.. ).

+2

; BitTorrent ? (.. , , ?)

BT , , .

: ; log2(n), , ; , .

, ; , , , , , , log2(n) , . n , . (Edit: , , , , ?;)

+1

, . , 4 4 ... , , . node D = log2 (n). (D ) 0 D-1. , node X X 0 X.

, " ", "".

, node node. , () : -)

+1

Source: https://habr.com/ru/post/1770921/


All Articles