Skip to content

Commit

Permalink
Add generic JSON-scenario perf client (microsoft#618)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyashton authored Dec 9, 2019
1 parent 2063934 commit ab42f9c
Show file tree
Hide file tree
Showing 8 changed files with 868 additions and 33 deletions.
23 changes: 21 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ target_link_libraries(logging_client PRIVATE
${CMAKE_THREAD_LIBS_INIT}
)

add_enclave_lib(loggingenc ${CMAKE_CURRENT_SOURCE_DIR}/src/apps/logging/oe_sign.conf ${CMAKE_CURRENT_SOURCE_DIR}/src/apps/sample_key.pem SRCS src/apps/logging/logging.cpp src/apps/logging/stub_for_code_signing.cpp)
add_enclave_lib(loggingenc
${CMAKE_CURRENT_SOURCE_DIR}/src/apps/logging/oe_sign.conf
${CMAKE_CURRENT_SOURCE_DIR}/src/apps/sample_key.pem
SRCS
src/apps/logging/logging.cpp
src/apps/logging/stub_for_code_signing.cpp
)

if(BUILD_TESTS)
# Tests
Expand Down Expand Up @@ -414,8 +420,21 @@ if(BUILD_TESTS)
ADDITIONAL_ARGS
--election-timeout 2000
)
endif()

if (NOT PBFT)
# Logging scenario perf test
add_perf_test(
NAME logging_scenario_perf_test
PYTHON_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/tests/perfclient.py
CLIENT_BIN ./scenario_perf_client
LABEL logging_scenario_perf_test
ADDITIONAL_ARGS
--package libloggingenc
--scenario-file ${CMAKE_CURRENT_LIST_DIR}/tests/perf_logging_scenario_100txs.json
--repetitions 1000
)
endif()
endif()

if (EXTENSIVE_TESTS)
set_tests_properties(recovery_tests PROPERTIES TIMEOUT 2000)
Expand Down
23 changes: 12 additions & 11 deletions cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,16 @@ target_link_libraries(client PRIVATE
)
add_dependencies(client flatbuffers)

# Perf scenario executable
add_executable(scenario_perf_client
${CCF_DIR}/samples/perf_client/scenario_perf_client.cpp
)
use_client_mbedtls(scenario_perf_client)
target_link_libraries(scenario_perf_client PRIVATE
${CMAKE_THREAD_LIBS_INIT}
secp256k1.host
)

# Lua for host and enclave
add_enclave_library_c(lua.enclave "${LUA_SOURCES}")
target_compile_definitions(lua.enclave PRIVATE NO_IO)
Expand Down Expand Up @@ -589,9 +599,6 @@ add_enclave_lib(luagenericenc ${CCF_DIR}/src/apps/luageneric/oe_sign.conf ${CCF_

# Samples

# Common options
set(TEST_ITERATIONS 200000)

## Helper for building clients inheriting from perf_client
function(add_client_exe name)

Expand Down Expand Up @@ -675,15 +682,10 @@ function(add_perf_test)

cmake_parse_arguments(PARSE_ARGV 0 PARSED_ARGS
""
"NAME;PYTHON_SCRIPT;CLIENT_BIN;ITERATIONS;VERIFICATION_FILE;LABEL"
"NAME;PYTHON_SCRIPT;CLIENT_BIN;VERIFICATION_FILE;LABEL"
"ADDITIONAL_ARGS"
)

## Use default value if undefined
if(NOT PARSED_ARGS_ITERATIONS)
set(PARSED_ARGS_ITERATIONS ${TEST_ITERATIONS})
endif()

if(PARSED_ARGS_VERIFICATION_FILE)
set(VERIFICATION_ARG "--verify ${PARSED_ARGS_VERIFICATION_FILE}")
else()
Expand All @@ -705,12 +707,11 @@ function(add_perf_test)
COMMAND ${PYTHON} ${PARSED_ARGS_PYTHON_SCRIPT}
-b .
-c ${PARSED_ARGS_CLIENT_BIN}
-i ${PARSED_ARGS_ITERATIONS}
${CCF_NETWORK_TEST_ARGS}
${PARSED_ARGS_ADDITIONAL_ARGS}
--write-tx-times
${VERIFICATION_ARG}
${LABEL_ARG}
${PARSED_ARGS_ADDITIONAL_ARGS}
)

## Make python test client framework importable
Expand Down
6 changes: 3 additions & 3 deletions samples/apps/smallbank/smallbank.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ if(BUILD_TESTS)
PYTHON_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/tests/small_bank_client.py
CLIENT_BIN ./small_bank_client
VERIFICATION_FILE ${SMALL_BANK_VERIFICATION_FILE}
ITERATIONS ${SMALL_BANK_ITERATIONS}
LABEL Small_Bank_ClientCpp
ADDITIONAL_ARGS
--transactions ${SMALL_BANK_ITERATIONS}
--max-writes-ahead 1000
--metrics-file small_bank_metrics.json
)
Expand All @@ -51,9 +51,9 @@ if(BUILD_TESTS)
PYTHON_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/tests/small_bank_client.py
CLIENT_BIN ./small_bank_client
VERIFICATION_FILE ${SMALL_BANK_SIGNED_VERIFICATION_FILE}
ITERATIONS ${SMALL_BANK_SIGNED_ITERATIONS}
LABEL Small_Bank_Client_Sigs
ADDITIONAL_ARGS
--transactions ${SMALL_BANK_SIGNED_ITERATIONS}
--max-writes-ahead 1000
--sign
--metrics-file small_bank_sigs_metrics.json
Expand All @@ -65,9 +65,9 @@ if(BUILD_TESTS)
NAME small_bank_sigs_forwarding
PYTHON_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/tests/small_bank_client.py
CLIENT_BIN ./small_bank_client
ITERATIONS ${SMALL_BANK_SIGNED_ITERATIONS}
LABEL Small_Bank_ClientSigs_Forwarding
ADDITIONAL_ARGS
--transactions ${SMALL_BANK_SIGNED_ITERATIONS}
--max-writes-ahead 1000
--metrics-file small_bank_fwd_metrics.json
-n localhost -n localhost
Expand Down
122 changes: 122 additions & 0 deletions samples/perf_client/scenario_perf_client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache 2.0 License.
#include "ds/files.h"
#include "perf_client.h"

#include <nlohmann/json.hpp>
#include <string>

using Base = client::PerfBase;

class ScenarioPerfClient : public Base
{
private:
size_t repetitions = 1;
std::string scenario_file;
nlohmann::json scenario_json;

void send_verbose_transactions(
const std::shared_ptr<RpcTlsClient>& connection, char const* element_name)
{
const auto it = scenario_json.find(element_name);

if (it != scenario_json.end())
{
const auto transactions = *it;
if (!transactions.is_array())
{
throw std::runtime_error(fmt::format(
"Expected scenario to contain '{}' field containing an array of "
"transaction objects",
element_name));
}

std::cout << fmt::format(
"Sending {} {} transactions",
transactions.size(),
element_name)
<< std::endl;
for (const auto& transaction : transactions)
{
const auto method = transaction["method"];
const auto params = transaction["params"];

std::cout << fmt::format("Sending {}: {}", method, params.dump(2))
<< std::endl;
const auto response =
nlohmann::json::from_msgpack(connection->call(method, params));
std::cout << fmt::format("Response: {}", response.dump(2)) << std::endl;
}
}
}

void pre_creation_hook() override
{
scenario_json = files::slurp_json(scenario_file);
}

void send_creation_transactions(
const std::shared_ptr<RpcTlsClient>& connection) override
{
send_verbose_transactions(connection, "setup");
}

void post_timing_body_hook() override
{
const auto connection = create_connection();
send_verbose_transactions(connection, "cleanup");
}

void prepare_transactions() override
{
constexpr auto transactions_element_name = "transactions";

const auto transactions = scenario_json[transactions_element_name];
if (!transactions.is_array())
{
throw std::runtime_error(fmt::format(
"Expected scenario to contain '{}' field containing an array of "
"transaction objects",
transactions_element_name));
}

// Reserve space for transactions
prepared_txs.reserve(transactions.size() * repetitions);

for (size_t r = 0; r < repetitions; ++r)
{
for (size_t i = 0; i < transactions.size(); ++i)
{
const auto& transaction = transactions[i];

add_prepared_tx(
transaction["method"], transaction["params"], true, std::nullopt);
}
}
}

public:
ScenarioPerfClient() : Base("scenario_perf") {}

void setup_parser(CLI::App& app) override
{
Base::setup_parser(app);

app.add_option("--repetitions", repetitions);
app.add_option("--scenario-file", scenario_file)
->required(true)
->check(CLI::ExistingFile);
}
};

int main(int argc, char** argv)
{
ScenarioPerfClient client;
CLI::App cli_app{"Scenario Perf Client"};
client.setup_parser(cli_app);
CLI11_PARSE(cli_app, argc, argv);

client.run();

return 0;
}
2 changes: 0 additions & 2 deletions tests/infra/remote_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def __init__(
node_port,
workspace,
label,
iterations,
config,
command_args,
remote_class,
Expand Down Expand Up @@ -56,7 +55,6 @@ def __init__(
cmd = [
self.BIN,
f"--rpc-address={node_host}:{node_port}",
f"--transactions={iterations}",
f"--config={os.path.basename(config)}",
] + client_command_args

Expand Down
3 changes: 0 additions & 3 deletions tests/infra/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ def get_command_args(args, get_command):
command_args = []
if args.label:
command_args.append("--label={}".format(args.label))
if args.sign:
command_args.append("--sign")
return get_command(*command_args)


Expand Down Expand Up @@ -68,7 +66,6 @@ def configure_remote_client(args, client_id, client_host, node, command_args):
node.rpc_port,
args.workspace,
args.label,
args.iterations,
args.config,
command_args,
remote_impl,
Expand Down
Loading

0 comments on commit ab42f9c

Please sign in to comment.