I just want to carry out a stress test.
Howerver, I found a TCP connection is not reused in a new RcfProtoChannel, though it connected to the same server.
Is there some way to reuse an existing TCP connection.
Or, is it by design in RCFProto framework that we cannot reuse a TCP connection?
Code: Select all
#include <iostream>
#include <RCF/RCFProto.hpp>
#include "ranking_service.pb.h"
namespace {
void OnCallCompletion(RCF::RcfProtoController* controller,
RankingResponse* response) {
if (controller->Failed()) {
std::cout << "Error: " << controller->ErrorText() << std::endl;
} else {
std::cout << "Received response:" << std::endl;
std::cout << response->DebugString() << std::endl;
}
// delete controller->getChannel();
delete response;
}
bool AllCompleted(const std::vector<RCF::RcfProtoController>& controllers) {
for (const RCF::RcfProtoController& controller : controllers) {
if (!controller.Completed()) {
return false;
}
}
return true;
}
} // namespace
int main(int argc, char* argv[]) {
try {
RCF::init();
RankingRequest request;
std::vector<RCF::RcfProtoController> controllers(std::stol(argv[1]));
const RCF::TcpEndpoint tcp_endpoint("127.0.0.1", 50001);
for (RCF::RcfProtoController& controller : controllers) {
RCF::RcfProtoChannel* channel =
new RCF::RcfProtoChannel(tcp_endpoint);
channel->setAsynchronousRpcMode(true);
channel->setConnectTimeoutMs(1000000);
RankingResponse* response = new RankingResponse;
RankingService::Stub stub(channel);
stub.Score(&controller,
&request,
response,
google::protobuf::NewCallback(OnCallCompletion, &controller, response));
std::cout << "Sending request:" << std::endl;
std::cout << request.DebugString() << std::endl;
}
int i = 0;
while (!AllCompleted(controllers)) {
RCF::sleepMs(1);
++i;
}
std::cout << "Have waited for " << i << " milliseconds." << std::endl;
} catch(const RCF::Exception & e) {
std::cout << "RCF::Exception: " << e.getErrorString() << std::endl;
return 1;
}
return 0;
}