mirror of
https://github.com/xmrig/xmrig.git
synced 2026-04-18 05:22:28 -04:00
Merge branch 'master' of https://github.com/oxyzenQ/xmrig into pr3764
This commit is contained in:
@@ -210,7 +210,7 @@ void xmrig::NetworkState::printResults() const
|
||||
printHashes(m_accepted, m_hashes);
|
||||
printDiff(m_diff);
|
||||
|
||||
if (m_active && !m_latency.empty()) {
|
||||
if (m_active && m_latencyCount > 0) {
|
||||
printAvgTime(avgTime());
|
||||
}
|
||||
|
||||
@@ -298,13 +298,19 @@ void xmrig::NetworkState::onResultAccepted(IStrategy *strategy, IClient *client,
|
||||
|
||||
uint32_t xmrig::NetworkState::latency() const
|
||||
{
|
||||
const size_t calls = m_latency.size();
|
||||
const size_t calls = m_latencyCount;
|
||||
if (calls == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto v = m_latency;
|
||||
std::nth_element(v.begin(), v.begin() + calls / 2, v.end());
|
||||
std::array<uint16_t, kLatencyWindow> v;
|
||||
const size_t start = (m_latencyPos + kLatencyWindow - calls) % kLatencyWindow;
|
||||
|
||||
for (size_t i = 0; i < calls; ++i) {
|
||||
v[i] = m_latency[(start + i) % kLatencyWindow];
|
||||
}
|
||||
|
||||
std::nth_element(v.begin(), v.begin() + calls / 2, v.begin() + calls);
|
||||
|
||||
return v[calls / 2];
|
||||
}
|
||||
@@ -312,11 +318,11 @@ uint32_t xmrig::NetworkState::latency() const
|
||||
|
||||
uint64_t xmrig::NetworkState::avgTime() const
|
||||
{
|
||||
if (m_latency.empty()) {
|
||||
if (m_latencyCount == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return connectionTime() / m_latency.size();
|
||||
return connectionTime() / m_latencyCount;
|
||||
}
|
||||
|
||||
|
||||
@@ -342,7 +348,12 @@ void xmrig::NetworkState::add(const SubmitResult &result, const char *error)
|
||||
std::sort(m_topDiff.rbegin(), m_topDiff.rend());
|
||||
}
|
||||
|
||||
m_latency.push_back(result.elapsed > 0xFFFF ? 0xFFFF : static_cast<uint16_t>(result.elapsed));
|
||||
m_latency[m_latencyPos] = result.elapsed > 0xFFFF ? 0xFFFF : static_cast<uint16_t>(result.elapsed);
|
||||
m_latencyPos = (m_latencyPos + 1) % kLatencyWindow;
|
||||
|
||||
if (m_latencyCount < kLatencyWindow) {
|
||||
m_latencyCount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -355,5 +366,6 @@ void xmrig::NetworkState::stop()
|
||||
m_fingerprint = nullptr;
|
||||
|
||||
m_failures++;
|
||||
m_latency.clear();
|
||||
m_latencyCount = 0;
|
||||
m_latencyPos = 0;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
@@ -60,6 +59,8 @@ protected:
|
||||
void onResultAccepted(IStrategy *strategy, IClient *client, const SubmitResult &result, const char *error) override;
|
||||
|
||||
private:
|
||||
constexpr static size_t kLatencyWindow = 1024;
|
||||
|
||||
uint32_t latency() const;
|
||||
uint64_t avgTime() const;
|
||||
uint64_t connectionTime() const;
|
||||
@@ -70,7 +71,9 @@ private:
|
||||
bool m_active = false;
|
||||
char m_pool[256]{};
|
||||
std::array<uint64_t, 10> m_topDiff { { } };
|
||||
std::vector<uint16_t> m_latency;
|
||||
std::array<uint16_t, kLatencyWindow> m_latency { { } };
|
||||
size_t m_latencyCount = 0;
|
||||
size_t m_latencyPos = 0;
|
||||
String m_fingerprint;
|
||||
String m_ip;
|
||||
String m_tls;
|
||||
|
||||
Reference in New Issue
Block a user