]>
Commit | Line | Data |
---|---|---|
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. | |
11fdf7f2 TL |
6 | * |
7 | * Author: J. Eric Ivancich <ivancich@redhat.com> | |
8 | * | |
9 | * This is free software; you can redistribute it and/or modify it | |
10 | * under the terms of the GNU Lesser General Public License version | |
11 | * 2.1, as published by the Free Software Foundation. See file | |
12 | * COPYING. | |
7c673cae FG |
13 | */ |
14 | ||
15 | ||
16 | #include "test_ssched.h" | |
17 | ||
18 | ||
19 | #ifdef PROFILE | |
20 | #include "profile.h" | |
21 | #endif | |
22 | ||
23 | ||
24 | namespace test = crimson::test_simple_scheduler; | |
25 | namespace ssched = crimson::simple_scheduler; | |
26 | namespace sim = crimson::qos_simulation; | |
27 | ||
28 | using namespace std::placeholders; | |
29 | ||
30 | ||
31 | namespace crimson { | |
32 | namespace test_simple_scheduler { | |
33 | void client_data(std::ostream& out, | |
34 | test::MySim* sim, | |
35 | test::MySim::ClientFilter client_disp_filter, | |
36 | int head_w, int data_w, int data_prec); | |
37 | ||
38 | void server_data(std::ostream& out, | |
39 | test::MySim* sim, | |
40 | test::MySim::ServerFilter server_disp_filter, | |
41 | int head_w, int data_w, int data_prec); | |
42 | } // namespace test_simple | |
43 | } // namespace crimson | |
11fdf7f2 TL |
44 | |
45 | ||
46 | using Cost = uint32_t; | |
7c673cae FG |
47 | |
48 | ||
49 | int main(int argc, char* argv[]) { | |
50 | // server params | |
51 | ||
9f95a23c TL |
52 | const unsigned server_count = 100; |
53 | const unsigned server_iops = 40; | |
54 | const unsigned server_threads = 1; | |
7c673cae FG |
55 | |
56 | // client params | |
57 | ||
9f95a23c TL |
58 | const unsigned client_total_ops = 1000; |
59 | const unsigned client_count = 100; | |
60 | const unsigned client_server_select_range = 10; | |
61 | const unsigned client_wait_count = 1; | |
62 | const unsigned client_iops_goal = 50; | |
63 | const unsigned client_outstanding_ops = 100; | |
7c673cae FG |
64 | const std::chrono::seconds client_wait(10); |
65 | ||
66 | auto client_disp_filter = [=] (const ClientId& i) -> bool { | |
67 | return i < 3 || i >= (client_count - 3); | |
68 | }; | |
69 | ||
70 | auto server_disp_filter = [=] (const ServerId& i) -> bool { | |
71 | return i < 3 || i >= (server_count - 3); | |
72 | }; | |
73 | ||
74 | ||
75 | test::MySim *simulation; | |
76 | ||
77 | // lambda to post a request to the identified server; called by client | |
78 | test::SubmitFunc server_post_f = | |
79 | [&simulation](const ServerId& server_id, | |
d2e6a577 | 80 | sim::TestRequest&& request, |
7c673cae FG |
81 | const ClientId& client_id, |
82 | const ssched::ReqParams& req_params) { | |
83 | auto& server = simulation->get_server(server_id); | |
11fdf7f2 | 84 | server.post(std::move(request), client_id, req_params, 1u); |
7c673cae FG |
85 | }; |
86 | ||
87 | static std::vector<sim::CliInst> no_wait = | |
88 | { { sim::req_op, client_total_ops, client_iops_goal, client_outstanding_ops } }; | |
89 | static std::vector<sim::CliInst> wait = | |
90 | { { sim::wait_op, client_wait }, | |
91 | { sim::req_op, client_total_ops, client_iops_goal, client_outstanding_ops } }; | |
92 | ||
93 | simulation = new test::MySim(); | |
94 | ||
95 | #if 1 | |
96 | test::MySim::ClientBasedServerSelectFunc server_select_f = | |
97 | simulation->make_server_select_alt_range(client_server_select_range); | |
98 | #elif 0 | |
99 | test::MySim::ClientBasedServerSelectFunc server_select_f = | |
100 | std::bind(&test::MySim::server_select_random, simulation, _1, _2); | |
101 | #else | |
102 | test::MySim::ClientBasedServerSelectFunc server_select_f = | |
103 | std::bind(&test::MySim::server_select_0, simulation, _1, _2); | |
104 | #endif | |
105 | ||
106 | test::SimpleServer::ClientRespFunc client_response_f = | |
107 | [&simulation](ClientId client_id, | |
108 | const sim::TestResponse& resp, | |
109 | const ServerId& server_id, | |
11fdf7f2 TL |
110 | const ssched::NullData& resp_params, |
111 | Cost request_cost) { | |
7c673cae FG |
112 | simulation->get_client(client_id).receive_response(resp, |
113 | server_id, | |
11fdf7f2 TL |
114 | resp_params, |
115 | request_cost); | |
7c673cae FG |
116 | }; |
117 | ||
118 | test::CreateQueueF create_queue_f = | |
119 | [&](test::SimpleQueue::CanHandleRequestFunc can_f, | |
120 | test::SimpleQueue::HandleRequestFunc handle_f) -> test::SimpleQueue* { | |
121 | return new test::SimpleQueue(can_f, handle_f); | |
122 | }; | |
123 | ||
124 | auto create_server_f = [&](ServerId id) -> test::SimpleServer* { | |
125 | return new test::SimpleServer(id, | |
126 | server_iops, server_threads, | |
127 | client_response_f, | |
128 | test::simple_server_accumulate_f, | |
129 | create_queue_f); | |
130 | }; | |
131 | ||
132 | auto create_client_f = [&](ClientId id) -> test::SimpleClient* { | |
133 | return new test::SimpleClient(id, | |
134 | server_post_f, | |
135 | std::bind(server_select_f, _1, id), | |
136 | test::simple_client_accumulate_f, | |
137 | id < (client_count - client_wait_count) | |
138 | ? no_wait : wait); | |
139 | }; | |
140 | ||
141 | simulation->add_servers(server_count, create_server_f); | |
142 | simulation->add_clients(client_count, create_client_f); | |
143 | ||
144 | simulation->run(); | |
145 | simulation->display_stats(std::cout, | |
146 | &test::server_data, &test::client_data, | |
147 | server_disp_filter, client_disp_filter); | |
148 | } // main | |
149 | ||
150 | ||
151 | void test::client_data(std::ostream& out, | |
152 | test::MySim* sim, | |
153 | test::MySim::ClientFilter client_disp_filter, | |
154 | int head_w, int data_w, int data_prec) { | |
155 | // empty | |
156 | } | |
157 | ||
158 | ||
159 | void test::server_data(std::ostream& out, | |
160 | test::MySim* sim, | |
161 | test::MySim::ServerFilter server_disp_filter, | |
162 | int head_w, int data_w, int data_prec) { | |
163 | out << std::setw(head_w) << "requests:"; | |
164 | int total_req = 0; | |
9f95a23c | 165 | for (unsigned i = 0; i < sim->get_server_count(); ++i) { |
7c673cae FG |
166 | const auto& server = sim->get_server(i); |
167 | auto req_count = server.get_accumulator().request_count; | |
168 | total_req += req_count; | |
169 | if (!server_disp_filter(i)) continue; | |
170 | out << std::setw(data_w) << req_count; | |
171 | } | |
172 | out << std::setw(data_w) << std::setprecision(data_prec) << | |
173 | std::fixed << total_req << std::endl; | |
174 | ||
175 | #ifdef PROFILE | |
176 | crimson::ProfileCombiner<std::chrono::nanoseconds> art_combiner; | |
177 | crimson::ProfileCombiner<std::chrono::nanoseconds> rct_combiner; | |
9f95a23c | 178 | for (unsigned i = 0; i < sim->get_server_count(); ++i) { |
7c673cae FG |
179 | const auto& q = sim->get_server(i).get_priority_queue(); |
180 | const auto& art = q.add_request_timer; | |
181 | art_combiner.combine(art); | |
182 | const auto& rct = q.request_complete_timer; | |
183 | rct_combiner.combine(rct); | |
184 | } | |
185 | out << "Server add_request_timer: count:" << art_combiner.get_count() << | |
186 | ", mean:" << art_combiner.get_mean() << | |
187 | ", std_dev:" << art_combiner.get_std_dev() << | |
188 | ", low:" << art_combiner.get_low() << | |
189 | ", high:" << art_combiner.get_high() << std::endl; | |
190 | out << "Server request_complete_timer: count:" << rct_combiner.get_count() << | |
191 | ", mean:" << rct_combiner.get_mean() << | |
192 | ", std_dev:" << rct_combiner.get_std_dev() << | |
193 | ", low:" << rct_combiner.get_low() << | |
194 | ", high:" << rct_combiner.get_high() << std::endl; | |
195 | out << "Server combined mean: " << | |
196 | (art_combiner.get_mean() + rct_combiner.get_mean()) << | |
197 | std::endl; | |
198 | #endif | |
199 | } |