1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2013 CohortFS, LLC
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #include <sys/types.h>
22 #include "common/config.h"
23 #include "msg/msg_types.h"
24 #include "msg/xio/XioMessenger.h"
25 #include "msg/xio/FastStrategy.h"
26 #include "msg/xio/QueueStrategy.h"
27 #include "msg/xio/XioMsg.h"
28 #include "messages/MPing.h"
29 #include "common/Timer.h"
30 #include "common/ceph_argparse.h"
31 #include "global/global_init.h"
32 #include "perfglue/heap_profiler.h"
33 #include "common/address_helper.h"
34 #include "message_helper.h"
35 #include "xio_dispatcher.h"
36 #include "msg/xio/XioConnection.h"
38 #define dout_subsys ceph_subsys_xio_client
40 void usage(ostream& out)
42 out << "usage: xio_client [options]\n"
53 int main(int argc, const char **argv)
55 vector<const char*> args;
57 XioDispatcher *dispatcher;
58 std::vector<const char*>::iterator arg_iter;
60 entity_addr_t dest_addr;
64 std::string addr = "localhost";
65 std::string port = "1234";
75 argv_to_vec(argc, argv, args);
78 auto cct = global_init(NULL, args,
80 CODE_ENVIRONMENT_UTILITY, 0);
82 for (arg_iter = args.begin(); arg_iter != args.end();) {
83 if (ceph_argparse_witharg(args, arg_iter, &val, "--addr",
86 } else if (ceph_argparse_witharg(args, arg_iter, &val, "--port",
89 } else if (ceph_argparse_witharg(args, arg_iter, &val, "--msgs",
91 n_msgs = atoi(val.c_str());
92 } else if (ceph_argparse_witharg(args, arg_iter, &val, "--dsize",
94 n_dsize = atoi(val.c_str());
95 } else if (ceph_argparse_witharg(args, arg_iter, &val, "--nfrags",
97 n_nfrags = atoi(val.c_str());
98 } else if (ceph_argparse_flag(args, arg_iter, "--dfast",
107 cerr << "What is this? -- " << args[0] << std::endl;
112 DispatchStrategy* dstrategy;
114 dstrategy = new FastStrategy();
116 dstrategy = new QueueStrategy(2);
118 messenger = new XioMessenger(g_ceph_context,
119 entity_name_t::MON(-1),
125 // enable timing prints
126 static_cast<XioMessenger*>(messenger)->set_magic(
127 MSG_MAGIC_REDUPE /* resubmit messages on delivery (REQUIRED) */ |
128 MSG_MAGIC_TRACE_CTR /* timing prints */);
130 // ensure we have a pool of sizeof(payload data)
132 (void) static_cast<XioMessenger*>(messenger)->pool_hint(n_dsize);
134 messenger->set_default_policy(Messenger::Policy::lossy_client(0));
136 string dest_str = "tcp://";
140 entity_addr_from_url(&dest_addr, dest_str.c_str());
141 entity_inst_t dest_server(entity_name_t::MON(-1), dest_addr);
143 dispatcher = new XioDispatcher(messenger);
144 messenger->add_dispatcher_head(dispatcher);
146 dispatcher->set_active(); // this side is the pinger
148 r = messenger->start();
152 conn = messenger->get_connection(dest_server);
159 for (msg_ix = 0; msg_ix < n_msgs; ++msg_ix) {
160 /* add a data payload if asked */
162 conn->send_message(new MPing());
164 conn->send_message(new_simple_ping_with_data("xio_client", n_dsize, n_nfrags));
169 while (conn->is_connected()) {
170 nanosleep(&ts, NULL);
175 << static_cast<XioConnection*>(conn->get())->get_scount()
176 << " one-way messages in " << t2-t1 << "s"
181 // wait a bit for cleanup to finalize
183 nanosleep(&ts, NULL);
185 messenger->shutdown();