From 96e047b186245ab8f0883bb0e0fe9dfaff3ef407 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sun, 19 Aug 2018 00:49:16 +0200 Subject: add remote benchmarking --- src/benchmark/benchmark.conf | 4 + .../.config/taler/account-2.json | 4 +- src/benchmark/taler-exchange-benchmark.c | 477 ++++++++++++++------- 3 files changed, 326 insertions(+), 159 deletions(-) (limited to 'src/benchmark') diff --git a/src/benchmark/benchmark.conf b/src/benchmark/benchmark.conf index 045cc0a27..a160cc1cd 100644 --- a/src/benchmark/benchmark.conf +++ b/src/benchmark/benchmark.conf @@ -32,6 +32,10 @@ lookahead_sign = 12 h [exchangedb-postgres] config = "postgres:///talercheck" +[benchmark-remote-exchange] +host = localhost +dir = /home/dold/repos/taler/exchange/src/benchmark + [account-2] # What is the bank account (with the "Taler Bank" demo system)? URL = "payto://x-taler-bank/localhost:8082/2" diff --git a/src/benchmark/exchange_benchmark_home/.config/taler/account-2.json b/src/benchmark/exchange_benchmark_home/.config/taler/account-2.json index a99f114f0..ff4a4a25a 100644 --- a/src/benchmark/exchange_benchmark_home/.config/taler/account-2.json +++ b/src/benchmark/exchange_benchmark_home/.config/taler/account-2.json @@ -1,5 +1,5 @@ { "url": "payto://x-taler-bank/localhost:8082/2", - "salt": "121B05SK5B4P0ZXQ748G3HCXA35W3QYQ6KP799TEMSJSVYHCG5CNZWY2CYD5RN4QHYBFWM1M8973W3X9PBKW78D49QV4D7NT7PEE040", - "master_sig": "WJWQBR8M0M9CENCBZVRDT2D6YMCD1AYN1JS54KX0Q7VRMS163800GP25871Y96T0TPF1SN1CPR6TE3KG4VZXW8HJPENVC8PAK01S218" + "salt": "S6DM52Z465K13EBEK5GRPT5WWK36EY7GHADJMFS7DB9WGXW6385FWXXHR325VYETCN63SS21AV6ZT77H7VZ8KY9G1QPPKKSMAG6GE98", + "master_sig": "NPPB20YYYP2BEHSZGKCTKJH217FFSQC38P1Z6TCDQ55DHXFPV1XAHCY8Z0PEJXJJ0AAR7MMPXAE8RS1W6G72E8715PS2DC5WT5WJ42R" } \ No newline at end of file diff --git a/src/benchmark/taler-exchange-benchmark.c b/src/benchmark/taler-exchange-benchmark.c index 58cff7714..ed923cd3b 100644 --- a/src/benchmark/taler-exchange-benchmark.c +++ b/src/benchmark/taler-exchange-benchmark.c @@ -100,6 +100,27 @@ struct Account }; +/** + * What mode should the benchmark run in? + */ +enum BenchmarkMode { + /** + * Run as client (with fakebank), also starts a remote exchange. + */ + MODE_CLIENT = 1, + + /** + * Run the the exchange. + */ + MODE_EXCHANGE = 2, + + /** + * Run both, for a local benchmark. + */ + MODE_BOTH = 3, +}; + + /** * Hold information regarding which bank has the exchange account. */ @@ -146,6 +167,16 @@ static char *loglev; */ static char *logfile; +/** + * Benchmarking mode (run as client, exchange, both) as string. + */ +static char *mode_str; + +/** + * Benchmarking mode (run as client, exchange, both). + */ +static enum BenchmarkMode mode; + /** * Config filename. */ @@ -156,6 +187,16 @@ static char *cfg_filename; */ static char *currency; +/** + * Remote host that runs the exchange. + */ +static char *remote_host; + +/** + * Remote benchmarking directory. + */ +static char *remote_dir; + /** * Convenience macros to allocate all the currency-dependant * strings; note that the argument list of the macro is ignored. @@ -163,19 +204,6 @@ static char *currency; * where it is called. */ #define ALLOCATE_AMOUNTS(...) \ - char *AMOUNT_5; \ - char *AMOUNT_4; \ - char *AMOUNT_1; \ - \ - GNUNET_asprintf (&AMOUNT_5, \ - "%s:5", \ - currency); \ - GNUNET_asprintf (&AMOUNT_4, \ - "%s:4", \ - currency); \ - GNUNET_asprintf (&AMOUNT_1, \ - "%s:1", \ - currency); /** * Decide which exchange account is going to be @@ -190,7 +218,7 @@ pick_exchange_account_cb (void *cls, const char *section) { if (0 == strncasecmp ("account-", - section, + section, strlen ("account-"))) { const char **s = cls; @@ -332,17 +360,21 @@ run (void *cls, [howmany_reserves * (1 + /* Withdraw block */ howmany_coins) + /* All units */ 1 /* End CMD */]; + char *AMOUNT_5; + char *AMOUNT_4; + char *AMOUNT_1; + + GNUNET_asprintf (&AMOUNT_5, "%s:5", currency); + GNUNET_asprintf (&AMOUNT_4, "%s:4", currency); + GNUNET_asprintf (&AMOUNT_1, "%s:1", currency); ALLOCATE_AMOUNTS (AMOUNT_5, AMOUNT_4, AMOUNT_1); + GNUNET_assert (GNUNET_OK == TALER_amount_get_zero (currency, &total_reserve_amount)); total_reserve_amount.value = 5 * howmany_coins; - total_reserve_amount.fraction = 0; - strncpy (total_reserve_amount.currency, - currency, - TALER_CURRENCY_LEN); GNUNET_asprintf (&withdraw_fee_str, "%s:0.1", @@ -535,117 +567,215 @@ parallel_benchmark (TALER_TESTING_Main main_cb, const char *config_file, const char *exchange_url) { - int result; + int result = GNUNET_OK; pid_t cpids[howmany_clients]; - pid_t fakebank; + pid_t fakebank = -1; int wstatus; - struct GNUNET_OS_Process *exchanged; - struct GNUNET_OS_Process *wirewatch; + struct GNUNET_OS_Process *exchanged = NULL; + struct GNUNET_OS_Process *wirewatch = NULL; + struct GNUNET_OS_Process *exchange_slave = NULL; - /* start fakebank */ - fakebank = fork (); - if (0 == fakebank) + if ( (MODE_CLIENT == mode) || (MODE_BOTH == mode) ) { - GNUNET_SCHEDULER_run (&launch_fakebank, - exchange_bank_account.bank_base_url); - exit (0); - } - if (-1 == fakebank) - { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, - "fork"); - return GNUNET_SYSERR; + + /* start fakebank */ + fakebank = fork (); + if (0 == fakebank) + { + GNUNET_SCHEDULER_run (&launch_fakebank, + exchange_bank_account.bank_base_url); + exit (0); + } + if (-1 == fakebank) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, + "fork"); + return GNUNET_SYSERR; + } } - /* start exchange */ - exchanged = GNUNET_OS_start_process (GNUNET_NO, - GNUNET_OS_INHERIT_STD_ALL, - NULL, NULL, NULL, - "taler-exchange-httpd", - "taler-exchange-httpd", - "-c", config_file, - "-i", - "-C", - NULL); - if (NULL == exchanged) + if ( (MODE_EXCHANGE == mode) || (MODE_BOTH == mode) ) { - kill (fakebank, - SIGTERM); - waitpid (fakebank, - &wstatus, - 0); - return 77; + /* start exchange */ + exchanged = GNUNET_OS_start_process (GNUNET_NO, + GNUNET_OS_INHERIT_STD_ALL, + NULL, NULL, NULL, + "taler-exchange-httpd", + "taler-exchange-httpd", + "-c", config_file, + "-i", + "-C", + NULL); + if ( (NULL == exchanged) && (MODE_BOTH == mode) ) + { + GNUNET_assert (-1 != fakebank); + kill (fakebank, + SIGTERM); + waitpid (fakebank, + &wstatus, + 0); + return 77; + } + /* start exchange wirewatch */ + wirewatch = GNUNET_OS_start_process (GNUNET_NO, + GNUNET_OS_INHERIT_STD_ALL, + NULL, NULL, NULL, + "taler-exchange-wirewatch", + "taler-exchange-wirewatch", + "-c", config_file, + NULL); + if (NULL == wirewatch) + { + GNUNET_OS_process_kill (exchanged, + SIGTERM); + if (MODE_BOTH == mode) + { + GNUNET_assert (-1 != fakebank); + kill (fakebank, + SIGTERM); + waitpid (fakebank, + &wstatus, + 0); + } + GNUNET_OS_process_destroy (exchanged); + return 77; + } } - /* start exchange */ - wirewatch = GNUNET_OS_start_process (GNUNET_NO, - GNUNET_OS_INHERIT_STD_ALL, - NULL, NULL, NULL, - "taler-exchange-wirewatch", - "taler-exchange-wirewatch", - "-c", config_file, - NULL); - if (NULL == wirewatch) + + if (MODE_CLIENT == mode) { - GNUNET_OS_process_kill (exchanged, - SIGTERM); - kill (fakebank, - SIGTERM); - GNUNET_OS_process_wait (exchanged); - GNUNET_OS_process_destroy (exchanged); - waitpid (fakebank, - &wstatus, - 0); - return 77; + char *remote_cmd; + + GNUNET_asprintf (&remote_cmd, + ("cd '%s'; " + "taler-exchange-benchmark --mode=exchange -c '%s'"), + remote_dir, + config_file); + + printf ("remote command: %s\n", remote_cmd); + + exchange_slave = GNUNET_OS_start_process (GNUNET_NO, + GNUNET_OS_INHERIT_STD_ALL, + NULL, NULL, NULL, + "ssh", + "ssh", + /* Don't ask for pw/passphrase, rather fail */ + "-oBatchMode=yes", + remote_host, + remote_cmd, + NULL); + GNUNET_free (remote_cmd); } + + /* We always wait for the exchange, no matter if it's running locally or + remotely */ if (0 != TALER_TESTING_wait_exchange_ready (exchange_url)) { GNUNET_OS_process_kill (exchanged, SIGTERM); - kill (fakebank, - SIGTERM); + if ( (MODE_BOTH == mode) || (MODE_CLIENT == mode)) + { + GNUNET_assert (-1 != fakebank); + kill (fakebank, + SIGTERM); + waitpid (fakebank, + &wstatus, + 0); + } GNUNET_OS_process_wait (exchanged); GNUNET_OS_process_destroy (exchanged); - waitpid (fakebank, - &wstatus, - 0); return 77; } - sleep (1); /* make sure fakebank process is ready before continuing */ - - start_time = GNUNET_TIME_absolute_get (); - result = GNUNET_OK; - for (unsigned int i=0;i