Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transaction rate setting to perfclient #1071

Merged
merged 5 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions samples/perf_client/perf_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

// STL/3rdparty
#include <CLI11/CLI11.hpp>
#include <chrono>
#include <fstream>
#include <nlohmann/json.hpp>
#include <random>
Expand Down Expand Up @@ -63,6 +64,7 @@ namespace client
size_t max_writes_ahead = 0;
size_t latency_rounds = 1;
size_t generator_seed = 42u;
size_t transactions_per_s = 0;
ashamis marked this conversation as resolved.
Show resolved Hide resolved

bool sign = false;
bool no_create = false;
Expand Down Expand Up @@ -123,6 +125,11 @@ namespace client
->check(CLI::ExistingFile);
app.add_option("--generator-seed", generator_seed);

app.add_option(
"--transaction-rate",
transactions_per_s,
"The number of transactions per second to send");

// Transaction counts and batching details
app
.add_option(
Expand Down Expand Up @@ -289,6 +296,9 @@ namespace client
timing::ResponseTimes response_times;
timing::CommitPoint last_response_commit = {0, 0};

std::chrono::high_resolution_clock::time_point last_write_time;
std::chrono::nanoseconds write_delay_ns = std::chrono::nanoseconds::zero();

std::shared_ptr<RpcTlsClient> create_connection(bool force_unsigned = false)
{
// Create a cert if this is our first rpc_connection
Expand Down Expand Up @@ -379,6 +389,14 @@ namespace client
size_t read;
size_t written;

if (options.transactions_per_s > 0)
{
write_delay_ns =
std::chrono::nanoseconds{1000000000 / options.transactions_per_s};
connection->set_tcp_nodelay(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should set TCP_NODELAY in all cases, outside of this check. Even without a target transaction rate, this should make the performance tests more predictable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In throughput tests, I don't expect it will produce a measurable effect, we are writing heavily.

}

last_write_time = std::chrono::high_resolution_clock::now();
kick_off_timing();

// Repeat for each session
Expand Down Expand Up @@ -431,13 +449,21 @@ namespace client
size_t& written,
const std::shared_ptr<RpcTlsClient>& connection)
{
while (std::chrono::high_resolution_clock::now() - last_write_time <
write_delay_ns)
{
continue;
}

// Record time of sent requests
if (response_times.is_timing_active())
{
response_times.record_send(tx.method, tx.rpc.id, tx.expects_commit);
}

connection->write(tx.rpc.encoded);
last_write_time = std::chrono::high_resolution_clock::now();

++written;

// Optimistically read (non-blocking) any current responses
Expand Down
9 changes: 9 additions & 0 deletions src/clients/tls_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <mbedtls/error.h>
#include <mbedtls/net_sockets.h>
#include <mbedtls/ssl.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <string>
#include <vector>

Expand Down Expand Up @@ -185,4 +187,11 @@ class TlsClient

return buf;
}

void set_tcp_nodelay(bool on)
{
int option = on ? 1 : 0;
setsockopt(
server_fd.fd, IPPROTO_TCP, TCP_NODELAY, (char*)&option, sizeof(int));
}
};