new computing for download and upload rate. No more indiv rate settings

Merge branch 'maxUploadRate'

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1293 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
joss17 2009-06-08 17:09:00 +00:00
parent 9d0f90d434
commit 646603d71d
13 changed files with 381 additions and 542 deletions

View File

@ -30,6 +30,7 @@
#include <sstream>
#include "util/rsdebug.h"
#include <stdlib.h>
const int pqihandlerzone = 34283;
/****
@ -553,184 +554,99 @@ int pqihandler::UpdateRates()
float avail_in = getMaxRate(true);
float avail_out = getMaxRate(false);
float avg_rate_in = avail_in/num_sm;
float avg_rate_out = avail_out/num_sm;
float indiv_in = getMaxIndivRate(true);
float indiv_out = getMaxIndivRate(false);
float used_bw_in = 0;
float used_bw_out = 0;
float extra_bw_in = 0;
float extra_bw_out = 0;
int maxxed_in = 0;
int maxxed_out = 0;
/* Lock once rates have been retrieved */
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
// loop through modules....
int effectiveUploadsSm = 0;
int effectiveDownloadsSm = 0;
// loop through modules to get the used bandwith and the number of modules that are affectively transfering
//std::cerr << " Looping through modules" << std::endl;
for(it = mods.begin(); it != mods.end(); it++)
{
SearchModule *mod = (it -> second);
float crate_in = mod -> pqi -> getRate(true);
if (crate_in > 0.01 * avail_in || crate_in > 0.1)
{
effectiveDownloadsSm ++;
}
float crate_out = mod -> pqi -> getRate(false);
if (crate_out > 0.01 * avail_out || crate_out > 0.1)
{
effectiveUploadsSm ++;
}
used_bw_in += crate_in;
used_bw_out += crate_out;
if (crate_in > avg_rate_in)
{
if (mod -> pqi -> getMaxRate(true) == indiv_in)
{
maxxed_in++;
}
extra_bw_in += crate_in - avg_rate_in;
}
if (crate_out > avg_rate_out)
{
if (mod -> pqi -> getMaxRate(false) == indiv_out)
{
maxxed_out++;
}
extra_bw_out += crate_out - avg_rate_out;
}
//std::cerr << "\tSM(" << mod -> smi << ")";
//std::cerr << "In A: " << mod -> pqi -> getMaxRate(true);
//std::cerr << " C: " << crate_in;
//std::cerr << " && Out A: " << mod -> pqi -> getMaxRate(false);
//std::cerr << " C: " << crate_out << std::endl;
}
//std::cerr << "Totals (In) Used B/W " << used_bw_in;
//std::cerr << " Excess B/W " << extra_bw_in;
//std::cerr << " Available B/W " << avail_in << std::endl;
//std::cerr << "Totals (Out) Used B/W " << used_bw_out;
//std::cerr << " Excess B/W " << extra_bw_out;
//std::cerr << " Available B/W " << avail_out << std::endl;
// std::cerr << "Totals (In) Used B/W " << used_bw_in;
// std::cerr << " Available B/W " << avail_in;
// std::cerr << " Effective transfers " << effectiveDownloadsSm << std::endl;
// std::cerr << "Totals (Out) Used B/W " << used_bw_out;
// std::cerr << " Available B/W " << avail_out;
// std::cerr << " Effective transfers " << effectiveUploadsSm << std::endl;
locked_StoreCurrentRates(used_bw_in, used_bw_out);
if (used_bw_in > avail_in)
{
//std::cerr << "Decreasing Incoming B/W!" << std::endl;
// drop all above the avg down!
float fchg = (used_bw_in - avail_in) / (float) extra_bw_in;
for(it = mods.begin(); it != mods.end(); it++)
{
SearchModule *mod = (it -> second);
float crate_in = mod -> pqi -> getRate(true);
float new_max = avg_rate_in;
if (crate_in > avg_rate_in)
{
new_max = avg_rate_in + (1 - fchg) *
(crate_in - avg_rate_in);
}
if (new_max > indiv_in)
{
new_max = indiv_in;
}
mod -> pqi -> setMaxRate(true, new_max);
}
//computing average rates for effective transfers
float max_in_effective = avail_in / num_sm;
if (effectiveDownloadsSm != 0) {
max_in_effective = avail_in / effectiveDownloadsSm;
}
// if not maxxed already and using less than 95%
else if ((maxxed_in != num_sm) && (used_bw_in < 0.95 * avail_in))
{
//std::cerr << "Increasing Incoming B/W!" << std::endl;
// increase.
float fchg = (avail_in - used_bw_in) / avail_in;
for(it = mods.begin(); it != mods.end(); it++)
{
SearchModule *mod = (it -> second);
float crate_in = mod -> pqi -> getRate(true);
float max_in = mod -> pqi -> getMaxRate(true);
if (max_in == indiv_in)
{
// do nothing...
}
else
{
float new_max = max_in;
if (max_in < avg_rate_in)
{
new_max = avg_rate_in * (1 + fchg);
}
else if (crate_in > 0.5 * max_in)
{
new_max = max_in * (1 + fchg);
}
if (new_max > indiv_in)
{
new_max = indiv_in;
}
mod -> pqi -> setMaxRate(true, new_max);
}
}
float max_out_effective = avail_out / num_sm;
if (effectiveUploadsSm != 0) {
max_out_effective = avail_out / effectiveUploadsSm;
}
if (used_bw_out > avail_out)
{
//std::cerr << "Decreasing Outgoing B/W!" << std::endl;
// drop all above the avg down!
float fchg = (used_bw_out - avail_out) / (float) extra_bw_out;
for(it = mods.begin(); it != mods.end(); it++)
{
SearchModule *mod = (it -> second);
float crate_out = mod -> pqi -> getRate(false);
float new_max = avg_rate_out;
if (crate_out > avg_rate_out)
{
new_max = avg_rate_out + (1 - fchg) *
(crate_out - avg_rate_out);
}
if (new_max > indiv_out)
{
new_max = indiv_out;
}
mod -> pqi -> setMaxRate(false, new_max);
}
//modify the outgoing rates if bandwith is not used well
float rate_out_modifier = 0;
if (used_bw_out / avail_out < 0.95) {
rate_out_modifier = 0.001 * avail_out;
} else if (used_bw_out / avail_out > 1.05) {
rate_out_modifier = - 0.001 * avail_out;
}
// if not maxxed already and using less than 95%
else if ((maxxed_out != num_sm) && (used_bw_out < 0.95 * avail_out))
if (rate_out_modifier != 0) {
for(it = mods.begin(); it != mods.end(); it++)
{
SearchModule *mod = (it -> second);
mod -> pqi -> setMaxRate(false, mod -> pqi -> getMaxRate(false) + rate_out_modifier);
}
}
//modify the incoming rates if bandwith is not used well
float rate_in_modifier = 0;
if (used_bw_in / avail_in < 0.95) {
rate_in_modifier = 0.001 * avail_in;
} else if (used_bw_in / avail_in > 1.05) {
rate_in_modifier = - 0.001 * avail_in;
}
if (rate_in_modifier != 0) {
for(it = mods.begin(); it != mods.end(); it++)
{
SearchModule *mod = (it -> second);
mod -> pqi -> setMaxRate(true, mod -> pqi -> getMaxRate(true) + rate_in_modifier);
}
}
//cap the rates
for(it = mods.begin(); it != mods.end(); it++)
{
//std::cerr << "Increasing Outgoing B/W!" << std::endl;
// increase.
float fchg = (avail_out - used_bw_out) / avail_out;
for(it = mods.begin(); it != mods.end(); it++)
{
SearchModule *mod = (it -> second);
float crate_out = mod -> pqi -> getRate(false);
float max_out = mod -> pqi -> getMaxRate(false);
if (max_out == indiv_out)
{
// do nothing...
}
else
{
float new_max = max_out;
if (max_out < avg_rate_out)
{
new_max = avg_rate_out * (1 + fchg);
}
else if (crate_out > 0.5 * max_out)
{
new_max = max_out * (1 + fchg);
}
if (new_max > indiv_out)
{
new_max = indiv_out;
}
mod -> pqi -> setMaxRate(false, new_max);
}
SearchModule *mod = (it -> second);
if (mod -> pqi -> getMaxRate(false) < max_out_effective) {
mod -> pqi -> setMaxRate(false, max_out_effective);
}
if (mod -> pqi -> getMaxRate(false) > avail_out) {
mod -> pqi -> setMaxRate(false, avail_out);
}
if (mod -> pqi -> getMaxRate(true) < max_in_effective) {
mod -> pqi -> setMaxRate(true, max_in_effective);
}
if (mod -> pqi -> getMaxRate(true) > avail_in) {
mod -> pqi -> setMaxRate(true, avail_in);
}
}
return 1;

View File

@ -75,8 +75,9 @@ virtual int SendRsRawItem(RsRawItem *);
virtual RsRawItem *GetRsRawItem();
// rate control.
void setMaxIndivRate(bool in, float val);
float getMaxIndivRate(bool in);
//indiv rate is deprecated
//void setMaxIndivRate(bool in, float val);
//float getMaxIndivRate(bool in);
void setMaxRate(bool in, float val);
float getMaxRate(bool in);
@ -118,24 +119,24 @@ void locked_StoreCurrentRates(float in, float out);
float rateTotal_out;
};
inline void pqihandler::setMaxIndivRate(bool in, float val)
{
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
if (in)
rateIndiv_in = val;
else
rateIndiv_out = val;
return;
}
inline float pqihandler::getMaxIndivRate(bool in)
{
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
if (in)
return rateIndiv_in;
else
return rateIndiv_out;
}
//inline void pqihandler::setMaxIndivRate(bool in, float val)
//{
// RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
// if (in)
// rateIndiv_in = val;
// else
// rateIndiv_out = val;
// return;
//}
//
//inline float pqihandler::getMaxIndivRate(bool in)
//{
// RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
// if (in)
// return rateIndiv_in;
// else
// return rateIndiv_out;
//}
inline void pqihandler::setMaxRate(bool in, float val)
{

View File

@ -223,8 +223,7 @@ static const std::string pqih_ftr("PQIH_FTR");
int pqipersongrp::save_config()
{
char line[512];
sprintf(line, "%f %f %f %f", getMaxRate(true), getMaxRate(false),
getMaxIndivRate(true), getMaxIndivRate(false));
sprintf(line, "%f %f", getMaxRate(true), getMaxRate(false));
if (config)
{
config -> setSetting(pqih_ftr, std::string(line));
@ -240,14 +239,12 @@ int pqipersongrp::load_config()
line = config -> getSetting(pqih_ftr);
}
float mri, mro, miri, miro;
if (4 == sscanf(line.c_str(), "%f %f %f %f", &mri, &mro, &miri, &miro))
float mri, mro;
if (2 == sscanf(line.c_str(), "%f %f", &mri, &mro))
{
setMaxRate(true, mri);
setMaxRate(false, mro);
setMaxIndivRate(true, miri);
setMaxIndivRate(false, miro);
}
else
{
@ -256,8 +253,6 @@ int pqipersongrp::load_config()
setMaxRate(true, 500.0);
setMaxRate(false, 500.0);
setMaxIndivRate(true, 100.0);
setMaxIndivRate(false, 100.0);
}
return 1;

View File

@ -171,7 +171,7 @@ class RsControl /* The Main Interface Class - for controlling the server */
/****************************************/
/* Config */
virtual int ConfigSetDataRates( int total, int indiv ) = 0;
virtual int ConfigSetDataRates( int totalDownload, int totalUpload ) = 0;
virtual int ConfigGetDataRates( float &inKb, float &outKb) = 0;
virtual int ConfigSetBootPrompt( bool on ) = 0;
virtual void ConfigFinalSave( ) = 0;

View File

@ -126,7 +126,8 @@ class RsConfig
bool firewalled;
bool forwardPort;
int maxDataRate; /* kb */
int maxDownloadDataRate; /* kb */
int maxUploadDataRate; /* kb */
int maxIndivDataRate; /* kb */
int promptAtBoot; /* popup the password prompt */

View File

@ -41,7 +41,7 @@ const int p3facemsgzone = 11453;
/* RsIface Config */
/* Config */
int RsServer::ConfigSetDataRates( int total, int indiv ) /* in kbrates */
int RsServer::ConfigSetDataRates( int totalDownload, int totalUpload ) /* in kbrates */
{
/* fill the rsiface class */
RsIface &iface = getIface();
@ -50,10 +50,8 @@ int RsServer::ConfigSetDataRates( int total, int indiv ) /* in kbrates */
lockRsCore(); /* LOCK */
iface.lockData(); /* LOCK */
pqih -> setMaxRate(true, total);
pqih -> setMaxRate(false, total);
pqih -> setMaxIndivRate(true, indiv);
pqih -> setMaxIndivRate(false, indiv);
pqih -> setMaxRate(true, totalDownload);
pqih -> setMaxRate(false, totalUpload);
pqih -> save_config();
@ -120,8 +118,9 @@ int RsServer::UpdateAllConfig()
config.extPort = ntohs(pstate.serveraddr.sin_port);
/* data rates */
config.maxDataRate = (int) pqih -> getMaxRate(true); /* kb */
config.maxIndivDataRate = (int) pqih -> getMaxIndivRate(true);/* kb */
config.maxDownloadDataRate = (int) pqih -> getMaxRate(true); /* kb */
config.maxUploadDataRate = (int) pqih -> getMaxRate(false); /* kb */
config.promptAtBoot = true; /* popup the password prompt */
/* update network configuration */

View File

@ -137,7 +137,7 @@ class RsServer: public RsControl, public RsThread
/* Config */
virtual int ConfigGetDataRates(float &inKb, float &outKb);
virtual int ConfigSetDataRates( int total, int indiv );
virtual int ConfigSetDataRates( int totalDownload, int totalUpload );
virtual int ConfigSetBootPrompt( bool on );
virtual void ConfigFinalSave( );

View File

@ -654,7 +654,9 @@ void PeersDialog::insertChat()
{
if (!rsMsgs->chatAvailable())
{
// std::cerr << "no chat available." << std::endl ;
#ifdef PEERS_DEBUG
std::cerr << "no chat available." << std::endl ;
#endif
return;
}

View File

@ -91,12 +91,6 @@ ServerDialog::save(QString &errmsg)
}
/** Change of maxDataRate limits the Individual Data Rate */
void ServerDialog::setMaximumIndivRate(int maximum) {
ui.indivRate->setMaximum(maximum);
}
/** Loads the settings for this page */
void ServerDialog::load()
{
@ -142,15 +136,8 @@ void ServerDialog::load()
rsiface->lockData(); /* Lock Interface */
ui.totalRate->setValue(rsiface->getConfig().maxDataRate);
ui.indivRate->setValue(rsiface->getConfig().maxIndivDataRate);
// It makes no sense to set the total transfer rate lower than the individual rate.
// Avoid this by setting the upper limit for individual rate to total transfer rate now,
// and every time the user changes the total transfer rate.
ui.indivRate->setMaximum(rsiface->getConfig().maxDataRate);
QObject::connect(ui.totalRate, SIGNAL (valueChanged(int)),
this, SLOT (setMaximumIndivRate(int)));
ui.totalDownloadRate->setValue(rsiface->getConfig().maxDownloadDataRate);
ui.totalUploadRate->setValue(rsiface->getConfig().maxUploadDataRate);
rsiface->unlockData(); /* UnLock Interface */
@ -371,7 +358,7 @@ void ServerDialog::saveAddresses()
rsPeers->setExtAddress(rsPeers->getOwnId(), ui.extAddress->text().toStdString(), ui.extPort->value());
}
rsicontrol->ConfigSetDataRates( ui.totalRate->value(), ui.indivRate->value() );
rsicontrol->ConfigSetDataRates( ui.totalDownloadRate->value(), ui.totalUploadRate->value() );
load();
}

View File

@ -50,7 +50,6 @@ private slots:
void saveAddresses();
void toggleUPnP();
void toggleIpDetermination(bool) ;
void setMaximumIndivRate(int);
private:
/** A RshareSettings object used for saving/loading settings */

File diff suppressed because it is too large Load Diff

View File

@ -171,7 +171,7 @@ class RsControl /* The Main Interface Class - for controlling the server */
/****************************************/
/* Config */
virtual int ConfigSetDataRates( int total, int indiv ) = 0;
virtual int ConfigSetDataRates( int totalDownload, int totalUpload ) = 0;
virtual int ConfigGetDataRates( float &inKb, float &outKb) = 0;
virtual int ConfigSetBootPrompt( bool on ) = 0;
virtual void ConfigFinalSave( ) = 0;

View File

@ -126,8 +126,8 @@ class RsConfig
bool firewalled;
bool forwardPort;
int maxDataRate; /* kb */
int maxIndivDataRate; /* kb */
int maxDownloadDataRate; /* kb */
int maxUploadDataRate; /* kb */
int promptAtBoot; /* popup the password prompt */