MCPcopy Create free account
hub / github.com/PaddlePaddle/Serving / thread_worker

Function thread_worker

tools/cpp_examples/demo-client/src/ctr_prediction.cpp:152–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150}
151
152void thread_worker(PredictorApi* api,
153 int thread_id,
154 const std::vector<std::string>& data_list) {
155 // init
156 Request req;
157 Response res;
158 std::string line;
159
160 api->thrd_initialize();
161
162 for (int i = 0; i < FLAGS_repeat; ++i) {
163 int start_index = 0;
164
165 while (true) {
166 if (start_index >= data_list.size()) {
167 break;
168 }
169
170 api->thrd_clear();
171
172 Predictor* predictor = api->fetch_predictor("ctr_prediction_service");
173 if (!predictor) {
174 LOG(ERROR) << "Failed fetch predictor: ctr_prediction_service";
175 return;
176 }
177
178 req.Clear();
179 res.Clear();
180
181 // wait for other thread
182 while (g_concurrency.load() >= FLAGS_concurrency) {
183 }
184 g_concurrency++;
185 LOG(INFO) << "Current concurrency " << g_concurrency.load();
186
187 if (create_req(&req, data_list, start_index, FLAGS_batch_size) != 0) {
188 return;
189 }
190 start_index += FLAGS_batch_size;
191 LOG(INFO) << "start_index = " << start_index;
192
193 timeval start;
194 gettimeofday(&start, NULL);
195
196 if (predictor->inference(&req, &res) != 0) {
197 LOG(ERROR) << "failed call predictor with req:"
198 << req.ShortDebugString();
199 return;
200 }
201 g_concurrency--;
202
203 timeval end;
204 gettimeofday(&end, NULL);
205 uint64_t elapse_ms = (end.tv_sec * 1000 + end.tv_usec / 1000) -
206 (start.tv_sec * 1000 + start.tv_usec / 1000);
207
208 response_time[thread_id].push_back(elapse_ms);
209

Callers

nothing calls this directly

Calls 13

push_backMethod · 0.80
create_reqFunction · 0.70
print_resFunction · 0.70
thrd_initializeMethod · 0.45
sizeMethod · 0.45
thrd_clearMethod · 0.45
fetch_predictorMethod · 0.45
ClearMethod · 0.45
loadMethod · 0.45
inferenceMethod · 0.45
ShortDebugStringMethod · 0.45
tagMethod · 0.45

Tested by

no test coverage detected