Browse Source

Minor cleanup. More efficient push() operation for RingBuffer

Joseph Henry 7 years ago
parent
commit
f8005b88ad
3 changed files with 9 additions and 11 deletions
  1. 0 7
      node/Path.hpp
  2. 2 2
      node/Peer.hpp
  3. 7 2
      node/RingBuffer.hpp

+ 0 - 7
node/Path.hpp

@@ -161,11 +161,9 @@ public:
 	{
 	{
 		delete _throughputSamples;
 		delete _throughputSamples;
 		delete _latencySamples;
 		delete _latencySamples;
-		delete _qualitySamples;
 		delete _packetValiditySamples;
 		delete _packetValiditySamples;
 		_throughputSamples = NULL;
 		_throughputSamples = NULL;
 		_latencySamples = NULL;
 		_latencySamples = NULL;
-		_qualitySamples = NULL;
 		_packetValiditySamples = NULL;
 		_packetValiditySamples = NULL;
 	}
 	}
 
 
@@ -580,7 +578,6 @@ public:
 	 * @param now Current time
 	 * @param now Current time
 	 */
 	 */
 	inline void processBackgroundPathMeasurements(int64_t now, const int64_t peerId) {
 	inline void processBackgroundPathMeasurements(int64_t now, const int64_t peerId) {
-		// Compute path stability
 		if (now - _lastPathQualityComputeTime > ZT_PATH_QUALITY_COMPUTE_INTERVAL) {
 		if (now - _lastPathQualityComputeTime > ZT_PATH_QUALITY_COMPUTE_INTERVAL) {
 			Mutex::Lock _l(_statistics_m);
 			Mutex::Lock _l(_statistics_m);
 			_lastPathQualityComputeTime = now;
 			_lastPathQualityComputeTime = now;
@@ -606,8 +603,6 @@ public:
 			// Compute the quality product
 			// Compute the quality product
 			_lastComputedStability = pdv_contrib + latency_contrib + throughput_disturbance_contrib;
 			_lastComputedStability = pdv_contrib + latency_contrib + throughput_disturbance_contrib;
 			_lastComputedStability *= 1 - _packetErrorRatio;
 			_lastComputedStability *= 1 - _packetErrorRatio;
-			_qualitySamples->push(_lastComputedStability);
-
 			// Prevent QoS records from sticking around for too long
 			// Prevent QoS records from sticking around for too long
 			std::map<uint64_t,uint64_t>::iterator it = _outQoSRecords.begin();
 			std::map<uint64_t,uint64_t>::iterator it = _outQoSRecords.begin();
 			while (it != _outQoSRecords.end()) {
 			while (it != _outQoSRecords.end()) {
@@ -650,7 +645,6 @@ public:
 	inline void prepareBuffers() {
 	inline void prepareBuffers() {
 		_throughputSamples = new RingBuffer<uint64_t>(ZT_PATH_QUALITY_METRIC_WIN_SZ);
 		_throughputSamples = new RingBuffer<uint64_t>(ZT_PATH_QUALITY_METRIC_WIN_SZ);
 		_latencySamples = new RingBuffer<uint32_t>(ZT_PATH_QUALITY_METRIC_WIN_SZ);
 		_latencySamples = new RingBuffer<uint32_t>(ZT_PATH_QUALITY_METRIC_WIN_SZ);
-		_qualitySamples = new RingBuffer<float>(ZT_PATH_QUALITY_METRIC_WIN_SZ);
 		_packetValiditySamples = new RingBuffer<bool>(ZT_PATH_QUALITY_METRIC_WIN_SZ);
 		_packetValiditySamples = new RingBuffer<bool>(ZT_PATH_QUALITY_METRIC_WIN_SZ);
 		memset(_ifname, 0, 16);
 		memset(_ifname, 0, 16);
 		memset(_addrString, 0, sizeof(_addrString));
 		memset(_addrString, 0, sizeof(_addrString));
@@ -704,7 +698,6 @@ private:
 
 
 	RingBuffer<uint64_t> *_throughputSamples;
 	RingBuffer<uint64_t> *_throughputSamples;
 	RingBuffer<uint32_t> *_latencySamples;
 	RingBuffer<uint32_t> *_latencySamples;
-	RingBuffer<float> *_qualitySamples;
 	RingBuffer<bool> *_packetValiditySamples;
 	RingBuffer<bool> *_packetValiditySamples;
 };
 };
 
 

+ 2 - 2
node/Peer.hpp

@@ -678,8 +678,8 @@ private:
 	bool _linkIsRedundant;
 	bool _linkIsRedundant;
 	bool _remotePeerMultipathEnabled;
 	bool _remotePeerMultipathEnabled;
 
 
-	uint64_t _lastAggregateStatsReport;
-	uint64_t _lastAggregateAllocation;
+	int64_t _lastAggregateStatsReport;
+	int64_t _lastAggregateAllocation;
 
 
 	char _interfaceListStr[256]; // 16 characters * 16 paths in a link
 	char _interfaceListStr[256]; // 16 characters * 16 paths in a link
 };
 };

+ 7 - 2
node/RingBuffer.hpp

@@ -37,7 +37,7 @@
 namespace ZeroTier {
 namespace ZeroTier {
 
 
 /**
 /**
- * A revolving (ring) buffer. 
+ * A circular buffer
  *
  *
  * For fast handling of continuously-evolving variables (such as path quality metrics).
  * For fast handling of continuously-evolving variables (such as path quality metrics).
  * Using this, we can maintain longer sliding historical windows for important path 
  * Using this, we can maintain longer sliding historical windows for important path 
@@ -169,7 +169,12 @@ public:
 		if (count() == size) {
 		if (count() == size) {
 			consume(1);
 			consume(1);
 		}
 		}
-		write(&value, 1);
+		const size_t first_chunk = std::min((size_t)1, size - end);
+		*(buf + end) = value;
+		end = (end + first_chunk) % size;
+		if (begin == end) {
+			wrap = true;
+		}
 	}
 	}
 
 
 	/**
 	/**