| 121 | } |
| 122 | |
| 123 | void 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 | |
| 169 | void calc_time(int server_concurrency, int batch_size) { |
| 170 | std::vector<int> time_list; |
nothing calls this directly
no test coverage detected