| 150 | } |
| 151 | |
| 152 | void 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 |
nothing calls this directly
no test coverage detected