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 <sstream>
#include "util/rsdebug.h" #include "util/rsdebug.h"
#include <stdlib.h>
const int pqihandlerzone = 34283; const int pqihandlerzone = 34283;
/**** /****
@ -553,184 +554,99 @@ int pqihandler::UpdateRates()
float avail_in = getMaxRate(true); float avail_in = getMaxRate(true);
float avail_out = getMaxRate(false); 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_in = 0;
float used_bw_out = 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 */ /* Lock once rates have been retrieved */
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ 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++) for(it = mods.begin(); it != mods.end(); it++)
{ {
SearchModule *mod = (it -> second); SearchModule *mod = (it -> second);
float crate_in = mod -> pqi -> getRate(true); 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); 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_in += crate_in;
used_bw_out += crate_out; 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 << "Totals (In) Used B/W " << used_bw_in;
//std::cerr << " Excess B/W " << extra_bw_in; // std::cerr << " Available B/W " << avail_in;
//std::cerr << " Available B/W " << avail_in << std::endl; // std::cerr << " Effective transfers " << effectiveDownloadsSm << std::endl;
//std::cerr << "Totals (Out) Used B/W " << used_bw_out; // 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::cerr << " Available B/W " << avail_out << std::endl; // std::cerr << " Effective transfers " << effectiveUploadsSm << std::endl;
locked_StoreCurrentRates(used_bw_in, used_bw_out); locked_StoreCurrentRates(used_bw_in, used_bw_out);
if (used_bw_in > avail_in) //computing average rates for effective transfers
{ float max_in_effective = avail_in / num_sm;
//std::cerr << "Decreasing Incoming B/W!" << std::endl; if (effectiveDownloadsSm != 0) {
max_in_effective = avail_in / effectiveDownloadsSm;
// 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);
}
} }
// if not maxxed already and using less than 95% float max_out_effective = avail_out / num_sm;
else if ((maxxed_in != num_sm) && (used_bw_in < 0.95 * avail_in)) if (effectiveUploadsSm != 0) {
{ max_out_effective = avail_out / effectiveUploadsSm;
//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);
}
}
} }
//modify the outgoing rates if bandwith is not used well
if (used_bw_out > avail_out) float rate_out_modifier = 0;
{ if (used_bw_out / avail_out < 0.95) {
//std::cerr << "Decreasing Outgoing B/W!" << std::endl; rate_out_modifier = 0.001 * avail_out;
// drop all above the avg down! } else if (used_bw_out / avail_out > 1.05) {
float fchg = (used_bw_out - avail_out) / (float) extra_bw_out; rate_out_modifier = - 0.001 * avail_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);
}
} }
// if not maxxed already and using less than 95% if (rate_out_modifier != 0) {
else if ((maxxed_out != num_sm) && (used_bw_out < 0.95 * avail_out)) 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; SearchModule *mod = (it -> second);
// increase. if (mod -> pqi -> getMaxRate(false) < max_out_effective) {
float fchg = (avail_out - used_bw_out) / avail_out; mod -> pqi -> setMaxRate(false, max_out_effective);
for(it = mods.begin(); it != mods.end(); it++) }
{ if (mod -> pqi -> getMaxRate(false) > avail_out) {
SearchModule *mod = (it -> second); mod -> pqi -> setMaxRate(false, avail_out);
float crate_out = mod -> pqi -> getRate(false); }
float max_out = mod -> pqi -> getMaxRate(false); if (mod -> pqi -> getMaxRate(true) < max_in_effective) {
mod -> pqi -> setMaxRate(true, max_in_effective);
if (max_out == indiv_out) }
{ if (mod -> pqi -> getMaxRate(true) > avail_in) {
// do nothing... mod -> pqi -> setMaxRate(true, avail_in);
}
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);
}
} }
} }
return 1; return 1;

View File

@ -75,8 +75,9 @@ virtual int SendRsRawItem(RsRawItem *);
virtual RsRawItem *GetRsRawItem(); virtual RsRawItem *GetRsRawItem();
// rate control. // rate control.
void setMaxIndivRate(bool in, float val); //indiv rate is deprecated
float getMaxIndivRate(bool in); //void setMaxIndivRate(bool in, float val);
//float getMaxIndivRate(bool in);
void setMaxRate(bool in, float val); void setMaxRate(bool in, float val);
float getMaxRate(bool in); float getMaxRate(bool in);
@ -118,24 +119,24 @@ void locked_StoreCurrentRates(float in, float out);
float rateTotal_out; float rateTotal_out;
}; };
inline void pqihandler::setMaxIndivRate(bool in, float val) //inline void pqihandler::setMaxIndivRate(bool in, float val)
{ //{
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ // RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
if (in) // if (in)
rateIndiv_in = val; // rateIndiv_in = val;
else // else
rateIndiv_out = val; // rateIndiv_out = val;
return; // return;
} //}
//
inline float pqihandler::getMaxIndivRate(bool in) //inline float pqihandler::getMaxIndivRate(bool in)
{ //{
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ // RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
if (in) // if (in)
return rateIndiv_in; // return rateIndiv_in;
else // else
return rateIndiv_out; // return rateIndiv_out;
} //}
inline void pqihandler::setMaxRate(bool in, float val) 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() int pqipersongrp::save_config()
{ {
char line[512]; char line[512];
sprintf(line, "%f %f %f %f", getMaxRate(true), getMaxRate(false), sprintf(line, "%f %f", getMaxRate(true), getMaxRate(false));
getMaxIndivRate(true), getMaxIndivRate(false));
if (config) if (config)
{ {
config -> setSetting(pqih_ftr, std::string(line)); config -> setSetting(pqih_ftr, std::string(line));
@ -240,14 +239,12 @@ int pqipersongrp::load_config()
line = config -> getSetting(pqih_ftr); line = config -> getSetting(pqih_ftr);
} }
float mri, mro, miri, miro; float mri, mro;
if (4 == sscanf(line.c_str(), "%f %f %f %f", &mri, &mro, &miri, &miro)) if (2 == sscanf(line.c_str(), "%f %f", &mri, &mro))
{ {
setMaxRate(true, mri); setMaxRate(true, mri);
setMaxRate(false, mro); setMaxRate(false, mro);
setMaxIndivRate(true, miri);
setMaxIndivRate(false, miro);
} }
else else
{ {
@ -256,8 +253,6 @@ int pqipersongrp::load_config()
setMaxRate(true, 500.0); setMaxRate(true, 500.0);
setMaxRate(false, 500.0); setMaxRate(false, 500.0);
setMaxIndivRate(true, 100.0);
setMaxIndivRate(false, 100.0);
} }
return 1; return 1;

View File

@ -171,7 +171,7 @@ class RsControl /* The Main Interface Class - for controlling the server */
/****************************************/ /****************************************/
/* Config */ /* 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 ConfigGetDataRates( float &inKb, float &outKb) = 0;
virtual int ConfigSetBootPrompt( bool on ) = 0; virtual int ConfigSetBootPrompt( bool on ) = 0;
virtual void ConfigFinalSave( ) = 0; virtual void ConfigFinalSave( ) = 0;

View File

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

View File

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

View File

@ -137,7 +137,7 @@ class RsServer: public RsControl, public RsThread
/* Config */ /* Config */
virtual int ConfigGetDataRates(float &inKb, float &outKb); 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 int ConfigSetBootPrompt( bool on );
virtual void ConfigFinalSave( ); virtual void ConfigFinalSave( );

View File

@ -654,7 +654,9 @@ void PeersDialog::insertChat()
{ {
if (!rsMsgs->chatAvailable()) if (!rsMsgs->chatAvailable())
{ {
// std::cerr << "no chat available." << std::endl ; #ifdef PEERS_DEBUG
std::cerr << "no chat available." << std::endl ;
#endif
return; 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 */ /** Loads the settings for this page */
void ServerDialog::load() void ServerDialog::load()
{ {
@ -142,15 +136,8 @@ void ServerDialog::load()
rsiface->lockData(); /* Lock Interface */ rsiface->lockData(); /* Lock Interface */
ui.totalRate->setValue(rsiface->getConfig().maxDataRate); ui.totalDownloadRate->setValue(rsiface->getConfig().maxDownloadDataRate);
ui.indivRate->setValue(rsiface->getConfig().maxIndivDataRate); ui.totalUploadRate->setValue(rsiface->getConfig().maxUploadDataRate);
// 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)));
rsiface->unlockData(); /* UnLock Interface */ rsiface->unlockData(); /* UnLock Interface */
@ -371,7 +358,7 @@ void ServerDialog::saveAddresses()
rsPeers->setExtAddress(rsPeers->getOwnId(), ui.extAddress->text().toStdString(), ui.extPort->value()); 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(); load();
} }

View File

@ -50,7 +50,6 @@ private slots:
void saveAddresses(); void saveAddresses();
void toggleUPnP(); void toggleUPnP();
void toggleIpDetermination(bool) ; void toggleIpDetermination(bool) ;
void setMaximumIndivRate(int);
private: private:
/** A RshareSettings object used for saving/loading settings */ /** 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 */ /* 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 ConfigGetDataRates( float &inKb, float &outKb) = 0;
virtual int ConfigSetBootPrompt( bool on ) = 0; virtual int ConfigSetBootPrompt( bool on ) = 0;
virtual void ConfigFinalSave( ) = 0; virtual void ConfigFinalSave( ) = 0;

View File

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