From 2fc09a90e7e62a4c3e4a67506bf90fcf4c6ccfaf Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 26 May 2018 21:28:55 +0200 Subject: Remove unused time-tracking from http method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Stats method isn't called anywhere, was partly commented out before, but we keep updating the time for it – lets avoid this pointless busywork. Gbp-Dch: Ignore --- methods/http.cc | 17 ----------------- methods/http.h | 3 --- 2 files changed, 20 deletions(-) (limited to 'methods') diff --git a/methods/http.cc b/methods/http.cc index 3862497a8..1933d9d00 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -134,8 +134,6 @@ bool CircleBuf::Read(std::unique_ptr const &Fd) return false; } - if (InP == 0) - gettimeofday(&Start,0); InP += Res; } } @@ -267,21 +265,6 @@ bool CircleBuf::Write(string &Data) return true; } /*}}}*/ -// CircleBuf::Stats - Print out stats information /*{{{*/ -// --------------------------------------------------------------------- -/* */ -void CircleBuf::Stats() -{ - if (InP == 0) - return; - - struct timeval Stop; - gettimeofday(&Stop,0); -/* float Diff = Stop.tv_sec - Start.tv_sec + - (float)(Stop.tv_usec - Start.tv_usec)/1000000; - clog << "Got " << InP << " in " << Diff << " at " << InP/Diff << endl;*/ -} - /*}}}*/ CircleBuf::~CircleBuf() /*{{{*/ { delete [] Buf; diff --git a/methods/http.h b/methods/http.h index d511196e3..ae6cedc13 100644 --- a/methods/http.h +++ b/methods/http.h @@ -36,7 +36,6 @@ class CircleBuf std::string OutQueue; unsigned long long StrPos; unsigned long long MaxGet; - struct timeval Start; static unsigned long long BwReadLimit; static unsigned long long BwTickReadData; @@ -85,8 +84,6 @@ class CircleBuf bool WriteSpace() const {return InP - OutP > 0;}; void Reset(); - // Dump everything - void Stats(); CircleBuf(HttpMethod const * const Owner, unsigned long long Size); ~CircleBuf(); -- cgit v1.2.3 From f6655a1138a11e80884959014939a25f23a1e308 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 26 May 2018 21:26:03 +0200 Subject: Use steady clock source for bandwidth limitation Using the time of day for this is slightly wrong just like it is for progress, just less visible. --- methods/http.cc | 18 +++++++++--------- methods/http.h | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'methods') diff --git a/methods/http.cc b/methods/http.cc index 1933d9d00..2e7fca307 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -49,7 +50,7 @@ using namespace std; unsigned long long CircleBuf::BwReadLimit=0; unsigned long long CircleBuf::BwTickReadData=0; -struct timeval CircleBuf::BwReadTick={0,0}; +std::chrono::steady_clock::duration CircleBuf::BwReadTick{0}; const unsigned int CircleBuf::BW_HZ=10; // CircleBuf::CircleBuf - Circular input buffer /*{{{*/ @@ -98,18 +99,17 @@ bool CircleBuf::Read(std::unique_ptr const &Fd) unsigned long long const BwReadMax = CircleBuf::BwReadLimit/BW_HZ; if(CircleBuf::BwReadLimit) { - struct timeval now; - gettimeofday(&now,0); + auto const now = std::chrono::steady_clock::now().time_since_epoch(); + auto const d = now - CircleBuf::BwReadTick; - unsigned long long d = (now.tv_sec-CircleBuf::BwReadTick.tv_sec)*1000000 + - now.tv_usec-CircleBuf::BwReadTick.tv_usec; - if(d > 1000000/BW_HZ) { + auto const tickLen = std::chrono::microseconds(std::chrono::seconds(1)) / BW_HZ; + if(d > tickLen) { CircleBuf::BwReadTick = now; CircleBuf::BwTickReadData = 0; - } - + } + if(CircleBuf::BwTickReadData >= BwReadMax) { - usleep(1000000/BW_HZ); + usleep(tickLen.count()); return true; } } diff --git a/methods/http.h b/methods/http.h index ae6cedc13..5668f0b87 100644 --- a/methods/http.h +++ b/methods/http.h @@ -12,6 +12,7 @@ #include +#include #include #include #include @@ -39,7 +40,7 @@ class CircleBuf static unsigned long long BwReadLimit; static unsigned long long BwTickReadData; - static struct timeval BwReadTick; + static std::chrono::steady_clock::duration BwReadTick; static const unsigned int BW_HZ; unsigned long long LeftRead() const -- cgit v1.2.3