1 #include "hmbdc/app/utils/changeSched.hpp" 2 #include "hmbdc/app/Client.hpp" 3 #include "hmbdc/app/Context.hpp" 4 #include "hmbdc/app/Config.hpp" 5 #include "hmbdc/pattern/GuardedSingleton.hpp" 6 #include "hmbdc/numeric/StatHistogram.hpp" 7 #include "hmbdc/time/Rater.hpp" 8 #include "hmbdc/os/Signals.hpp" 16 namespace hmbdc {
namespace app {
namespace utils {
34 char padding[1024 - 16];
37 template <
typename Sender>
39 :
Client<Pinger<Sender>, Ball> {
40 Pinger(Sender* sender, uint16_t msgPerSec, uint16_t msgSize,
size_t skipFirst)
41 : rater_(Duration::seconds(1), msgPerSec, 1u)
43 , hist_(Duration::microseconds(0), Duration::microseconds(1000), 50000)
44 , periodicPingCount_(0)
47 , msgPerSec_(msgPerSec)
51 char const* hmbdcName()
const {
55 void messageDispatchingStartedCb(uint16_t threadSerialNumber)
override {
56 cout <<
"Started with the first " << skipped_ <<
" values ignored(x), press ctrl-c to get results" << endl;
59 void handleMessageCb(
Ball const& m) {
60 auto now = SysTime::now();
61 auto lat = now - m.ts;
69 void stoppedCb(exception
const& e){
70 cerr << e.what() << endl;
73 void invokedCb(uint16_t)
override {
74 if (unlikely(rater_.check())) {
75 if (++periodicPingCount_ == msgPerSec_) {
76 cout << (skipped_?
'x':
'.') << flush;
77 periodicPingCount_ = 0;
80 sender_->send(p, msgSize_);
82 if (!skipped_) pingCount_++;
87 cout <<
"\nround trip latency:(" << hist_.sampleSize() <<
'/' << pingCount_ <<
"):";
88 hist_.display(cout, {0, 25, 50, 75, 90, 95, 99, 99.9, 99.99, 100});
95 size_t periodicPingCount_;
103 template <
typename Sender>
105 :
Client<Ponger<Sender>, Ball> {
110 char const* hmbdcName()
const {
114 void messageDispatchingStartedCb(uint16_t)
override {
115 cout <<
"Started, press ctrl-c to stop" << endl;
118 void handleMessageCb(
Ball const& m) {
119 sender_->send(m, m.size);
122 void stoppedCb(std::exception
const& e){
123 std::cerr << e.what() << std::endl;
129 template <
typename NetContext>
131 pingpong(
Config const& config) {
132 uint16_t startCore = config.
getExt<uint16_t>(
"startCore");
133 size_t skipFirst = config.
getExt<
size_t>(
"skipFirst");
134 bool ping = config.
getExt<
bool>(
"ping");
135 auto runTime = config.
getExt<uint32_t>(
"runTime");
138 auto& net = NetContext::instance();
139 auto msgSize = config.
getExt<uint16_t>(
"msgSize");
140 msgSize = min<uint16_t>(msgSize, 512);
141 msgSize = max<uint16_t>(msgSize, 16);
147 Config pingCfg(config,
"ping");
148 Config pongCfg(config,
"pong");
149 cout <<
"initailizing..." << endl;
151 auto sengine = net.createSendTransportEngine(pingCfg, msgSize);
152 auto rengine = net.createRecvTransportEngine(pongCfg, ctx.
buffer());
154 , min<uint16_t>(config.
getExt<uint16_t>(
"msgPerSec"), 1000u)
158 net.listenTo(
"pong");
160 uint64_t cpuMask = (1ul << startCore);
162 ctx.
start(1, cpuMask,
true);
166 ctx.
start(pinger, cpuMask);
178 pinger.finalReport();
181 auto sengine = net.createSendTransportEngine(pongCfg,
sizeof(
Ball));
182 auto rengine = net.createRecvTransportEngine(pingCfg, ctx.
buffer());
185 net.listenTo(
"ping");
187 uint64_t cpuMask = (1ul << startCore);
189 ctx.
start(1, cpuMask,
true);
194 ctx.
start(ponger, cpuMask);
Definition: Pingpong.hpp:104
Definition: Pingpong.hpp:38
class to hold an hmbdc configuration
Definition: Config.hpp:35
Definition: Client.hpp:11
void stop()
stop the message dispatching - asynchronously
Definition: Context.hpp:588
void join()
wait until all threads (Pool threads too if apply) of the Context exit
Definition: Context.hpp:597
Definition: TypedString.hpp:74
Definition: BitMath.hpp:6
Definition: Message.hpp:21
Definition: GuardedSingleton.hpp:12
Buffer & buffer()
accessor - mostly used internally
Definition: Context.hpp:274
Definition: GuardedSingleton.hpp:9
void start(uint16_t poolThreadCount, uint64_t poolThreadsCpuAffinityMask, Args &&...args)
start the context and specify its Pool and direct Clients
Definition: Context.hpp:553
Definition: Pingpong.hpp:26
void addToPool(Client &client, uint64_t poolThreadAffinityIn=0xfffffffffffffffful)
add a client to Context's pool - the Client is running in pool mode
Definition: Context.hpp:477
Definition: Context.hpp:384
static void onTermIntDo(function< void()> doThis)
specfy what to do when SIGTERM or SIGINT is received
Definition: Signals.hpp:29
T getExt(const path_type ¶m) const
get a value from the config
Definition: Config.hpp:143
Definition: Client.hpp:39
Definition: Client.hpp:11