From cf3f1c3b4412412231cd19cb5aa30c5e62b21914 Mon Sep 17 00:00:00 2001 From: Determinant Date: Mon, 20 Aug 2018 23:17:00 -0400 Subject: ... --- src/hotstuff_client.cpp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'src/hotstuff_client.cpp') diff --git a/src/hotstuff_client.cpp b/src/hotstuff_client.cpp index bee8abd..f925b73 100644 --- a/src/hotstuff_client.cpp +++ b/src/hotstuff_client.cpp @@ -9,22 +9,19 @@ #include "hotstuff/client.h" using salticidae::Config; -using salticidae::ElapsedTime; -using salticidae::trim_all; -using salticidae::split; using salticidae::MsgNetwork; using hotstuff::ReplicaID; using hotstuff::NetAddr; using hotstuff::EventContext; -using hotstuff::uint256_t; using hotstuff::MsgReqCmd; using hotstuff::MsgRespCmd; using hotstuff::CommandDummy; -using hotstuff::command_t; using hotstuff::Finality; using hotstuff::HotStuffError; +using hotstuff::uint256_t; using hotstuff::opcode_t; +using hotstuff::command_t; EventContext eb; ReplicaID proposer; @@ -34,7 +31,7 @@ int max_iter_num; struct Request { ReplicaID rid; command_t cmd; - ElapsedTime et; + salticidae::ElapsedTime et; Request(ReplicaID rid, const command_t &cmd): rid(rid), cmd(cmd) { et.start(); } }; @@ -56,8 +53,10 @@ void try_send() { { auto cmd = CommandDummy::make_cmd(); mn.send_msg(MsgReqCmd(*cmd), *conns.at(proposer)); +#ifndef HOTSTUFF_ENABLE_BENCHMARK HOTSTUFF_LOG_INFO("send new cmd %.10s", get_hex(cmd->get_hash()).c_str()); +#endif waiting.insert(std::make_pair( cmd->get_hash(), Request(proposer, cmd))); if (max_iter_num > 0) @@ -70,6 +69,9 @@ void client_resp_cmd_handler(MsgRespCmd &&msg, MsgNetwork::Conn &) { HOTSTUFF_LOG_DEBUG("got %s", std::string(msg.fin).c_str()); const uint256_t &cmd_hash = fin.cmd_hash; auto it = waiting.find(cmd_hash); + auto &et = it->second.et; + if (it == waiting.end()) return; + et.stop(); if (fin.rid != proposer) { HOTSTUFF_LOG_INFO("reconnect to the new proposer"); @@ -79,20 +81,27 @@ void client_resp_cmd_handler(MsgRespCmd &&msg, MsgNetwork::Conn &) { { mn.send_msg(MsgReqCmd(*(waiting.find(cmd_hash)->second.cmd)), *conns.at(proposer)); +#ifndef HOTSTUFF_ENABLE_BENCHMARK HOTSTUFF_LOG_INFO("resend cmd %.10s", get_hex(cmd_hash).c_str()); - it->second.et.start(); +#endif + et.start(); it->second.rid = proposer; return; } - HOTSTUFF_LOG_INFO("got %s", std::string(fin).c_str()); - if (it == waiting.end()) return; +#ifndef HOTSTUFF_ENABLE_BENCHMARK + HOTSTUFF_LOG_INFO("got %s, wall: %.3f, cpu: %.3f", + std::string(fin).c_str(), + et.elapsed_sec, et.cpu_elapsed_sec); +#else + HOTSTUFF_LOG_INFO("%.6f %.6f", et.elapsed_sec, et.cpu_elapsed_sec); +#endif waiting.erase(it); try_send(); } std::pair split_ip_port_cport(const std::string &s) { - auto ret = trim_all(split(s, ";")); + auto ret = salticidae::trim_all(salticidae::split(s, ";")); return std::make_pair(ret[0], ret[1]); } @@ -117,7 +126,7 @@ int main(int argc, char **argv) { std::vector> raw; for (const auto &s: opt_replicas->get()) { - auto res = trim_all(split(s, ",")); + auto res = salticidae::trim_all(salticidae::split(s, ",")); if (res.size() != 2) throw HotStuffError("format error"); raw.push_back(std::make_pair(res[0], res[1])); -- cgit v1.2.3 From 69208d4931f45911e401a97ba9b019a2ffdfe82c Mon Sep 17 00:00:00 2001 From: Determinant Date: Tue, 21 Aug 2018 21:58:40 -0400 Subject: use randomized initial cnt to avoid duplicate command --- src/hotstuff_client.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/hotstuff_client.cpp') diff --git a/src/hotstuff_client.cpp b/src/hotstuff_client.cpp index f925b73..97c5dc5 100644 --- a/src/hotstuff_client.cpp +++ b/src/hotstuff_client.cpp @@ -1,4 +1,5 @@ #include +#include #include "salticidae/type.h" #include "salticidae/netaddr.h" #include "salticidae/network.h" @@ -27,6 +28,8 @@ EventContext eb; ReplicaID proposer; size_t max_async_num; int max_iter_num; +uint64_t cnd_stride; +uint64_t cnt; struct Request { ReplicaID rid; @@ -51,7 +54,8 @@ void set_proposer(ReplicaID rid) { void try_send() { while (waiting.size() < max_async_num && max_iter_num) { - auto cmd = CommandDummy::make_cmd(); + auto cmd = new CommandDummy(cnt); + cnt += cnd_stride; mn.send_msg(MsgReqCmd(*cmd), *conns.at(proposer)); #ifndef HOTSTUFF_ENABLE_BENCHMARK HOTSTUFF_LOG_INFO("send new cmd %.10s", @@ -106,11 +110,15 @@ std::pair split_ip_port_cport(const std::string &s) { } int main(int argc, char **argv) { + cnt = std::random_device()(); + HOTSTUFF_LOG_INFO("init cnt = %lu", cnt); + Config config("hotstuff.conf"); auto opt_idx = Config::OptValInt::create(0); auto opt_replicas = Config::OptValStrVec::create(); auto opt_max_iter_num = Config::OptValInt::create(100); auto opt_max_async_num = Config::OptValInt::create(10); + auto opt_cnt_stride = Config::OptValInt::create(1000); mn.reg_handler(client_resp_cmd_handler); @@ -119,8 +127,10 @@ int main(int argc, char **argv) { config.add_opt("replica", opt_replicas, Config::APPEND); config.add_opt("iter", opt_max_iter_num, Config::SET_VAL); config.add_opt("max-async", opt_max_async_num, Config::SET_VAL); + config.add_opt("cnt-stride", opt_cnt_stride, Config::SET_VAL); config.parse(argc, argv); auto idx = opt_idx->get(); + cnd_stride = opt_cnt_stride->get(); max_iter_num = opt_max_iter_num->get(); max_async_num = opt_max_async_num->get(); std::vector> raw; -- cgit v1.2.3 From 51796ba2e778001948f4cd5acb51e31fcaec0641 Mon Sep 17 00:00:00 2001 From: Determinant Date: Tue, 21 Aug 2018 22:25:00 -0400 Subject: use cid instead of randomization --- src/hotstuff_client.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/hotstuff_client.cpp') diff --git a/src/hotstuff_client.cpp b/src/hotstuff_client.cpp index 97c5dc5..62b13ed 100644 --- a/src/hotstuff_client.cpp +++ b/src/hotstuff_client.cpp @@ -28,8 +28,8 @@ EventContext eb; ReplicaID proposer; size_t max_async_num; int max_iter_num; -uint64_t cnd_stride; -uint64_t cnt; +uint32_t cid; +uint32_t cnt = 0; struct Request { ReplicaID rid; @@ -54,8 +54,7 @@ void set_proposer(ReplicaID rid) { void try_send() { while (waiting.size() < max_async_num && max_iter_num) { - auto cmd = new CommandDummy(cnt); - cnt += cnd_stride; + auto cmd = new CommandDummy(cid, cnt++); mn.send_msg(MsgReqCmd(*cmd), *conns.at(proposer)); #ifndef HOTSTUFF_ENABLE_BENCHMARK HOTSTUFF_LOG_INFO("send new cmd %.10s", @@ -110,27 +109,23 @@ std::pair split_ip_port_cport(const std::string &s) { } int main(int argc, char **argv) { - cnt = std::random_device()(); - HOTSTUFF_LOG_INFO("init cnt = %lu", cnt); - Config config("hotstuff.conf"); auto opt_idx = Config::OptValInt::create(0); auto opt_replicas = Config::OptValStrVec::create(); auto opt_max_iter_num = Config::OptValInt::create(100); auto opt_max_async_num = Config::OptValInt::create(10); - auto opt_cnt_stride = Config::OptValInt::create(1000); + auto opt_cid = Config::OptValInt::create(-1); mn.reg_handler(client_resp_cmd_handler); try { config.add_opt("idx", opt_idx, Config::SET_VAL); + config.add_opt("cid", opt_cid, Config::SET_VAL); config.add_opt("replica", opt_replicas, Config::APPEND); config.add_opt("iter", opt_max_iter_num, Config::SET_VAL); config.add_opt("max-async", opt_max_async_num, Config::SET_VAL); - config.add_opt("cnt-stride", opt_cnt_stride, Config::SET_VAL); config.parse(argc, argv); auto idx = opt_idx->get(); - cnd_stride = opt_cnt_stride->get(); max_iter_num = opt_max_iter_num->get(); max_async_num = opt_max_async_num->get(); std::vector> raw; @@ -144,6 +139,7 @@ int main(int argc, char **argv) { if (!(0 <= idx && (size_t)idx < raw.size() && raw.size() > 0)) throw std::invalid_argument("out of range"); + cid = opt_cid->get() != -1 ? opt_cid->get() : idx; for (const auto &p: raw) { auto _p = split_ip_port_cport(p.first); -- cgit v1.2.3