mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-25 23:06:10 -05:00
- fixed download priority handling. Proof-tested on multiple DL from the same peer.
- removed dependency of mRateIncrease into measured rtt -> would cause very slow transfers through long tunnels git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4671 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
f952bc267b
commit
4d9727f47a
@ -76,8 +76,7 @@ static const uint32_t FT_FILECONTROL_QUEUE_ADD_AFTER_CACHE = 1 ;
|
||||
|
||||
ftFileControl::ftFileControl()
|
||||
:mTransfer(NULL), mCreator(NULL),
|
||||
mState(DOWNLOADING), mSize(0), mFlags(0),
|
||||
mPriority(SPEED_NORMAL)
|
||||
mState(DOWNLOADING), mSize(0), mFlags(0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -88,8 +87,7 @@ ftFileControl::ftFileControl(std::string fname,
|
||||
ftFileCreator *fc, ftTransferModule *tm)
|
||||
:mName(fname), mCurrentPath(tmppath), mDestination(dest),
|
||||
mTransfer(tm), mCreator(fc), mState(DOWNLOADING), mHash(hash),
|
||||
mSize(size), mFlags(flags),
|
||||
mPriority(SPEED_NORMAL) // default priority to normal
|
||||
mSize(size), mFlags(flags)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -287,39 +285,11 @@ void ftController::tickTransfers()
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ticking transfers." << std::endl ;
|
||||
#endif
|
||||
std::vector<std::vector<ftTransferModule*> >priority_tab (3,std::vector<ftTransferModule*>()) ;
|
||||
|
||||
// Collect all non queued files.
|
||||
//
|
||||
for(std::map<std::string,ftFileControl*>::iterator it(mDownloads.begin()); it != mDownloads.end(); it++)
|
||||
if(it->second->mState != ftFileControl::QUEUED && it->second->mState != ftFileControl::PAUSED)
|
||||
priority_tab[it->second->mPriority].push_back(it->second->mTransfer) ;
|
||||
|
||||
// 2 - tick arrays with a probability proportional to priority
|
||||
|
||||
// 2.1 - decide based on probability, which category of files we handle.
|
||||
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "Priority tabs: " ;
|
||||
std::cerr << "Low (" << priority_tab[SPEED_LOW ].size() << ") " ;
|
||||
std::cerr << "Normal (" << priority_tab[SPEED_NORMAL].size() << ") " ;
|
||||
std::cerr << "High (" << priority_tab[SPEED_HIGH ].size() << ") " ;
|
||||
std::cerr << std::endl ;
|
||||
#endif
|
||||
|
||||
/* tick the transferModules */
|
||||
|
||||
// start anywhere in the chosen list of transfers, so that not to favor any special transfer
|
||||
//
|
||||
|
||||
for(int chosen=2;chosen>=0;--chosen)
|
||||
if(!priority_tab[chosen].empty())
|
||||
{
|
||||
int start = rand() % priority_tab[chosen].size() ;
|
||||
|
||||
for(int i=0;i<(int)priority_tab[chosen].size();++i)
|
||||
priority_tab[chosen][(i+start)%(int)priority_tab[chosen].size()]->tick() ;
|
||||
}
|
||||
it->second->mTransfer->tick() ;
|
||||
}
|
||||
|
||||
bool ftController::getPriority(const std::string& hash,DwlSpeed& p)
|
||||
@ -330,12 +300,13 @@ bool ftController::getPriority(const std::string& hash,DwlSpeed& p)
|
||||
|
||||
if(it != mDownloads.end())
|
||||
{
|
||||
p = it->second->mPriority ;
|
||||
p = it->second->mTransfer->downloadPriority() ;
|
||||
return true ;
|
||||
}
|
||||
else
|
||||
return false ;
|
||||
}
|
||||
|
||||
void ftController::setPriority(const std::string& hash,DwlSpeed p)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
@ -343,7 +314,7 @@ void ftController::setPriority(const std::string& hash,DwlSpeed p)
|
||||
std::map<std::string,ftFileControl*>::iterator it(mDownloads.find(hash)) ;
|
||||
|
||||
if(it != mDownloads.end())
|
||||
it->second->mPriority = p ;
|
||||
it->second->mTransfer->setDownloadPriority(p) ;
|
||||
}
|
||||
|
||||
void ftController::cleanCacheDownloads()
|
||||
@ -1605,7 +1576,7 @@ bool ftController::FileDetails(const std::string &hash, FileInfo &info)
|
||||
info.fname = it->second->mName;
|
||||
info.flags = it->second->mFlags;
|
||||
info.path = RsDirUtil::removeTopDir(it->second->mDestination); /* remove fname */
|
||||
info.priority = it->second->mPriority ;
|
||||
info.priority = it->second->mTransfer->downloadPriority() ;
|
||||
info.queue_position = it->second->mQueuePosition ;
|
||||
|
||||
/* get list of sources from transferModule */
|
||||
|
@ -86,7 +86,6 @@ class ftFileControl
|
||||
uint64_t mSize;
|
||||
uint32_t mFlags;
|
||||
time_t mCreateTime;
|
||||
DwlSpeed mPriority ;
|
||||
uint32_t mQueuePriority ;
|
||||
uint32_t mQueuePosition ;
|
||||
};
|
||||
|
@ -26,7 +26,6 @@
|
||||
/******
|
||||
* #define FT_DEBUG 1
|
||||
*****/
|
||||
#define FT_DEBUG 1
|
||||
|
||||
#include "retroshare/rsturtle.h"
|
||||
#include "fttransfermodule.h"
|
||||
@ -47,19 +46,24 @@
|
||||
*
|
||||
*/
|
||||
|
||||
const double FT_TM_MAX_PEER_RATE = 10 * 1024 * 1024; /* 10MB/s */
|
||||
const uint32_t FT_TM_MAX_RESETS = 5;
|
||||
const double FT_TM_MAX_PEER_RATE = 10 * 1024 * 1024; /* 10MB/s */
|
||||
const uint32_t FT_TM_MAX_RESETS = 5;
|
||||
|
||||
const uint32_t FT_TM_MINIMUM_CHUNK = 1024; /* ie 1Kb / sec */
|
||||
const uint32_t FT_TM_RESTART_DOWNLOAD = 20; /* 20 seconds */
|
||||
const uint32_t FT_TM_DOWNLOAD_TIMEOUT = 10; /* 10 seconds */
|
||||
const uint32_t FT_TM_MINIMUM_CHUNK = 1024; /* ie 1Kb / sec */
|
||||
const uint32_t FT_TM_RESTART_DOWNLOAD = 20; /* 20 seconds */
|
||||
const uint32_t FT_TM_DOWNLOAD_TIMEOUT = 10; /* 10 seconds */
|
||||
const uint32_t FT_TM_CRC_MAP_MAX_WAIT_PER_GIG = 20; /* 20 seconds per gigabyte */
|
||||
|
||||
const double FT_TM_MAX_INCREASE = 1.00;
|
||||
const double FT_TM_MIN_INCREASE = -0.10;
|
||||
// const double FT_TM_MAX_INCREASE = 1.00;
|
||||
// const double FT_TM_MIN_INCREASE = -0.10;
|
||||
|
||||
const double FT_TM_RATE_INCREASE_SLOWER = 0.05 ;
|
||||
const double FT_TM_RATE_INCREASE_AVERAGE = 0.3 ;
|
||||
const double FT_TM_RATE_INCREASE_FASTER = 1.0 ;
|
||||
|
||||
const int32_t FT_TM_FAST_RTT = 1.0;
|
||||
const int32_t FT_TM_STD_RTT = 5.0;
|
||||
const int32_t FT_TM_SLOW_RTT = 9.0;
|
||||
const int32_t FT_TM_SLOW_RTT = 20.0;
|
||||
|
||||
const uint32_t FT_TM_CRC_MAP_STATE_NOCHECK = 0 ;
|
||||
const uint32_t FT_TM_CRC_MAP_STATE_DONT_HAVE = 1 ;
|
||||
@ -72,7 +76,7 @@ const uint32_t FT_TM_CRC_MAP_STATE_HAVE = 2 ;
|
||||
#define FT_TM_FLAG_CHUNK_CRC 4
|
||||
|
||||
ftTransferModule::ftTransferModule(ftFileCreator *fc, ftDataMultiplex *dm, ftController *c)
|
||||
:mFileCreator(fc), mMultiplexor(dm), mFtController(c), tfMtx("ftTransferModule"), mFlag(FT_TM_FLAG_DOWNLOADING)
|
||||
:mFileCreator(fc), mMultiplexor(dm), mFtController(c), tfMtx("ftTransferModule"), mFlag(FT_TM_FLAG_DOWNLOADING),mPriority(SPEED_NORMAL)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
|
||||
@ -916,7 +920,6 @@ bool ftTransferModule::locked_tickPeerTransfer(peerInfo &info)
|
||||
uint32_t next_req = info.actualRate * (1.0 + info.mRateIncrease);
|
||||
#ifdef FT_DEBUG
|
||||
std::cerr << "locked_tickPeerTransfer() actual rate (after): " << actualRate
|
||||
<< " increase factor=" << 1.0 + info.mRateIncrease
|
||||
<< " info.desiredRate=" << info.desiredRate
|
||||
<< " info.actualRate=" << info.actualRate
|
||||
<< ", next_req=" << next_req ;
|
||||
@ -992,12 +995,8 @@ bool ftTransferModule::locked_tickPeerTransfer(peerInfo &info)
|
||||
|
||||
|
||||
//interface to client module
|
||||
bool ftTransferModule::locked_recvPeerData(peerInfo &info, uint64_t offset,
|
||||
uint32_t chunk_size, void *data)
|
||||
bool ftTransferModule::locked_recvPeerData(peerInfo &info, uint64_t offset, uint32_t chunk_size, void *)
|
||||
{
|
||||
/* remove unused parameter warnings */
|
||||
(void) data;
|
||||
|
||||
#ifdef FT_DEBUG
|
||||
std::cerr << "ftTransferModule::locked_recvPeerData()";
|
||||
std::cerr << " peerId: " << info.peerId;
|
||||
@ -1005,7 +1004,6 @@ bool ftTransferModule::locked_recvPeerData(peerInfo &info, uint64_t offset,
|
||||
std::cerr << " lastTransfers: " << info.lastTransfers;
|
||||
std::cerr << " offset: " << offset;
|
||||
std::cerr << " chunksize: " << chunk_size;
|
||||
std::cerr << " data: " << data;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
@ -1015,37 +1013,43 @@ bool ftTransferModule::locked_recvPeerData(peerInfo &info, uint64_t offset,
|
||||
info.state = PQIPEER_DOWNLOADING;
|
||||
info.lastTransfers += chunk_size;
|
||||
|
||||
if ((info.rttActive) && (info.rttOffset == offset + chunk_size))
|
||||
{
|
||||
/* update tip */
|
||||
int32_t rtt = time(NULL) - info.rttStart;
|
||||
|
||||
/*
|
||||
* FT_TM_FAST_RTT = 1 sec. mRateIncrease = 1.00
|
||||
* FT_TM_SLOW_RTT = 9 sec. mRateIncrease = 0
|
||||
* 11 sec. mRateIncrease = -0.25
|
||||
* if it is slower than this allow fast data increase.
|
||||
* initial guess - linear with rtt.
|
||||
* change if this leads to wild oscillations
|
||||
*
|
||||
*/
|
||||
|
||||
info.mRateIncrease = (FT_TM_SLOW_RTT - rtt) *
|
||||
(FT_TM_MAX_INCREASE / (FT_TM_SLOW_RTT - FT_TM_FAST_RTT));
|
||||
|
||||
if (info.mRateIncrease > FT_TM_MAX_INCREASE)
|
||||
info.mRateIncrease = FT_TM_MAX_INCREASE;
|
||||
|
||||
if (info.mRateIncrease < FT_TM_MIN_INCREASE)
|
||||
info.mRateIncrease = FT_TM_MIN_INCREASE;
|
||||
|
||||
info.rtt = rtt;
|
||||
info.rttActive = false;
|
||||
if ((info.rttActive) && (info.rttOffset == offset + chunk_size))
|
||||
{
|
||||
/* update tip */
|
||||
int32_t rtt = time(NULL) - info.rttStart;
|
||||
|
||||
/*
|
||||
* FT_TM_FAST_RTT = 1 sec. mRateIncrease = 1.00
|
||||
* FT_TM_SLOW_RTT =20 sec. mRateIncrease = 0
|
||||
* 11 sec. mRateIncrease = -0.25
|
||||
* if it is slower than this allow fast data increase.
|
||||
* initial guess - linear with rtt.
|
||||
* change if this leads to wild oscillations
|
||||
*
|
||||
*/
|
||||
|
||||
// info.mRateIncrease = (FT_TM_SLOW_RTT - rtt) *
|
||||
// (FT_TM_MAX_INCREASE / (FT_TM_SLOW_RTT - FT_TM_FAST_RTT));
|
||||
//
|
||||
// if (info.mRateIncrease > FT_TM_MAX_INCREASE)
|
||||
// info.mRateIncrease = FT_TM_MAX_INCREASE;
|
||||
//
|
||||
// if (info.mRateIncrease < FT_TM_MIN_INCREASE)
|
||||
// info.mRateIncrease = FT_TM_MIN_INCREASE;
|
||||
|
||||
switch(mPriority)
|
||||
{
|
||||
case SPEED_LOW : info.mRateIncrease = FT_TM_RATE_INCREASE_SLOWER ; break ;
|
||||
case SPEED_NORMAL : info.mRateIncrease = FT_TM_RATE_INCREASE_AVERAGE; break ;
|
||||
case SPEED_HIGH : info.mRateIncrease = FT_TM_RATE_INCREASE_FASTER ; break ;
|
||||
}
|
||||
info.rtt = rtt;
|
||||
info.rttActive = false;
|
||||
|
||||
#ifdef FT_DEBUG
|
||||
std::cerr << "ftTransferModule::locked_recvPeerData()";
|
||||
std::cerr << "Updated Rate based on RTT: " << rtt;
|
||||
std::cerr << " Rate: " << info.mRateIncrease;
|
||||
std::cerr << " Rate increase: " << 1.0+info.mRateIncrease;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
|
@ -57,7 +57,6 @@ class peerInfo
|
||||
{
|
||||
public:
|
||||
peerInfo(std::string peerId_in):peerId(peerId_in),state(PQIPEER_NOT_ONLINE),desiredRate(0),actualRate(0),
|
||||
// offset(0),chunkSize(0),receivedSize(0),
|
||||
lastTS(0),
|
||||
recvTS(0), lastTransfers(0), nResets(0),
|
||||
rtt(0), rttActive(false), rttStart(0), rttOffset(0),
|
||||
@ -67,7 +66,6 @@ public:
|
||||
}
|
||||
peerInfo(std::string peerId_in,uint32_t state_in,uint32_t maxRate_in):
|
||||
peerId(peerId_in),state(state_in),desiredRate(maxRate_in),actualRate(0),
|
||||
// offset(0),chunkSize(0),receivedSize(0),
|
||||
lastTS(0),
|
||||
recvTS(0), lastTransfers(0), nResets(0),
|
||||
rtt(0), rttActive(false), rttStart(0), rttOffset(0),
|
||||
@ -80,13 +78,6 @@ public:
|
||||
double desiredRate;
|
||||
double actualRate;
|
||||
|
||||
//current file data request
|
||||
// uint64_t offset;
|
||||
// uint32_t chunkSize;
|
||||
|
||||
//already received data size for current request
|
||||
// uint32_t receivedSize;
|
||||
|
||||
time_t lastTS; /* last Request */
|
||||
time_t recvTS; /* last Recv */
|
||||
uint32_t lastTransfers; /* data recvd in last second */
|
||||
@ -164,6 +155,9 @@ public:
|
||||
bool queryInactive();
|
||||
void adjustSpeed();
|
||||
|
||||
DwlSpeed downloadPriority() const { return mPriority ; }
|
||||
void setDownloadPriority(DwlSpeed p) { mPriority =p ; }
|
||||
|
||||
private:
|
||||
|
||||
bool locked_tickPeerTransfer(peerInfo &info);
|
||||
@ -199,6 +193,7 @@ private:
|
||||
ftFileStatus mFileStatus; //used for pause/resume file transfer
|
||||
|
||||
HashThread *_hash_thread ;
|
||||
DwlSpeed mPriority ; // transfer speed priority
|
||||
};
|
||||
|
||||
#endif //FT_TRANSFER_MODULE_HEADER
|
||||
|
Loading…
x
Reference in New Issue
Block a user