]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/messenger/simple_client.cc
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/Messenger.h"
25 #include "messages/MPing.h"
26 #include "common/Timer.h"
27 #include "common/ceph_argparse.h"
28 #include "global/global_init.h"
29 #include "perfglue/heap_profiler.h"
30 #include "common/address_helper.h"
31 #include "message_helper.h"
32 #include "simple_dispatcher.h"
34 #define dout_subsys ceph_subsys_simple_client
36 void usage(ostream
& out
)
38 out
<< "usage: simple_client [options]\n"
48 int main(int argc
, const char **argv
)
50 vector
<const char*> args
;
52 SimpleDispatcher
*dispatcher
;
53 std::vector
<const char*>::iterator arg_iter
;
55 entity_addr_t dest_addr
;
59 std::string addr
= "localhost";
60 std::string port
= "1234";
69 argv_to_vec(argc
, argv
, args
);
72 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_ANY
,
73 CODE_ENVIRONMENT_UTILITY
,
76 for (arg_iter
= args
.begin(); arg_iter
!= args
.end();) {
77 if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--addr",
80 } else if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--port",
83 } else if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--msgs",
85 n_msgs
= atoi(val
.c_str());;
86 } else if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--dsize",
88 n_dsize
= atoi(val
.c_str());;
95 cerr
<< "What is this? -- " << args
[0] << std::endl
;
100 cout
<< "simple_client starting " <<
101 "dest addr " << addr
<< " " <<
102 "dest port " << port
<< " " <<
103 "initial msgs (pipe depth) " << n_msgs
<< " " <<
104 "data buffer size " << n_dsize
<< std::endl
;
106 messenger
= Messenger::create(g_ceph_context
, g_conf
->get_val
<std::string
>("ms_type"),
107 entity_name_t::MON(-1),
111 // enable timing prints
112 messenger
->set_magic(MSG_MAGIC_TRACE_CTR
);
113 messenger
->set_default_policy(Messenger::Policy::lossy_client(0));
115 string dest_str
= "tcp://";
119 entity_addr_from_url(&dest_addr
, dest_str
.c_str());
120 entity_inst_t
dest_server(entity_name_t::MON(-1), dest_addr
);
122 dispatcher
= new SimpleDispatcher(messenger
);
123 messenger
->add_dispatcher_head(dispatcher
);
125 dispatcher
->set_active(); // this side is the pinger
127 r
= messenger
->start();
131 conn
= messenger
->get_connection(dest_server
);
140 for (msg_ix
= 0; msg_ix
< n_msgs
; ++msg_ix
) {
141 /* add a data payload if asked */
145 m
= new_simple_ping_with_data("simple_client", n_dsize
);
147 conn
->send_message(m
);
151 while (conn
->is_connected()) {
152 nanosleep(&ts
, NULL
);
156 cout
<< "Processed " << dispatcher
->get_dcount() + n_msgs
157 << " round-trip messages in " << t2
-t1
<< "s"