]> git.proxmox.com Git - ceph.git/blame - ceph/src/dmclock/sim/src/test_ssched_main.cc
update sources to v12.1.3
[ceph.git] / ceph / src / dmclock / sim / src / test_ssched_main.cc
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4/*
5 * Copyright (C) 2016 Red Hat Inc.
6 */
7
8
9#include "test_ssched.h"
10
11
12#ifdef PROFILE
13#include "profile.h"
14#endif
15
16
17namespace test = crimson::test_simple_scheduler;
18namespace ssched = crimson::simple_scheduler;
19namespace sim = crimson::qos_simulation;
20
21using namespace std::placeholders;
22
23
24namespace crimson {
25 namespace test_simple_scheduler {
26 void client_data(std::ostream& out,
27 test::MySim* sim,
28 test::MySim::ClientFilter client_disp_filter,
29 int head_w, int data_w, int data_prec);
30
31 void server_data(std::ostream& out,
32 test::MySim* sim,
33 test::MySim::ServerFilter server_disp_filter,
34 int head_w, int data_w, int data_prec);
35 } // namespace test_simple
36} // namespace crimson
37
38
39int main(int argc, char* argv[]) {
40 // server params
41
42 const uint server_count = 100;
43 const uint server_iops = 40;
44 const uint server_threads = 1;
45
46 // client params
47
48 const uint client_total_ops = 1000;
49 const uint client_count = 100;
50 const uint client_server_select_range = 10;
51 const uint client_wait_count = 1;
52 const uint client_iops_goal = 50;
53 const uint client_outstanding_ops = 100;
54 const std::chrono::seconds client_wait(10);
55
56 auto client_disp_filter = [=] (const ClientId& i) -> bool {
57 return i < 3 || i >= (client_count - 3);
58 };
59
60 auto server_disp_filter = [=] (const ServerId& i) -> bool {
61 return i < 3 || i >= (server_count - 3);
62 };
63
64
65 test::MySim *simulation;
66
67 // lambda to post a request to the identified server; called by client
68 test::SubmitFunc server_post_f =
69 [&simulation](const ServerId& server_id,
d2e6a577 70 sim::TestRequest&& request,
7c673cae
FG
71 const ClientId& client_id,
72 const ssched::ReqParams& req_params) {
73 auto& server = simulation->get_server(server_id);
d2e6a577 74 server.post(std::move(request), client_id, req_params);
7c673cae
FG
75 };
76
77 static std::vector<sim::CliInst> no_wait =
78 { { sim::req_op, client_total_ops, client_iops_goal, client_outstanding_ops } };
79 static std::vector<sim::CliInst> wait =
80 { { sim::wait_op, client_wait },
81 { sim::req_op, client_total_ops, client_iops_goal, client_outstanding_ops } };
82
83 simulation = new test::MySim();
84
85#if 1
86 test::MySim::ClientBasedServerSelectFunc server_select_f =
87 simulation->make_server_select_alt_range(client_server_select_range);
88#elif 0
89 test::MySim::ClientBasedServerSelectFunc server_select_f =
90 std::bind(&test::MySim::server_select_random, simulation, _1, _2);
91#else
92 test::MySim::ClientBasedServerSelectFunc server_select_f =
93 std::bind(&test::MySim::server_select_0, simulation, _1, _2);
94#endif
95
96 test::SimpleServer::ClientRespFunc client_response_f =
97 [&simulation](ClientId client_id,
98 const sim::TestResponse& resp,
99 const ServerId& server_id,
100 const ssched::NullData& resp_params) {
101 simulation->get_client(client_id).receive_response(resp,
102 server_id,
103 resp_params);
104 };
105
106 test::CreateQueueF create_queue_f =
107 [&](test::SimpleQueue::CanHandleRequestFunc can_f,
108 test::SimpleQueue::HandleRequestFunc handle_f) -> test::SimpleQueue* {
109 return new test::SimpleQueue(can_f, handle_f);
110 };
111
112 auto create_server_f = [&](ServerId id) -> test::SimpleServer* {
113 return new test::SimpleServer(id,
114 server_iops, server_threads,
115 client_response_f,
116 test::simple_server_accumulate_f,
117 create_queue_f);
118 };
119
120 auto create_client_f = [&](ClientId id) -> test::SimpleClient* {
121 return new test::SimpleClient(id,
122 server_post_f,
123 std::bind(server_select_f, _1, id),
124 test::simple_client_accumulate_f,
125 id < (client_count - client_wait_count)
126 ? no_wait : wait);
127 };
128
129 simulation->add_servers(server_count, create_server_f);
130 simulation->add_clients(client_count, create_client_f);
131
132 simulation->run();
133 simulation->display_stats(std::cout,
134 &test::server_data, &test::client_data,
135 server_disp_filter, client_disp_filter);
136} // main
137
138
139void test::client_data(std::ostream& out,
140 test::MySim* sim,
141 test::MySim::ClientFilter client_disp_filter,
142 int head_w, int data_w, int data_prec) {
143 // empty
144}
145
146
147void test::server_data(std::ostream& out,
148 test::MySim* sim,
149 test::MySim::ServerFilter server_disp_filter,
150 int head_w, int data_w, int data_prec) {
151 out << std::setw(head_w) << "requests:";
152 int total_req = 0;
153 for (uint i = 0; i < sim->get_server_count(); ++i) {
154 const auto& server = sim->get_server(i);
155 auto req_count = server.get_accumulator().request_count;
156 total_req += req_count;
157 if (!server_disp_filter(i)) continue;
158 out << std::setw(data_w) << req_count;
159 }
160 out << std::setw(data_w) << std::setprecision(data_prec) <<
161 std::fixed << total_req << std::endl;
162
163#ifdef PROFILE
164 crimson::ProfileCombiner<std::chrono::nanoseconds> art_combiner;
165 crimson::ProfileCombiner<std::chrono::nanoseconds> rct_combiner;
166 for (uint i = 0; i < sim->get_server_count(); ++i) {
167 const auto& q = sim->get_server(i).get_priority_queue();
168 const auto& art = q.add_request_timer;
169 art_combiner.combine(art);
170 const auto& rct = q.request_complete_timer;
171 rct_combiner.combine(rct);
172 }
173 out << "Server add_request_timer: count:" << art_combiner.get_count() <<
174 ", mean:" << art_combiner.get_mean() <<
175 ", std_dev:" << art_combiner.get_std_dev() <<
176 ", low:" << art_combiner.get_low() <<
177 ", high:" << art_combiner.get_high() << std::endl;
178 out << "Server request_complete_timer: count:" << rct_combiner.get_count() <<
179 ", mean:" << rct_combiner.get_mean() <<
180 ", std_dev:" << rct_combiner.get_std_dev() <<
181 ", low:" << rct_combiner.get_low() <<
182 ", high:" << rct_combiner.get_high() << std::endl;
183 out << "Server combined mean: " <<
184 (art_combiner.get_mean() + rct_combiner.get_mean()) <<
185 std::endl;
186#endif
187}