This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Speedup

Tags: None
(comma "," separated)
Pär H
Registered Member
Posts
28
Karma
0

Speedup

Tue Dec 06, 2005 9:27 pm
I made a small "else" in the selection of chunks to download, after some testing i found a significant speedup when reach the last third of the download.

downloader.cpp
void Downloader::downloadFrom(PeerDownloader* pd)
Code: Select all
if (chunk_selector->select(pd,chunk))
{
   :
   :
}
else {
  // The peer has nothing more - start asking him for the
  // chunks we current downloads that he has.
  for (CurChunkItr j = current_chunks.begin();j != current_chunks.end();++j)
  {
    ChunkDownload* cd = j->second;            
    if (pd->hasChunk(cd->getChunk()->getIndex()))
      cd->assignPeer(pd,true);
  }
}
George
Moderator
Posts
5421
Karma
1

Wed Dec 07, 2005 5:37 pm
I'll test it out, see if it doesn't have any unintended side affects.
George
Moderator
Posts
5421
Karma
1

Thu Dec 08, 2005 5:50 pm
I added the changes, with some small modifications.
Pär H
Registered Member
Posts
28
Karma
0

Fri Dec 09, 2005 6:16 am
OK, thats better.


I had used break instead of return, if someone in the future add something at the end of the function....., but for now return works just fine.
Pär H
Registered Member
Posts
28
Karma
0

Sun Dec 11, 2005 2:12 pm
No, that wasn't bettter!
If more then 1 peer is in the same situation all peers got requests of the same chunk, I modified the else little!

Code: Select all
      else
      {
         // If the peer hasn't got a chunk we want,
         // try to assign it to a chunk we are currently downloading
         ChunkDownload *cdmin=NULL;
         for (CurChunkItr j = current_chunks.begin();j != current_chunks.end();++j)
         {
            ChunkDownload* cd = j->second;
            if (pd->hasChunk(cd->getChunk()->getIndex()))
            {
               if (cd->containsPeer(pd))
                  continue;
               if (cdmin==NULL)
                  cdmin=cd;
               else if (cd->getNumDownloaders()<cdmin->getNumDownloaders())
                  cdmin=cd;

            }
         }
         if (cdmin)
            cdmin->assignPeer(pd,true);
      }


And added one function to ChunkDownload (chunkdownload.h)
Code: Select all
bool containsPeer(PeerDownloader *pd) {return pdown.contains(pd);}
George
Moderator
Posts
5421
Karma
1

Mon Dec 12, 2005 8:13 pm
Thats a bit fairer indeed, I will add it with my next commit.


Bookmarks



Who is online

Registered users: bancha, Bing [Bot], Google [Bot], Sogou [Bot]