mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-29 01:16:20 -05:00
removed deprecated bandwidth recorder code in RsGxsNetService
This commit is contained in:
parent
cf8dac2e74
commit
bba1a719fe
@ -453,120 +453,6 @@ void RsGxsNetService::cleanRejectedMessages()
|
||||
++it ;
|
||||
}
|
||||
|
||||
// This class collects outgoing items due to the broadcast of Nxs messages. It computes
|
||||
// a probability that can be used to temper the broadcast of items so as to match the
|
||||
// residual bandwidth (difference between max allowed bandwidth and current outgoing rate.
|
||||
|
||||
class NxsBandwidthRecorder
|
||||
{
|
||||
public:
|
||||
static const int OUTQUEUE_CUTOFF_VALUE = 500 ;
|
||||
static const int BANDWIDTH_ESTIMATE_DELAY = 20 ;
|
||||
|
||||
static void recordEvent(uint16_t service_type, RsItem *item)
|
||||
{
|
||||
RS_STACK_MUTEX(mtx) ;
|
||||
|
||||
uint32_t bw = RsNxsSerialiser(service_type).size(item) ; // this is used to estimate bandwidth.
|
||||
timeval tv ;
|
||||
gettimeofday(&tv,NULL) ;
|
||||
|
||||
// compute time(NULL) in msecs, for a more accurate bw estimate.
|
||||
|
||||
uint64_t now = (uint64_t) tv.tv_sec * 1000 + tv.tv_usec/1000 ;
|
||||
|
||||
total_record += bw ;
|
||||
++total_events ;
|
||||
|
||||
#ifdef NXS_NET_DEBUG_2
|
||||
std::cerr << "bandwidthRecorder::recordEvent() Recording event time=" << now << ". bw=" << bw << std::endl;
|
||||
#endif
|
||||
|
||||
// Every 20 seconds at min, compute a new estimate of the required bandwidth.
|
||||
|
||||
if(now > last_event_record + BANDWIDTH_ESTIMATE_DELAY*1000)
|
||||
{
|
||||
// Compute the bandwidth using recorded times, in msecs
|
||||
float speed = total_record/1024.0f/(now - last_event_record)*1000.0f ;
|
||||
|
||||
// Apply a small temporal convolution.
|
||||
estimated_required_bandwidth = 0.75*estimated_required_bandwidth + 0.25 * speed ;
|
||||
|
||||
#ifdef NXS_NET_DEBUG_2
|
||||
std::cerr << std::dec << " " << total_record << " Bytes (" << total_events << " items)"
|
||||
<< " received in " << now - last_event_record << " seconds. Speed: " << speed << " KBytes/sec" << std::endl;
|
||||
std::cerr << " instantaneous speed = " << speed << " KB/s" << std::endl;
|
||||
std::cerr << " cumulated estimated = " << estimated_required_bandwidth << " KB/s" << std::endl;
|
||||
#endif
|
||||
|
||||
last_event_record = now ;
|
||||
total_record = 0 ;
|
||||
total_events = 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
// Estimate the probability of sending an item so that the expected bandwidth matches the residual bandwidth
|
||||
|
||||
static float computeCurrentSendingProbability()
|
||||
{
|
||||
// FIXTESTS global variable rsConfig not available in unittests!
|
||||
if(rsConfig == 0)
|
||||
{
|
||||
std::cerr << "computeCurrentSendingProbability(): rsConfig not initialised, returning 1.0"<<std::endl;
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
int maxIn=50,maxOut=50;
|
||||
float currIn=0,currOut=0 ;
|
||||
|
||||
rsConfig->GetMaxDataRates(maxIn,maxOut) ;
|
||||
rsConfig->GetCurrentDataRates(currIn,currOut) ;
|
||||
|
||||
RsConfigDataRates rates ;
|
||||
rsConfig->getTotalBandwidthRates(rates) ;
|
||||
|
||||
#ifdef NXS_NET_DEBUG_2
|
||||
std::cerr << std::dec << std::endl;
|
||||
#endif
|
||||
|
||||
float outqueue_factor = 1.0f/pow( std::max(0.02f,rates.mQueueOut / (float)OUTQUEUE_CUTOFF_VALUE),5.0f) ;
|
||||
float accepted_bandwidth = std::max( 0.0f, maxOut - currOut) ;
|
||||
float max_bandwidth_factor = std::min( accepted_bandwidth / estimated_required_bandwidth,1.0f ) ;
|
||||
|
||||
// We account for two things here:
|
||||
// 1 - the required max bandwidth
|
||||
// 2 - the current network overload, measured from the size of the outqueues.
|
||||
//
|
||||
// Only the later can limit the traffic if the internet connexion speed is responsible for outqueue overloading.
|
||||
|
||||
float sending_probability = std::min(outqueue_factor,max_bandwidth_factor) ;
|
||||
|
||||
#ifdef NXS_NET_DEBUG_2
|
||||
std::cerr << "bandwidthRecorder::computeCurrentSendingProbability()" << std::endl;
|
||||
std::cerr << " current required bandwidth : " << estimated_required_bandwidth << " KB/s" << std::endl;
|
||||
std::cerr << " max_bandwidth_factor : " << max_bandwidth_factor << std::endl;
|
||||
std::cerr << " outqueue size : " << rates.mQueueOut << ", factor=" << outqueue_factor << std::endl;
|
||||
std::cerr << " max out : " << maxOut << ", currOut=" << currOut << std::endl;
|
||||
std::cerr << " computed probability : " << sending_probability << std::endl;
|
||||
#endif
|
||||
|
||||
return sending_probability ;
|
||||
}
|
||||
|
||||
private:
|
||||
static RsMutex mtx;
|
||||
static uint64_t last_event_record ;
|
||||
static float estimated_required_bandwidth ;
|
||||
static uint32_t total_events ;
|
||||
static uint64_t total_record ;
|
||||
};
|
||||
|
||||
uint32_t NxsBandwidthRecorder::total_events =0 ; // total number of events. Not used.
|
||||
uint64_t NxsBandwidthRecorder::last_event_record = time(NULL) * 1000;// starting time of bw estimate period (in msec)
|
||||
uint64_t NxsBandwidthRecorder::total_record =0 ; // total bytes recorded in the current time frame
|
||||
float NxsBandwidthRecorder::estimated_required_bandwidth = 10.0f ;// Estimated BW for sending sync data. Set to 10KB/s, to avoid 0.
|
||||
RsMutex NxsBandwidthRecorder::mtx("Bandwidth recorder") ; // Protects the recorder since bw events are collected from multiple GXS Net services
|
||||
|
||||
// temporary holds a map of pointers to class T, and destroys all pointers on delete.
|
||||
|
||||
template<class T>
|
||||
@ -657,8 +543,6 @@ void RsGxsNetService::syncWithPeers()
|
||||
grp->PeerId(*sit);
|
||||
grp->updateTS = updateTS;
|
||||
|
||||
//NxsBandwidthRecorder::recordEvent(mServType,grp) ;
|
||||
|
||||
#ifdef NXS_NET_DEBUG_5
|
||||
GXSNETDEBUG_P_(*sit) << "Service "<< std::hex << ((mServiceInfo.mServiceType >> 8)& 0xffff) << std::dec << " sending global group TS of peer id: " << *sit << " ts=" << nice_time_stamp(time(NULL),updateTS) << " (secs ago) to himself" << std::endl;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user