mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-27 15:57:08 -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()
|
ftFileControl::ftFileControl()
|
||||||
:mTransfer(NULL), mCreator(NULL),
|
:mTransfer(NULL), mCreator(NULL),
|
||||||
mState(DOWNLOADING), mSize(0), mFlags(0),
|
mState(DOWNLOADING), mSize(0), mFlags(0)
|
||||||
mPriority(SPEED_NORMAL)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -88,8 +87,7 @@ ftFileControl::ftFileControl(std::string fname,
|
|||||||
ftFileCreator *fc, ftTransferModule *tm)
|
ftFileCreator *fc, ftTransferModule *tm)
|
||||||
:mName(fname), mCurrentPath(tmppath), mDestination(dest),
|
:mName(fname), mCurrentPath(tmppath), mDestination(dest),
|
||||||
mTransfer(tm), mCreator(fc), mState(DOWNLOADING), mHash(hash),
|
mTransfer(tm), mCreator(fc), mState(DOWNLOADING), mHash(hash),
|
||||||
mSize(size), mFlags(flags),
|
mSize(size), mFlags(flags)
|
||||||
mPriority(SPEED_NORMAL) // default priority to normal
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -287,39 +285,11 @@ void ftController::tickTransfers()
|
|||||||
#ifdef CONTROL_DEBUG
|
#ifdef CONTROL_DEBUG
|
||||||
std::cerr << "ticking transfers." << std::endl ;
|
std::cerr << "ticking transfers." << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
std::vector<std::vector<ftTransferModule*> >priority_tab (3,std::vector<ftTransferModule*>()) ;
|
|
||||||
|
|
||||||
// Collect all non queued files.
|
// Collect all non queued files.
|
||||||
//
|
//
|
||||||
for(std::map<std::string,ftFileControl*>::iterator it(mDownloads.begin()); it != mDownloads.end(); it++)
|
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)
|
if(it->second->mState != ftFileControl::QUEUED && it->second->mState != ftFileControl::PAUSED)
|
||||||
priority_tab[it->second->mPriority].push_back(it->second->mTransfer) ;
|
it->second->mTransfer->tick() ;
|
||||||
|
|
||||||
// 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() ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ftController::getPriority(const std::string& hash,DwlSpeed& p)
|
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())
|
if(it != mDownloads.end())
|
||||||
{
|
{
|
||||||
p = it->second->mPriority ;
|
p = it->second->mTransfer->downloadPriority() ;
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ftController::setPriority(const std::string& hash,DwlSpeed p)
|
void ftController::setPriority(const std::string& hash,DwlSpeed p)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
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)) ;
|
std::map<std::string,ftFileControl*>::iterator it(mDownloads.find(hash)) ;
|
||||||
|
|
||||||
if(it != mDownloads.end())
|
if(it != mDownloads.end())
|
||||||
it->second->mPriority = p ;
|
it->second->mTransfer->setDownloadPriority(p) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ftController::cleanCacheDownloads()
|
void ftController::cleanCacheDownloads()
|
||||||
@ -1605,7 +1576,7 @@ bool ftController::FileDetails(const std::string &hash, FileInfo &info)
|
|||||||
info.fname = it->second->mName;
|
info.fname = it->second->mName;
|
||||||
info.flags = it->second->mFlags;
|
info.flags = it->second->mFlags;
|
||||||
info.path = RsDirUtil::removeTopDir(it->second->mDestination); /* remove fname */
|
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 ;
|
info.queue_position = it->second->mQueuePosition ;
|
||||||
|
|
||||||
/* get list of sources from transferModule */
|
/* get list of sources from transferModule */
|
||||||
|
@ -86,7 +86,6 @@ class ftFileControl
|
|||||||
uint64_t mSize;
|
uint64_t mSize;
|
||||||
uint32_t mFlags;
|
uint32_t mFlags;
|
||||||
time_t mCreateTime;
|
time_t mCreateTime;
|
||||||
DwlSpeed mPriority ;
|
|
||||||
uint32_t mQueuePriority ;
|
uint32_t mQueuePriority ;
|
||||||
uint32_t mQueuePosition ;
|
uint32_t mQueuePosition ;
|
||||||
};
|
};
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
/******
|
/******
|
||||||
* #define FT_DEBUG 1
|
* #define FT_DEBUG 1
|
||||||
*****/
|
*****/
|
||||||
#define FT_DEBUG 1
|
|
||||||
|
|
||||||
#include "retroshare/rsturtle.h"
|
#include "retroshare/rsturtle.h"
|
||||||
#include "fttransfermodule.h"
|
#include "fttransfermodule.h"
|
||||||
@ -55,11 +54,16 @@ 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_DOWNLOAD_TIMEOUT = 10; /* 10 seconds */
|
||||||
const uint32_t FT_TM_CRC_MAP_MAX_WAIT_PER_GIG = 20; /* 20 seconds per gigabyte */
|
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_MAX_INCREASE = 1.00;
|
||||||
const double FT_TM_MIN_INCREASE = -0.10;
|
// 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_FAST_RTT = 1.0;
|
||||||
const int32_t FT_TM_STD_RTT = 5.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_NOCHECK = 0 ;
|
||||||
const uint32_t FT_TM_CRC_MAP_STATE_DONT_HAVE = 1 ;
|
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
|
#define FT_TM_FLAG_CHUNK_CRC 4
|
||||||
|
|
||||||
ftTransferModule::ftTransferModule(ftFileCreator *fc, ftDataMultiplex *dm, ftController *c)
|
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 ******/
|
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);
|
uint32_t next_req = info.actualRate * (1.0 + info.mRateIncrease);
|
||||||
#ifdef FT_DEBUG
|
#ifdef FT_DEBUG
|
||||||
std::cerr << "locked_tickPeerTransfer() actual rate (after): " << actualRate
|
std::cerr << "locked_tickPeerTransfer() actual rate (after): " << actualRate
|
||||||
<< " increase factor=" << 1.0 + info.mRateIncrease
|
|
||||||
<< " info.desiredRate=" << info.desiredRate
|
<< " info.desiredRate=" << info.desiredRate
|
||||||
<< " info.actualRate=" << info.actualRate
|
<< " info.actualRate=" << info.actualRate
|
||||||
<< ", next_req=" << next_req ;
|
<< ", next_req=" << next_req ;
|
||||||
@ -992,12 +995,8 @@ bool ftTransferModule::locked_tickPeerTransfer(peerInfo &info)
|
|||||||
|
|
||||||
|
|
||||||
//interface to client module
|
//interface to client module
|
||||||
bool ftTransferModule::locked_recvPeerData(peerInfo &info, uint64_t offset,
|
bool ftTransferModule::locked_recvPeerData(peerInfo &info, uint64_t offset, uint32_t chunk_size, void *)
|
||||||
uint32_t chunk_size, void *data)
|
|
||||||
{
|
{
|
||||||
/* remove unused parameter warnings */
|
|
||||||
(void) data;
|
|
||||||
|
|
||||||
#ifdef FT_DEBUG
|
#ifdef FT_DEBUG
|
||||||
std::cerr << "ftTransferModule::locked_recvPeerData()";
|
std::cerr << "ftTransferModule::locked_recvPeerData()";
|
||||||
std::cerr << " peerId: " << info.peerId;
|
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 << " lastTransfers: " << info.lastTransfers;
|
||||||
std::cerr << " offset: " << offset;
|
std::cerr << " offset: " << offset;
|
||||||
std::cerr << " chunksize: " << chunk_size;
|
std::cerr << " chunksize: " << chunk_size;
|
||||||
std::cerr << " data: " << data;
|
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1022,7 +1020,7 @@ bool ftTransferModule::locked_recvPeerData(peerInfo &info, uint64_t offset,
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* FT_TM_FAST_RTT = 1 sec. mRateIncrease = 1.00
|
* FT_TM_FAST_RTT = 1 sec. mRateIncrease = 1.00
|
||||||
* FT_TM_SLOW_RTT = 9 sec. mRateIncrease = 0
|
* FT_TM_SLOW_RTT =20 sec. mRateIncrease = 0
|
||||||
* 11 sec. mRateIncrease = -0.25
|
* 11 sec. mRateIncrease = -0.25
|
||||||
* if it is slower than this allow fast data increase.
|
* if it is slower than this allow fast data increase.
|
||||||
* initial guess - linear with rtt.
|
* initial guess - linear with rtt.
|
||||||
@ -1030,22 +1028,28 @@ bool ftTransferModule::locked_recvPeerData(peerInfo &info, uint64_t offset,
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
info.mRateIncrease = (FT_TM_SLOW_RTT - rtt) *
|
// info.mRateIncrease = (FT_TM_SLOW_RTT - rtt) *
|
||||||
(FT_TM_MAX_INCREASE / (FT_TM_SLOW_RTT - FT_TM_FAST_RTT));
|
// (FT_TM_MAX_INCREASE / (FT_TM_SLOW_RTT - FT_TM_FAST_RTT));
|
||||||
|
//
|
||||||
if (info.mRateIncrease > FT_TM_MAX_INCREASE)
|
// if (info.mRateIncrease > FT_TM_MAX_INCREASE)
|
||||||
info.mRateIncrease = FT_TM_MAX_INCREASE;
|
// info.mRateIncrease = FT_TM_MAX_INCREASE;
|
||||||
|
//
|
||||||
if (info.mRateIncrease < FT_TM_MIN_INCREASE)
|
// if (info.mRateIncrease < FT_TM_MIN_INCREASE)
|
||||||
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.rtt = rtt;
|
||||||
info.rttActive = false;
|
info.rttActive = false;
|
||||||
|
|
||||||
#ifdef FT_DEBUG
|
#ifdef FT_DEBUG
|
||||||
std::cerr << "ftTransferModule::locked_recvPeerData()";
|
std::cerr << "ftTransferModule::locked_recvPeerData()";
|
||||||
std::cerr << "Updated Rate based on RTT: " << rtt;
|
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;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -57,7 +57,6 @@ class peerInfo
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
peerInfo(std::string peerId_in):peerId(peerId_in),state(PQIPEER_NOT_ONLINE),desiredRate(0),actualRate(0),
|
peerInfo(std::string peerId_in):peerId(peerId_in),state(PQIPEER_NOT_ONLINE),desiredRate(0),actualRate(0),
|
||||||
// offset(0),chunkSize(0),receivedSize(0),
|
|
||||||
lastTS(0),
|
lastTS(0),
|
||||||
recvTS(0), lastTransfers(0), nResets(0),
|
recvTS(0), lastTransfers(0), nResets(0),
|
||||||
rtt(0), rttActive(false), rttStart(0), rttOffset(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):
|
peerInfo(std::string peerId_in,uint32_t state_in,uint32_t maxRate_in):
|
||||||
peerId(peerId_in),state(state_in),desiredRate(maxRate_in),actualRate(0),
|
peerId(peerId_in),state(state_in),desiredRate(maxRate_in),actualRate(0),
|
||||||
// offset(0),chunkSize(0),receivedSize(0),
|
|
||||||
lastTS(0),
|
lastTS(0),
|
||||||
recvTS(0), lastTransfers(0), nResets(0),
|
recvTS(0), lastTransfers(0), nResets(0),
|
||||||
rtt(0), rttActive(false), rttStart(0), rttOffset(0),
|
rtt(0), rttActive(false), rttStart(0), rttOffset(0),
|
||||||
@ -80,13 +78,6 @@ public:
|
|||||||
double desiredRate;
|
double desiredRate;
|
||||||
double actualRate;
|
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 lastTS; /* last Request */
|
||||||
time_t recvTS; /* last Recv */
|
time_t recvTS; /* last Recv */
|
||||||
uint32_t lastTransfers; /* data recvd in last second */
|
uint32_t lastTransfers; /* data recvd in last second */
|
||||||
@ -164,6 +155,9 @@ public:
|
|||||||
bool queryInactive();
|
bool queryInactive();
|
||||||
void adjustSpeed();
|
void adjustSpeed();
|
||||||
|
|
||||||
|
DwlSpeed downloadPriority() const { return mPriority ; }
|
||||||
|
void setDownloadPriority(DwlSpeed p) { mPriority =p ; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool locked_tickPeerTransfer(peerInfo &info);
|
bool locked_tickPeerTransfer(peerInfo &info);
|
||||||
@ -199,6 +193,7 @@ private:
|
|||||||
ftFileStatus mFileStatus; //used for pause/resume file transfer
|
ftFileStatus mFileStatus; //used for pause/resume file transfer
|
||||||
|
|
||||||
HashThread *_hash_thread ;
|
HashThread *_hash_thread ;
|
||||||
|
DwlSpeed mPriority ; // transfer speed priority
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //FT_TRANSFER_MODULE_HEADER
|
#endif //FT_TRANSFER_MODULE_HEADER
|
||||||
|
Loading…
x
Reference in New Issue
Block a user