| | |
| | | { |
| | | const std::string shm_name("ShmReqRep"); |
| | | ShmRemover auto_remove(shm_name); |
| | | SharedMemory shm(shm_name, 1024 * 1024 * 50); |
| | | SharedMemory shm(shm_name, 1024 * 1024 * 512); |
| | | |
| | | auto Avail = [&]() { return shm.get_free_memory(); }; |
| | | auto init_avail = Avail(); |
| | |
| | | printf("count: %d\n", count.load()); |
| | | } |
| | | }; |
| | | MsgRequestTopic req; |
| | | req.set_topic(topic); |
| | | req.set_data("data " + std::string(100, 'a')); |
| | | client.ClientStartWorker(onRecv, 2); |
| | | boost::timer::auto_cpu_timer timer; |
| | | for (int i = 0; i < nreq; ++i) { |
| | | MsgRequestTopic req; |
| | | req.set_topic(topic); |
| | | req.set_data("data " + std::to_string(i)); |
| | | std::string msg_id; |
| | | if (!client.ClientAsyncRequest(req, msg_id)) { |
| | | printf("client request failed\n"); |
| | | ++count; |
| | | } |
| | | |
| | | // if (!client.SyncRequest(topic, "data " + std::to_string(i), reply, 1000)) { |
| | | // std::string proc_id; |
| | | // MsgRequestTopicReply reply; |
| | | // if (!client.ClientSyncRequest(req, proc_id, reply, 1000)) { |
| | | // printf("client request failed\n"); |
| | | // } |
| | | // ++count; |
| | | // ++count; |
| | | } |
| | | do { |
| | | std::this_thread::yield(); |
| | |
| | | servers.Launch(Server, "server", topics); |
| | | Sleep(100ms); |
| | | for (auto &t : topics) { |
| | | clients.Launch(Client, t, 1000 * 100); |
| | | clients.Launch(Client, t, 1000 * 100 * 2); |
| | | } |
| | | clients.WaitAll(); |
| | | printf("clients done, server replyed: %ld\n", server_msg_count.load()); |