bool BNRPAssociator::GetPoiRecomList(string str_ip_port,string algorithm_id,const int req_source,double x, double y, int area_id, vector<uint64_t> poi_list) { // 全局变量,需要传过来 const uint32_t &soul_time_out = 3000; const char *soul_ip_port = str_ip_port.c_str(); //"10.48.55.39:7789"; const char *soul_default_algorithm_id = algorithm_id.c_str(); //"bnitems"; // sofa::pbrpc::RpcClientOptions client_options; sofa::pbrpc::RpcClient rpc_client(client_options); // Define an rpc channel. sofa::pbrpc::RpcChannelOptions channel_options; sofa::pbrpc::RpcChannel rpc_channel(&rpc_client, soul_ip_port, channel_options); // Prepare parameters. sofa::pbrpc::RpcController cntl; cntl.SetTimeout(soul_time_out); GetBNItemsRequest request; ConstructSoulRequest(request,req_source,x,y,area_id,poi_list,soul_default_algorithm_id); GetBNItemsResponse response; // Sync call. lbs::da::openservice::ItemService_Stub stub(&rpc_channel); stub.GetBNItemsByItem(&cntl, &request, &response, NULL); // Check if the request has been sent. // If has been sent, then can get the sent bytes. // MERGER_LOG_DEBUG("RemoteAddress=%s", cntl.RemoteAddress().c_str()); // MERGER_LOG_DEBUG("IsRequestSent=%s", cntl.IsRequestSent() ? "true" : "false"); /* if (cntl.IsRequestSent()) { MERGER_LOG_DEBUG("LocalAddress=%s", cntl.LocalAddress().c_str()); MERGER_LOG_DEBUG("SentBytes=%ld", cntl.SentBytes()); }*/ // Check if failed. if (cntl.Failed()) { printf("request failed: %s", cntl.ErrorText().c_str()); return false; } else { //#ifdef POI_DEBUG // for debug /*cout << "request [" << request.query() << "] "; for (int i = 0; i < request.item_ids_size(); ++i) { cout << "[" << *reinterpret_cast<const uint64_t*>(request.item_ids(i).c_str()) << "] "; } cout << " x:" << request.x() << " y:" << request.y() << endl;*/ //#endif // 解析结果 return ParseSoulResponse(response); } }
int benchmark_server_connections_per_minute() { int err; // Configure the server uint16_t port = 0; char addr[] = "127.0.0.1"; struct rpc_handler handlers[] = { NULL }; int comm[2]; struct rpc_server_config server_config = { /* .addr = */ addr, /* .port = */ port, /* .handlers = */ handlers, /* .not_found = */ NULL, /* .comm = */ comm }; // Configure the client struct rpc_client_config client_config = { /* .addr = */ addr, /* .port = */ 0, }; // Start the server in the background rpc_server_start_background(&server_config); // Set the client port to be what the server reports its port is client_config.port = server_config.port; // Count number of connections int num_con = 0; // Get the time before requests start time_t start, end; start = time(NULL); do { // Make the request err = rpc_client(&client_config); if (err == -1) { // Report the exit status and exit printf("Error from client: %d\n", errno); } // Update num_con ++num_con; // Update end time end = time(NULL); } while (difftime(end, start) < 1.00); // Time spent double diff = difftime(end, start); // Report printf("benchmark_server_connections_per_minute: %d connections in %0.02f seconds\n", num_con, diff); // Stop the server before we (the client) exit rpc_server_stop(&server_config); return EXIT_SUCCESS; }