Added benchmark and stress test

Easy to use and zero configuration embedded benchmark/stress test.
This commit is contained in:
SChernykh 2020-10-14 19:45:05 +02:00
parent 9fcc542676
commit 2ecece7b3d
28 changed files with 354 additions and 55 deletions

View file

@ -44,6 +44,7 @@ set(HEADERS_BASE
src/base/net/http/HttpListener.h
src/base/net/stratum/BaseClient.h
src/base/net/stratum/Client.h
src/base/net/stratum/NullClient.h
src/base/net/stratum/Job.h
src/base/net/stratum/NetworkState.h
src/base/net/stratum/Pool.h
@ -97,6 +98,7 @@ set(SOURCES_BASE
src/base/net/http/Http.cpp
src/base/net/stratum/BaseClient.cpp
src/base/net/stratum/Client.cpp
src/base/net/stratum/NullClient.cpp
src/base/net/stratum/Job.cpp
src/base/net/stratum/NetworkState.cpp
src/base/net/stratum/Pool.cpp

View file

@ -152,6 +152,8 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
break;
case IConfig::UrlKey: /* --url */
case IConfig::StressKey: /* --stress */
case IConfig::BenchKey: /* --bench */
{
if (!doc.HasMember(Pools::kPools)) {
doc.AddMember(rapidjson::StringRef(Pools::kPools), rapidjson::kArrayType, doc.GetAllocator());
@ -162,7 +164,19 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
array.PushBack(rapidjson::kObjectType, doc.GetAllocator());
}
set(doc, array[array.Size() - 1], Pool::kUrl, arg);
if (key == IConfig::UrlKey) {
set(doc, array[array.Size() - 1], Pool::kUrl, arg);
}
else {
set(doc, array[array.Size() - 1], Pool::kUrl, (key == IConfig::BenchKey) ? "offline" : "donate.v2.xmrig.com:3333");
set(doc, "cpu", "huge-pages-jit", true);
set(doc, "cpu", "priority", 2);
set(doc, "cpu", "yield", false);
if (key == IConfig::BenchKey) {
set(doc, array[array.Size() - 1], Pool::kBenchmark, arg);
}
}
break;
}

View file

@ -77,6 +77,8 @@ public:
TitleKey = 1037,
NoTitleKey = 1038,
PauseOnBatteryKey = 1041,
StressKey = 1042,
BenchKey = 1043,
// xmrig common
CPUPriorityKey = 1021,

View file

@ -154,6 +154,7 @@ void xmrig::Job::copy(const Job &other)
{
m_algorithm = other.m_algorithm;
m_nicehash = other.m_nicehash;
m_bench = other.m_bench;
m_size = other.m_size;
m_clientId = other.m_clientId;
m_id = other.m_id;
@ -181,6 +182,7 @@ void xmrig::Job::move(Job &&other)
{
m_algorithm = other.m_algorithm;
m_nicehash = other.m_nicehash;
m_bench = other.m_bench;
m_size = other.m_size;
m_clientId = std::move(other.m_clientId);
m_id = std::move(other.m_id);

View file

@ -87,6 +87,7 @@ public:
inline uint8_t *blob() { return m_blob; }
inline uint8_t fixedByte() const { return *(m_blob + 42); }
inline uint8_t index() const { return m_index; }
inline uint32_t bench() const { return m_bench; }
inline void reset() { m_size = 0; m_diff = 0; }
inline void setAlgorithm(const Algorithm::Id id) { m_algorithm = id; }
inline void setAlgorithm(const char *algo) { m_algorithm = algo; }
@ -96,6 +97,7 @@ public:
inline void setHeight(uint64_t height) { m_height = height; }
inline void setIndex(uint8_t index) { m_index = index; }
inline void setPoolWallet(const String &poolWallet) { m_poolWallet = poolWallet; }
inline void setBench(uint32_t bench) { m_bench = bench; }
# ifdef XMRIG_PROXY_PROJECT
inline char *rawBlob() { return m_rawBlob; }
@ -117,6 +119,7 @@ private:
Algorithm m_algorithm;
bool m_nicehash = false;
uint32_t m_bench = 0;
Buffer m_seed;
size_t m_size = 0;
String m_clientId;

View file

@ -0,0 +1,63 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "3rdparty/rapidjson/document.h"
#include "base/net/stratum/NullClient.h"
#include "base/kernel/interfaces/IClientListener.h"
xmrig::NullClient::NullClient(IClientListener* listener) :
m_listener(listener)
{
m_job.setAlgorithm(Algorithm::RX_0);
std::vector<char> blob(112 * 2 + 1, '0');
blob.back() = '\0';
m_job.setBlob(blob.data());
blob[Job::kMaxSeedSize * 2] = '\0';
m_job.setSeedHash(blob.data());
m_job.setDiff(uint64_t(-1));
m_job.setHeight(1);
m_job.setId("00000000");
}
void xmrig::NullClient::connect()
{
m_listener->onLoginSuccess(this);
rapidjson::Value params;
m_listener->onJobReceived(this, m_job, params);
}
void xmrig::NullClient::setPool(const Pool& pool)
{
m_pool = pool;
if (!m_pool.algorithm().isValid()) {
m_pool.setAlgo(Algorithm::RX_0);
}
m_job.setAlgorithm(m_pool.algorithm().id());
m_job.setBench(m_pool.benchSize());
}

View file

@ -0,0 +1,77 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_NULLCLIENT_H
#define XMRIG_NULLCLIENT_H
#include "base/net/stratum/Client.h"
namespace xmrig {
class NullClient : public IClient
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(NullClient)
NullClient(IClientListener* listener);
~NullClient() override = default;
virtual bool disconnect() override { return true; }
virtual bool hasExtension(Extension extension) const noexcept override { return false; }
virtual bool isEnabled() const override { return true; }
virtual bool isTLS() const override { return false; }
virtual const char* mode() const override { return "benchmark"; }
virtual const char* tag() const override { return "null"; }
virtual const char* tlsFingerprint() const override { return nullptr; }
virtual const char* tlsVersion() const override { return nullptr; }
virtual const Job& job() const override { return m_job; }
virtual const Pool& pool() const override { return m_pool; }
virtual const String& ip() const override { return m_ip; }
virtual int id() const override { return 0; }
virtual int64_t send(const rapidjson::Value& obj, Callback callback) override { return 0; }
virtual int64_t send(const rapidjson::Value& obj) override { return 0; }
virtual int64_t sequence() const override { return 0; }
virtual int64_t submit(const JobResult& result) override { return 0; }
virtual void connect() override;
virtual void connect(const Pool& pool) override { setPool(pool); }
virtual void deleteLater() override {}
virtual void setAlgo(const Algorithm& algo) override {}
virtual void setEnabled(bool enabled) override {}
virtual void setPool(const Pool& pool) override;
virtual void setProxy(const ProxyUrl& proxy) override {}
virtual void setQuiet(bool quiet) override {}
virtual void setRetries(int retries) override {}
virtual void setRetryPause(uint64_t ms) override {}
virtual void tick(uint64_t now) override {}
private:
IClientListener* m_listener;
Job m_job;
Pool m_pool;
String m_ip;
};
} /* namespace xmrig */
#endif /* XMRIG_NULLCLIENT_H */

View file

@ -50,6 +50,9 @@
#endif
#include "base/net/stratum/NullClient.h"
namespace xmrig {
@ -72,6 +75,7 @@ const char *Pool::kSOCKS5 = "socks5";
const char *Pool::kTls = "tls";
const char *Pool::kUrl = "url";
const char *Pool::kUser = "user";
const char *Pool::kBenchmark = "benchmark";
const char *Pool::kNicehashHost = "nicehash.com";
@ -125,7 +129,20 @@ xmrig::Pool::Pool(const rapidjson::Value &object) :
m_flags.set(FLAG_NICEHASH, Json::getBool(object, kNicehash) || m_url.host().contains(kNicehashHost));
m_flags.set(FLAG_TLS, Json::getBool(object, kTls) || m_url.isTLS());
if (m_daemon.isValid()) {
const char* benchSize = Json::getString(object, kBenchmark, nullptr);
if (benchSize) {
if (stricmp(benchSize, "1M") == 0) {
m_benchSize = 1000000;
}
else if (stricmp(benchSize, "10M") == 0) {
m_benchSize = 10000000;
}
}
if (m_benchSize) {
m_mode = MODE_BENCHMARK;
}
else if (m_daemon.isValid()) {
m_mode = MODE_SELF_SELECT;
}
else if (Json::getBool(object, kDaemon)) {
@ -217,6 +234,9 @@ xmrig::IClient *xmrig::Pool::createClient(int id, IClientListener *listener) con
client = new AutoClient(id, Platform::userAgent(), listener);
}
# endif
else if (m_mode == MODE_BENCHMARK) {
client = new NullClient(listener);
}
assert(client != nullptr);

View file

@ -50,7 +50,8 @@ public:
MODE_POOL,
MODE_DAEMON,
MODE_SELF_SELECT,
MODE_AUTO_ETH
MODE_AUTO_ETH,
MODE_BENCHMARK,
};
static const String kDefaultPassword;
@ -71,6 +72,7 @@ public:
static const char *kTls;
static const char *kUrl;
static const char *kUser;
static const char* kBenchmark;
static const char *kNicehashHost;
constexpr static int kKeepAliveTimeout = 60;
@ -97,6 +99,7 @@ public:
inline const Url &daemon() const { return m_daemon; }
inline int keepAlive() const { return m_keepAlive; }
inline Mode mode() const { return m_mode; }
inline uint64_t benchSize() const { return m_benchSize; }
inline uint16_t port() const { return m_url.port(); }
inline uint64_t pollInterval() const { return m_pollInterval; }
inline void setAlgo(const Algorithm &algorithm) { m_algorithm = algorithm; }
@ -133,6 +136,7 @@ private:
Coin m_coin;
int m_keepAlive = 0;
Mode m_mode = MODE_POOL;
uint32_t m_benchSize = 0;
ProxyUrl m_proxy;
std::bitset<FLAG_MAX> m_flags = 0;
String m_fingerprint;