diff --git a/src/benchmark/taler-bank-benchmark.c b/src/benchmark/taler-bank-benchmark.c index 5c9c46af9..80636a60e 100644 --- a/src/benchmark/taler-bank-benchmark.c +++ b/src/benchmark/taler-bank-benchmark.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2014-2021 Taler Systems SA + (C) 2014-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as @@ -39,65 +39,16 @@ #include "taler_error_codes.h" -/* Error codes. */ -enum BenchmarkError -{ - MISSING_BANK_URL, - FAILED_TO_LAUNCH_BANK, - BAD_CLI_ARG, - BAD_CONFIG_FILE, - NO_CONFIG_FILE_GIVEN -}; - - /** - * What mode should the benchmark run in? + * Credentials to use for the benchmark. */ -enum BenchmarkMode -{ - /** - * Run as client against the bank. - */ - MODE_CLIENT = 1, - - /** - * Run the bank. - */ - MODE_BANK = 2, - - /** - * Run both, for a local benchmark. - */ - MODE_BOTH = 3, -}; - - -/** - * Hold information regarding which bank has the exchange account. - */ -static const struct TALER_EXCHANGEDB_AccountInfo *exchange_bank_account; - -/** - * Time snapshot taken right before executing the CMDs. - */ -static struct GNUNET_TIME_Absolute start_time; - -/** - * Benchmark duration time taken right after the CMD interpreter - * returns. - */ -static struct GNUNET_TIME_Relative duration; +static struct TALER_TESTING_Credentials cred; /** * Array of all the commands the benchmark is running. */ static struct TALER_TESTING_Command *all_commands; -/** - * Dummy keepalive task. - */ -static struct GNUNET_SCHEDULER_Task *keepalive; - /** * Name of our configuration file. */ @@ -105,27 +56,14 @@ static char *cfg_filename; /** * Use the fakebank instead of LibEuFin. - * NOTE: LibEuFin not yet supported! Set - * to 0 once we do support it! */ -static int use_fakebank = 1; - -/** - * Number of taler-exchange-wirewatchers to launch. - */ -static unsigned int start_wirewatch; +static int use_fakebank; /** * Verbosity level. */ static unsigned int verbose; -/** - * Size of the transaction history the fakebank - * should keep in RAM. - */ -static unsigned long long history_size = 65536; - /** * How many reserves we want to create per client. */ @@ -141,6 +79,11 @@ static unsigned int howmany_clients = 1; */ static unsigned int howmany_threads; +/** + * How many wirewatch processes do we want to create. + */ +static unsigned int start_wirewatch; + /** * Log level used during the run. */ @@ -151,32 +94,17 @@ static char *loglev; */ static char *logfile; -/** - * Benchmarking mode (run as client, exchange, both) as string. - */ -static char *mode_str; - -/** - * Benchmarking mode (run as client, bank, both). - */ -static enum BenchmarkMode mode; - -/** - * Don't kill exchange/fakebank/wirewatch until - * requested by the user explicitly. - */ -static int linger; - -/** - * Do not initialize or reset the database. - */ -static int incremental; - /** * Configuration. */ static struct GNUNET_CONFIGURATION_Handle *cfg; +/** + * Section with the configuration data for the exchange + * bank account. + */ +static char *exchange_bank_section; + /** * Currency used. */ @@ -237,10 +165,10 @@ print_stats (void) total = GNUNET_strdup ( GNUNET_STRINGS_relative_time_to_string (timings[i].total_duration, - GNUNET_YES)); + true)); latency = GNUNET_strdup ( GNUNET_STRINGS_relative_time_to_string (timings[i].success_latency, - GNUNET_YES)); + true)); fprintf (stderr, "%s-%d took %s in total with %s for latency for %u executions (%u repeats)\n", timings[i].prefix, @@ -270,38 +198,39 @@ run (void *cls, (void) cls; len = howmany_reserves + 2; - all_commands = GNUNET_malloc_large (len + all_commands = GNUNET_malloc_large ((1 + len) * sizeof (struct TALER_TESTING_Command)); GNUNET_assert (NULL != all_commands); + all_commands[0] + = TALER_TESTING_cmd_get_exchange ("get-exchange", + cred.cfg, + NULL, + true, + true); + GNUNET_asprintf (&total_reserve_amount, "%s:5", currency); for (unsigned int j = 0; j < howmany_reserves; j++) { char *create_reserve_label; - char *user_payto_uri; - // FIXME: vary user accounts more... - GNUNET_assert (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string (cfg, - "benchmark", - "USER_PAYTO_URI", - &user_payto_uri)); GNUNET_asprintf (&create_reserve_label, "createreserve-%u", j); - all_commands[j] + // TODO: vary user accounts more... + all_commands[1 + j] = TALER_TESTING_cmd_admin_add_incoming_retry ( TALER_TESTING_cmd_admin_add_incoming (add_label ( create_reserve_label), total_reserve_amount, - exchange_bank_account->auth, - add_label (user_payto_uri))); + &cred.ba, + cred.user42_payto)); } GNUNET_free (total_reserve_amount); - all_commands[howmany_reserves] + all_commands[1 + howmany_reserves] = TALER_TESTING_cmd_stat (timings); - all_commands[howmany_reserves + 1] + all_commands[1 + howmany_reserves + 1] = TALER_TESTING_cmd_end (); TALER_TESTING_run2 (is, all_commands, @@ -318,7 +247,6 @@ launch_clients (void) enum GNUNET_GenericReturnValue result = GNUNET_OK; pid_t cpids[howmany_clients]; - start_time = GNUNET_TIME_absolute_get (); if (1 == howmany_clients) { /* do everything in this process */ @@ -387,78 +315,6 @@ again: } -/** - * Stop the fakebank. - * - * @param cls fakebank handle - */ -static void -stop_fakebank (void *cls) -{ - struct TALER_FAKEBANK_Handle *fakebank = cls; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Stopping fakebank\n"); - TALER_FAKEBANK_stop (fakebank); - GNUNET_SCHEDULER_cancel (keepalive); - keepalive = NULL; -} - - -/** - * Dummy task that is never run. - */ -static void -never_task (void *cls) -{ - (void) cls; - GNUNET_assert (0); -} - - -/** - * Start the fakebank. - * - * @param cls NULL - */ -static void -launch_fakebank (void *cls) -{ - struct TALER_FAKEBANK_Handle *fakebank; - unsigned long long pnum; - - (void) cls; - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (cfg, - "bank", - "HTTP_PORT", - &pnum)) - { - GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, - "bank", - "HTTP_PORT", - "must be valid port number"); - return; - } - fakebank - = TALER_FAKEBANK_start2 ((uint16_t) pnum, - currency, - history_size, - howmany_threads); - if (NULL == fakebank) - { - GNUNET_break (0); - return; - } - keepalive - = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, - &never_task, - NULL); - GNUNET_SCHEDULER_add_shutdown (&stop_fakebank, - fakebank); -} - - /** * Run the benchmark in parallel in many (client) processes * and summarize result. @@ -469,278 +325,94 @@ static enum GNUNET_GenericReturnValue parallel_benchmark (void) { enum GNUNET_GenericReturnValue result = GNUNET_OK; - pid_t fakebank = -1; - struct GNUNET_OS_Process *bankd = NULL; struct GNUNET_OS_Process *wirewatch[GNUNET_NZL (start_wirewatch)]; memset (wirewatch, 0, sizeof (wirewatch)); - if ( (MODE_BANK == mode) || - (MODE_BOTH == mode) ) + /* start exchange wirewatch */ + for (unsigned int w = 0; w 10240) - { - TALER_LOG_ERROR ("-p option value given is too large\n"); - return BAD_CLI_ARG; - } - if (0 == howmany_clients) - { - TALER_LOG_ERROR ("-p option value must not be zero\n"); - GNUNET_free (cfg_filename); - return BAD_CLI_ARG; - } + return EXIT_NOTCONFIGURED; } if (GNUNET_OK != - TALER_EXCHANGEDB_load_accounts (cfg, - TALER_EXCHANGEDB_ALO_AUTHDATA - | TALER_EXCHANGEDB_ALO_CREDIT)) + TALER_TESTING_get_credentials ( + cfg_filename, + exchange_bank_section, + use_fakebank + ? TALER_TESTING_BS_FAKEBANK + : TALER_TESTING_BS_IBAN, + &cred)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Configuration fails to provide exchange bank details\n"); + "Required bank credentials not given in configuration\n"); GNUNET_free (cfg_filename); - return BAD_CONFIG_FILE; + return EXIT_NOTCONFIGURED; } - exchange_bank_account - = TALER_EXCHANGEDB_find_account_by_method ("x-taler-bank"); - if (NULL == exchange_bank_account) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "No bank account for `x-taler-bank` given in configuration\n"); - GNUNET_free (cfg_filename); - return BAD_CONFIG_FILE; - } - result = parallel_benchmark (); - TALER_EXCHANGEDB_unload_accounts (); - GNUNET_CONFIGURATION_destroy (cfg); - GNUNET_free (cfg_filename); + struct GNUNET_TIME_Absolute start_time; - if (MODE_BANK == mode) - { - /* If we're the bank, we're done now. No need to print results. */ - return (GNUNET_OK == result) ? 0 : result; + start_time = GNUNET_TIME_absolute_get (); + result = parallel_benchmark (); + duration = GNUNET_TIME_absolute_get_duration (start_time); } if (GNUNET_OK == result) @@ -952,7 +569,7 @@ main (int argc, tps); } fprintf (stdout, - "CPU time: sys %llu user %llu\n", \ + "CPU time: sys %llu user %llu\n", (unsigned long long) (usage.ru_stime.tv_sec * 1000 * 1000 + usage.ru_stime.tv_usec), (unsigned long long) (usage.ru_utime.tv_sec * 1000 * 1000 @@ -963,5 +580,7 @@ main (int argc, GNUNET_array_grow (labels, label_len, 0); + GNUNET_CONFIGURATION_destroy (cfg); + GNUNET_free (cfg_filename); return (GNUNET_OK == result) ? 0 : result; } diff --git a/src/benchmark/taler-exchange-benchmark.c b/src/benchmark/taler-exchange-benchmark.c index b7f9189b5..a4f9e11e7 100644 --- a/src/benchmark/taler-exchange-benchmark.c +++ b/src/benchmark/taler-exchange-benchmark.c @@ -210,13 +210,14 @@ run (void *cls, char *amount_1; (void) cls; - all_commands = GNUNET_new_array ( - 1 /* exchange CMD */ - + howmany_reserves * (1 /* Withdraw block */ - + howmany_coins) /* All units */ - + 1 /* stat CMD */ - + 1 /* End CMD */, - struct TALER_TESTING_Command); + all_commands = GNUNET_malloc_large ( + (1 /* exchange CMD */ + + howmany_reserves + * (1 /* Withdraw block */ + + howmany_coins) /* All units */ + + 1 /* stat CMD */ + + 1 /* End CMD */) * sizeof (struct TALER_TESTING_Command)); + GNUNET_assert (NULL != all_commands); all_commands[0] = TALER_TESTING_cmd_get_exchange ("get-exchange", cred.cfg,