Large cluster optimizations. (#348)

* Added sync log to streamer.
* Fixed ledger closing attempt while syncing.
* Added diagnostic contract.
* Reset to stage 0 on unreliable votes.
* Reduced peer msg age threshold.
* Added health tracking.
* Weakly-connected detection improvement.
* Increased version 0.5.1.
* Improved client lib server version check.
* Added health logging support to text client.
* Added weakly connected status in status response.
* Increased max peers limits when serializing.
* Local docker cluster manual ip.
* Updated vultr script vm region order.
* Sync status reporting improvement.
* Added milliseconds to logging.
This commit is contained in:
Ravin Perera
2021-09-17 11:53:49 +05:30
committed by GitHub
parent c686745c81
commit 6dc0776b56
32 changed files with 720 additions and 86 deletions

View File

@@ -24,6 +24,7 @@ namespace msg::usrmsg::bson
* "contract_execution_enabled": true | false,
* "read_requests_enabled": true | false,
* "is_full_history_node": true | false,
* "weakly_connected": true | false,
* "current_unl": [ <ed prefixed pubkey>, ... ],
* "peers": [ "ip:port", ... ]
* }
@@ -33,6 +34,7 @@ namespace msg::usrmsg::bson
const util::sequence_hash lcl_id = status::get_lcl_id();
const std::set<std::string> unl = status::get_unl();
const bool in_sync = status::is_in_sync();
const bool weakly_connected = status::get_weakly_connected();
jsoncons::bson::bson_bytes_encoder encoder(msg);
encoder.begin_object();
@@ -54,6 +56,8 @@ namespace msg::usrmsg::bson
encoder.bool_value(conf::cfg.user.concurrent_read_requests != 0);
encoder.key(msg::usrmsg::FLD_IS_FULL_HISTORY_NODE);
encoder.bool_value(conf::cfg.node.history == conf::HISTORY::FULL);
encoder.key(msg::usrmsg::FLD_WEAKLY_CONNECTED);
encoder.bool_value(weakly_connected);
encoder.key(msg::usrmsg::FLD_CURRENT_UNL);
encoder.begin_array();
@@ -315,6 +319,70 @@ namespace msg::usrmsg::bson
encoder.flush();
}
/**
* Constructs health stat message.
* @param msg Buffer to construct the generated bson message into.
* Message format:
* {
* "type": "health_event",
* "proposals": {
* "comm_latency": {min:0, max:0, avg:0},
* "read_latency": {min:0, max:0, avg:0}
* "batch_size": 0
* },
* "peer_count": 0,
* "weakly_connected": true | false
* }
* @param ev Current health information.
*/
void create_health_notification(std::vector<uint8_t> &msg, const status::health_event &ev)
{
jsoncons::bson::bson_bytes_encoder encoder(msg);
encoder.begin_object();
encoder.key(msg::usrmsg::FLD_TYPE);
encoder.string_value(msg::usrmsg::MSGTYPE_HEALTH_EVENT);
encoder.key(msg::usrmsg::FLD_EVENT);
if (ev.index() == 0)
{
const status::proposal_health &phealth = std::get<status::proposal_health>(ev);
encoder.string_value(msg::usrmsg::HEALTH_EVENT_PROPOSAL);
encoder.key(msg::usrmsg::FLD_COMM_LATENCY);
encoder.begin_object();
encoder.key(msg::usrmsg::FLD_MIN);
encoder.uint64_value(phealth.comm_latency_min);
encoder.key(msg::usrmsg::FLD_MAX);
encoder.uint64_value(phealth.comm_latency_max);
encoder.key(msg::usrmsg::FLD_AVG);
encoder.uint64_value(phealth.comm_latency_avg);
encoder.end_object();
encoder.key(msg::usrmsg::FLD_READ_LATENCY);
encoder.begin_object();
encoder.key(msg::usrmsg::FLD_MIN);
encoder.uint64_value(phealth.read_latency_min);
encoder.key(msg::usrmsg::FLD_MAX);
encoder.uint64_value(phealth.read_latency_max);
encoder.key(msg::usrmsg::FLD_AVG);
encoder.uint64_value(phealth.read_latency_avg);
encoder.end_object();
encoder.key(msg::usrmsg::FLD_BATCH_SIZE);
encoder.uint64_value(phealth.batch_size);
}
else if (ev.index() == 1)
{
const status::connectivity_health &conn = std::get<status::connectivity_health>(ev);
encoder.string_value(msg::usrmsg::HEALTH_EVENT_CONNECTIVITY);
encoder.key(msg::usrmsg::FLD_PEER_COUNT);
encoder.uint64_value(conn.peer_count);
encoder.key(msg::usrmsg::FLD_WEAKLY_CONNECTED);
encoder.bool_value(conn.is_weakly_connected);
}
encoder.end_object();
encoder.flush();
}
/**
* Constructs a ledger query response.
* @param msg Buffer to construct the generated bson message string into.
@@ -533,6 +601,11 @@ namespace msg::usrmsg::bson
{
channel = usr::NOTIFICATION_CHANNEL::UNL_CHANGE;
}
else if (d[msg::usrmsg::FLD_CHANNEL] == msg::usrmsg::MSGTYPE_HEALTH_EVENT &&
(conf::cfg.health.proposal_stats || conf::cfg.health.connectivity_stats))
{
channel = usr::NOTIFICATION_CHANNEL::HEALTH_STAT;
}
else
{
LOG_DEBUG << "User subscription request invalid channel.";

View File

@@ -5,6 +5,7 @@
#include "../../util/merkle_hash_tree.hpp"
#include "../../ledger/ledger_query.hpp"
#include "../../usr/user_common.hpp"
#include "../../status.hpp"
namespace msg::usrmsg::bson
{
@@ -28,6 +29,8 @@ namespace msg::usrmsg::bson
void create_sync_status_notification(std::vector<uint8_t> &msg, const bool in_sync);
void create_health_notification(std::vector<uint8_t> &msg, const status::health_event &ev);
void create_ledger_query_response(std::vector<uint8_t> &msg, std::string_view reply_for,
const ledger::query::query_result &result);

View File

@@ -44,7 +44,7 @@ namespace msg::fbuf::p2pmsg
if (session && session->challenge_status == comm::CHALLENGE_STATUS::CHALLENGE_VERIFIED && message.size() <= MAX_SIZE_FOR_TIME_CHECK)
{
const uint64_t time_now = util::get_epoch_milliseconds();
if (p2p_msg->created_on() < (time_now - (conf::cfg.contract.roundtime * 4)))
if (p2p_msg->created_on() < (time_now - (conf::cfg.contract.roundtime * 3)))
{
LOG_DEBUG << "Peer message is too old. type:" << p2p_msg->content_type() << " from:" << (session ? session->display_name() : "");
return p2p::peer_message_info{NULL, P2PMsgContent_NONE, 0};

View File

@@ -143,6 +143,7 @@ namespace msg::usrmsg::json
* "contract_execution_enabled": true | false,
* "read_requests_enabled": true | false,
* "is_full_history_node": true | false,
* "weakly_connected": true | false,
* "current_unl": [ "<ed prefixed pubkey hex>"", ... ],
* "peers": [ "ip:port", ... ]
* }
@@ -152,6 +153,7 @@ namespace msg::usrmsg::json
const util::sequence_hash lcl_id = status::get_lcl_id();
const std::set<std::string> unl = status::get_unl();
const bool in_sync = status::is_in_sync();
const bool weakly_connected = status::get_weakly_connected();
msg.reserve(1024);
msg += "{\"";
@@ -191,6 +193,11 @@ namespace msg::usrmsg::json
msg += SEP_COLON_NOQUOTE;
msg += conf::cfg.node.history == conf::HISTORY::FULL ? STR_TRUE : STR_FALSE;
msg += SEP_COMMA_NOQUOTE;
msg += msg::usrmsg::FLD_WEAKLY_CONNECTED;
msg += SEP_COLON_NOQUOTE;
msg += weakly_connected ? STR_TRUE : STR_FALSE;
msg += SEP_COMMA_NOQUOTE;
msg += msg::usrmsg::FLD_CURRENT_UNL;
msg += SEP_COLON_NOQUOTE;
msg += OPEN_SQR_BRACKET;
@@ -546,6 +553,97 @@ namespace msg::usrmsg::json
msg += "}";
}
/**
* Constructs health stat message.
* @param msg Buffer to construct the generated json message string into.
* Message format:
* {
* "type": "health_event",
* "event": "proposal" | "connectivity",
*
* // proposal
* "comm_latency": {min:0, max:0, avg:0},
* "read_latency": {min:0, max:0, avg:0}
* "batch_size": 0
*
* // connectivity
* "peer_count": 0,
* "weakly_connected": true | false
* }
* @param ev Current health information.
*/
void create_health_notification(std::vector<uint8_t> &msg, const status::health_event &ev)
{
msg.reserve(128);
msg += "{\"";
msg += msg::usrmsg::FLD_TYPE;
msg += SEP_COLON;
msg += msg::usrmsg::MSGTYPE_HEALTH_EVENT;
msg += SEP_COMMA;
msg += msg::usrmsg::FLD_EVENT;
msg += SEP_COLON;
if (ev.index() == 0)
{
const status::proposal_health &phealth = std::get<status::proposal_health>(ev);
msg += msg::usrmsg::HEALTH_EVENT_PROPOSAL;
msg += SEP_COMMA;
msg += msg::usrmsg::FLD_COMM_LATENCY;
msg += SEP_COLON_NOQUOTE;
msg += "{\"";
msg += msg::usrmsg::FLD_MIN;
msg += SEP_COLON_NOQUOTE;
msg += std::to_string(phealth.comm_latency_min);
msg += SEP_COMMA_NOQUOTE;
msg += msg::usrmsg::FLD_MAX;
msg += SEP_COLON_NOQUOTE;
msg += std::to_string(phealth.comm_latency_max);
msg += SEP_COMMA_NOQUOTE;
msg += msg::usrmsg::FLD_AVG;
msg += SEP_COLON_NOQUOTE;
msg += std::to_string(phealth.comm_latency_avg);
msg += "}";
msg += SEP_COMMA_NOQUOTE;
msg += msg::usrmsg::FLD_READ_LATENCY;
msg += SEP_COLON_NOQUOTE;
msg += "{\"";
msg += msg::usrmsg::FLD_MIN;
msg += SEP_COLON_NOQUOTE;
msg += std::to_string(phealth.read_latency_min);
msg += SEP_COMMA_NOQUOTE;
msg += msg::usrmsg::FLD_MAX;
msg += SEP_COLON_NOQUOTE;
msg += std::to_string(phealth.read_latency_max);
msg += SEP_COMMA_NOQUOTE;
msg += msg::usrmsg::FLD_AVG;
msg += SEP_COLON_NOQUOTE;
msg += std::to_string(phealth.read_latency_avg);
msg += "}";
msg += SEP_COMMA_NOQUOTE;
msg += msg::usrmsg::FLD_BATCH_SIZE;
msg += SEP_COLON_NOQUOTE;
msg += std::to_string(phealth.batch_size);
}
else if (ev.index() == 1)
{
const status::connectivity_health &conn = std::get<status::connectivity_health>(ev);
msg += msg::usrmsg::HEALTH_EVENT_CONNECTIVITY;
msg += SEP_COMMA;
msg += msg::usrmsg::FLD_PEER_COUNT;
msg += SEP_COLON_NOQUOTE;
msg += std::to_string(conn.peer_count);
msg += SEP_COMMA_NOQUOTE;
msg += msg::usrmsg::FLD_WEAKLY_CONNECTED;
msg += SEP_COLON_NOQUOTE;
msg += conn.is_weakly_connected ? STR_TRUE : STR_FALSE;
}
msg += "}";
}
/**
* Constructs a ledger query response.
* @param msg Buffer to construct the generated json message string into.
@@ -892,6 +990,11 @@ namespace msg::usrmsg::json
{
channel = usr::NOTIFICATION_CHANNEL::UNL_CHANGE;
}
else if (d[msg::usrmsg::FLD_CHANNEL] == msg::usrmsg::MSGTYPE_HEALTH_EVENT &&
(conf::cfg.health.proposal_stats || conf::cfg.health.connectivity_stats))
{
channel = usr::NOTIFICATION_CHANNEL::HEALTH_STAT;
}
else
{
LOG_DEBUG << "User subscription request invalid channel.";

View File

@@ -5,6 +5,7 @@
#include "../../util/merkle_hash_tree.hpp"
#include "../../ledger/ledger_query.hpp"
#include "../../usr/user_common.hpp"
#include "../../status.hpp"
namespace msg::usrmsg::json
{
@@ -32,6 +33,8 @@ namespace msg::usrmsg::json
void create_sync_status_notification(std::vector<uint8_t> &msg, const bool in_sync);
void create_health_notification(std::vector<uint8_t> &msg, const status::health_event &ev);
void create_ledger_query_response(std::vector<uint8_t> &msg, std::string_view reply_for,
const ledger::query::query_result &result);

View File

@@ -9,7 +9,7 @@ namespace msg::usrmsg
constexpr size_t CHALLENGE_LEN = 16;
// Max no. of known peers to return in get status.
constexpr const size_t MAX_KNOWN_PEERS_INFO = 16;
constexpr const size_t MAX_KNOWN_PEERS_INFO = 100;
// Message field names
constexpr const char *FLD_HP_VERSION = "hp_version";
@@ -65,6 +65,14 @@ namespace msg::usrmsg
constexpr const char *FLD_LEDGER = "ledger";
constexpr const char *FLD_CHANNEL = "channel";
constexpr const char *FLD_ENABLED = "enabled";
constexpr const char *FLD_COMM_LATENCY = "comm_latency";
constexpr const char *FLD_READ_LATENCY = "read_latency";
constexpr const char *FLD_BATCH_SIZE = "batch_size";
constexpr const char *FLD_MIN = "min";
constexpr const char *FLD_MAX = "max";
constexpr const char *FLD_AVG = "avg";
constexpr const char *FLD_PEER_COUNT = "peer_count";
constexpr const char *FLD_WEAKLY_CONNECTED = "weakly_connected";
// Message types
constexpr const char *MSGTYPE_USER_CHALLENGE = "user_challenge";
@@ -81,6 +89,7 @@ namespace msg::usrmsg
constexpr const char *MSGTYPE_LCL_RESPONSE = "lcl_response";
constexpr const char *MSGTYPE_UNL_CHANGE = "unl_change";
constexpr const char *MSGTYPE_LEDGER_EVENT = "ledger_event";
constexpr const char *MSGTYPE_HEALTH_EVENT = "health_event";
constexpr const char *MSGTYPE_LEDGER_QUERY = "ledger_query";
constexpr const char *MSGTYPE_LEDGER_QUERY_RESULT = "ledger_query_result";
constexpr const char *MSGTYPE_SUBSCRIPTION = "subscription";
@@ -103,7 +112,8 @@ namespace msg::usrmsg
constexpr const char *STR_FALSE = "false";
constexpr const char *LEDGER_EVENT_LEDGER_CREATED = "ledger_created";
constexpr const char *LEDGER_EVENT_SYNC_STATUS = "sync_status";
constexpr const char *HEALTH_EVENT_PROPOSAL = "proposal";
constexpr const char *HEALTH_EVENT_CONNECTIVITY = "connectivity";
} // namespace msg::usrmsg

View File

@@ -80,6 +80,14 @@ namespace msg::usrmsg
busrmsg::create_sync_status_notification(msg, in_sync);
}
void usrmsg_parser::create_health_notification(std::vector<uint8_t> &msg, const status::health_event &ev) const
{
if (protocol == util::PROTOCOL::JSON)
jusrmsg::create_health_notification(msg, ev);
else
busrmsg::create_health_notification(msg, ev);
}
void usrmsg_parser::create_ledger_query_response(std::vector<uint8_t> &msg, std::string_view reply_for,
const ledger::query::query_result &result) const
{

View File

@@ -6,6 +6,7 @@
#include "../util/merkle_hash_tree.hpp"
#include "../ledger/ledger_query.hpp"
#include "../usr/user_common.hpp"
#include "../status.hpp"
namespace msg::usrmsg
{
@@ -37,6 +38,8 @@ namespace msg::usrmsg
void create_sync_status_notification(std::vector<uint8_t> &msg, const bool in_sync) const;
void create_health_notification(std::vector<uint8_t> &msg, const status::health_event &ev) const;
void create_ledger_query_response(std::vector<uint8_t> &msg, std::string_view reply_for,
const ledger::query::query_result &result) const;