Skip to content

Commit

Permalink
Optimize client by opening transport to host once (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasondu7297 authored Dec 28, 2023
1 parent bd7cbea commit a71be05
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/client/SharedQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,22 @@ class WarmUpRunner {
WarmUpRunner(SharedQueue& sharedQueue): sharedQueue(sharedQueue) {}

void operator()() {
auto socket = std::make_shared<TSocket>(HOST_IP, HOST_PORT);
auto transport = std::make_shared<TBufferedTransport>(socket);
auto protocol = std::make_shared<TBinaryProtocol>(transport);
RPCClient client(protocol);

transport->open();

while (warmupOperations--) {
Operation data = sharedQueue.dequeue();
if (data.op == OpType::EOD) return;

auto socket = std::make_shared<TSocket>(HOST_IP, HOST_PORT);
auto transport = std::make_shared<TBufferedTransport>(socket);
auto protocol = std::make_shared<TBinaryProtocol>(transport);
RPCClient client(protocol);

transport->open();
std::string out;
client.access(out, data);
transport->close();
}

transport->close();
}
};

Expand All @@ -113,26 +115,26 @@ class ClientRunner {
sharedQueue(sharedQueue), latencies(latencies) {}

void operator()() {
auto socket = std::make_shared<TSocket>(HOST_IP, HOST_PORT);
auto transport = std::make_shared<TBufferedTransport>(socket);
auto protocol = std::make_shared<TBinaryProtocol>(transport);
RPCClient client(protocol);

transport->open();

while (true) {
Operation data = sharedQueue.dequeue();
if (data.op == OpType::EOD) return;

auto socket = std::make_shared<TSocket>(HOST_IP, HOST_PORT);
auto transport = std::make_shared<TBufferedTransport>(socket);
auto protocol = std::make_shared<TBinaryProtocol>(transport);
RPCClient client(protocol);

transport->open();

auto start = high_resolution_clock::now();
std::string out;
client.access(out, data);
auto end = high_resolution_clock::now();
latencies.push_back(
duration_cast<milliseconds>(end - start).count());

transport->close();
}

transport->close();
}
};

Expand Down

0 comments on commit a71be05

Please sign in to comment.