mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-26 07:59:35 -05:00
switched to floating point time for bandwidth estimation in pqistreamer. Helps a lot RTTs since rounding to int prveviously caused packets to be delayed up to 1 sec (improvement by Jollavilette)
This commit is contained in:
parent
20397c38ec
commit
c968490b43
@ -76,6 +76,19 @@ static uint8_t PACKET_SLICING_PROBE_BYTES[8] = { 0x02, 0xaa, 0xbb, 0xcc, 0x00,
|
|||||||
#include "util/rsprint.h"
|
#include "util/rsprint.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static double getCurrentTS()
|
||||||
|
{
|
||||||
|
#ifndef WINDOWS_SYS
|
||||||
|
struct timeval cts_tmp;
|
||||||
|
gettimeofday(&cts_tmp, NULL);
|
||||||
|
double cts = (cts_tmp.tv_sec) + ((double) cts_tmp.tv_usec) / 1000000.0;
|
||||||
|
#else
|
||||||
|
struct _timeb timebuf;
|
||||||
|
_ftime( &timebuf);
|
||||||
|
double cts = (timebuf.time) + ((double) timebuf.millitm) / 1000.0;
|
||||||
|
#endif
|
||||||
|
return cts;
|
||||||
|
}
|
||||||
|
|
||||||
pqistreamer::pqistreamer(RsSerialiser *rss, const RsPeerId& id, BinInterface *bio_in, int bio_flags_in)
|
pqistreamer::pqistreamer(RsSerialiser *rss, const RsPeerId& id, BinInterface *bio_in, int bio_flags_in)
|
||||||
:PQInterface(id), mStreamerMtx("pqistreamer"),
|
:PQInterface(id), mStreamerMtx("pqistreamer"),
|
||||||
@ -97,7 +110,9 @@ pqistreamer::pqistreamer(RsSerialiser *rss, const RsPeerId& id, BinInterface *bi
|
|||||||
mAcceptsPacketSlicing = false ; // by default. Will be turned into true when everyone's ready.
|
mAcceptsPacketSlicing = false ; // by default. Will be turned into true when everyone's ready.
|
||||||
mLastSentPacketSlicingProbe = 0 ;
|
mLastSentPacketSlicingProbe = 0 ;
|
||||||
|
|
||||||
mAvgLastUpdate = mCurrReadTS = mCurrSentTS = time(NULL);
|
mAvgLastUpdate = time(NULL);
|
||||||
|
mCurrSentTS = mCurrReadTS = getCurrentTS();
|
||||||
|
|
||||||
mIncomingSize = 0 ;
|
mIncomingSize = 0 ;
|
||||||
|
|
||||||
mStatisticsTimeStamp = 0 ;
|
mStatisticsTimeStamp = 0 ;
|
||||||
@ -1099,7 +1114,7 @@ float pqistreamer::outTimeSlice_locked()
|
|||||||
// very simple.....
|
// very simple.....
|
||||||
int pqistreamer::outAllowedBytes_locked()
|
int pqistreamer::outAllowedBytes_locked()
|
||||||
{
|
{
|
||||||
int t = time(NULL); // get current timestep.
|
double t = getCurrentTS() ; // Grabs today's time in sec, with ms accuracy. Allows a much more accurate allocation of bw
|
||||||
|
|
||||||
/* allow a lot if not bandwidthLimited */
|
/* allow a lot if not bandwidthLimited */
|
||||||
if (!mBio->bandwidthLimited())
|
if (!mBio->bandwidthLimited())
|
||||||
@ -1109,17 +1124,18 @@ int pqistreamer::outAllowedBytes_locked()
|
|||||||
return PQISTREAM_ABS_MAX;
|
return PQISTREAM_ABS_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dt = t - mCurrSentTS;
|
double dt = t - mCurrSentTS;
|
||||||
|
|
||||||
// limiter -> for when currSentTs -> 0.
|
// limiter -> for when currSentTs -> 0.
|
||||||
if (dt > 5)
|
if (dt > 5)
|
||||||
dt = 5;
|
dt = 5;
|
||||||
|
|
||||||
int maxout = (int) (getMaxRate(false) * 1000.0);
|
double maxout = getMaxRate(false) * 1024.0;
|
||||||
mCurrSent -= dt * maxout;
|
|
||||||
|
mCurrSent -= int(dt * maxout);
|
||||||
|
|
||||||
if (mCurrSent < 0)
|
if (mCurrSent < 0)
|
||||||
{
|
|
||||||
mCurrSent = 0;
|
mCurrSent = 0;
|
||||||
}
|
|
||||||
|
|
||||||
mCurrSentTS = t;
|
mCurrSentTS = t;
|
||||||
|
|
||||||
@ -1137,7 +1153,7 @@ int pqistreamer::outAllowedBytes_locked()
|
|||||||
|
|
||||||
int pqistreamer::inAllowedBytes_locked()
|
int pqistreamer::inAllowedBytes_locked()
|
||||||
{
|
{
|
||||||
int t = time(NULL); // get current timestep.
|
double t = getCurrentTS(); // in secs, with a ms accuracy
|
||||||
|
|
||||||
/* allow a lot if not bandwidthLimited */
|
/* allow a lot if not bandwidthLimited */
|
||||||
if (!mBio->bandwidthLimited())
|
if (!mBio->bandwidthLimited())
|
||||||
@ -1147,17 +1163,18 @@ int pqistreamer::inAllowedBytes_locked()
|
|||||||
return PQISTREAM_ABS_MAX;
|
return PQISTREAM_ABS_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dt = t - mCurrReadTS;
|
double dt = t - mCurrReadTS;
|
||||||
|
|
||||||
// limiter -> for when currReadTs -> 0.
|
// limiter -> for when currReadTs -> 0.
|
||||||
if (dt > 5)
|
if (dt > 5)
|
||||||
dt = 5;
|
dt = 5;
|
||||||
|
|
||||||
int maxin = (int) (getMaxRate(true) * 1000.0);
|
double maxin = getMaxRate(true) * 1024.0;
|
||||||
mCurrRead -= dt * maxin;
|
|
||||||
|
mCurrRead -= int(dt * maxin);
|
||||||
|
|
||||||
if (mCurrRead < 0)
|
if (mCurrRead < 0)
|
||||||
{
|
|
||||||
mCurrRead = 0;
|
mCurrRead = 0;
|
||||||
}
|
|
||||||
|
|
||||||
mCurrReadTS = t;
|
mCurrReadTS = t;
|
||||||
|
|
||||||
|
@ -159,8 +159,8 @@ class pqistreamer: public PQInterface
|
|||||||
int mCurrRead;
|
int mCurrRead;
|
||||||
int mCurrSent;
|
int mCurrSent;
|
||||||
|
|
||||||
time_t mCurrReadTS; // TS from which these are measured.
|
double mCurrReadTS; // TS from which these are measured.
|
||||||
time_t mCurrSentTS;
|
double mCurrSentTS;
|
||||||
|
|
||||||
time_t mAvgLastUpdate; // TS from which these are measured.
|
time_t mAvgLastUpdate; // TS from which these are measured.
|
||||||
uint32_t mAvgReadCount;
|
uint32_t mAvgReadCount;
|
||||||
|
Loading…
Reference in New Issue
Block a user