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

Function thread_worker

tools/cpp_examples/demo-client/src/bert_service.cpp:123–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121}
122
123void thread_worker(PredictorApi* api,
124 int thread_id,
125 int batch_size,
126 int server_concurrency,
127 const std::vector<std::string>& data_list) {
128 Request req;
129 Response res;
130 api->thrd_initialize();
131 std::string line;
132 int turns = 0;
133 while (turns < max_turn) {
134 timeval start;
135 gettimeofday(&start, NULL);
136 api->thrd_clear();
137 Predictor* predictor = api->fetch_predictor("bert_service");
138 if (!predictor) {
139 LOG(ERROR) << "Failed fetch predictor: bert_service";
140 return;
141 }
142 req.Clear();
143 res.Clear();
144 while (g_concurrency.load() >= server_concurrency) {
145 }
146 g_concurrency++;
147 LOG(INFO) << "Current concurrency " << g_concurrency.load();
148 int data_index = turns * batch_size;
149 if (create_req(&req, data_list, data_index, batch_size) != 0) {
150 return;
151 }
152 if (predictor->inference(&req, &res) != 0) {
153 LOG(ERROR) << "failed call predictor with req:" << req.ShortDebugString();
154 return;
155 }
156 timeval end;
157 gettimeofday(&end, NULL);
158 uint64_t elapse_ms = (end.tv_sec * 1000 + end.tv_usec / 1000) -
159 (start.tv_sec * 1000 + start.tv_usec / 1000);
160 response_time[thread_id].push_back(elapse_ms);
161 print_res(req, res, predictor->tag(), elapse_ms);
162 g_concurrency--;
163 LOG(INFO) << "Done. Current concurrency " << g_concurrency.load();
164 turns++;
165 }
166 api->thrd_finalize();
167}
168
169void calc_time(int server_concurrency, int batch_size) {
170 std::vector<int> time_list;

Callers

nothing calls this directly

Calls 12

push_backMethod · 0.80
create_reqFunction · 0.70
print_resFunction · 0.70
thrd_initializeMethod · 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
thrd_finalizeMethod · 0.45

Tested by

no test coverage detected