2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file fs/perf_gnunet_service_fs_p2p.c
23 * @brief profile P2P routing using simple publish + download operation
24 * @author Christian Grothoff
27 #include "fs_test_lib.h"
28 #include "gnunet_testing_lib.h"
30 #define VERBOSE GNUNET_NO
33 * File-size we use for testing.
35 #define FILESIZE (1024 * 1024 * 1)
38 * How long until we give up on transmitting the message?
40 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
46 static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS];
50 static struct GNUNET_TIME_Absolute start_time;
52 static const char *progname;
56 const struct GNUNET_SCHEDULER_TaskContext *tc)
58 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
64 * Master context for 'stat_run'.
68 struct GNUNET_STATISTICS_Handle *stat;
75 const char *subsystem;
80 * Statistics we print out.
82 static struct StatValues stats[] =
84 { "fs", "# queries forwarded"},
85 { "fs", "# replies received and matched"},
86 { "fs", "# results found locally"},
87 { "fs", "# requests forwarded due to high load"},
88 { "fs", "# requests done for free (low load)"},
89 { "fs", "# requests dropped, priority insufficient"},
90 { "fs", "# requests done for a price (normal load)"},
91 { "fs", "# requests dropped by datastore (queue length limit)"},
92 { "fs", "# P2P searches received"},
93 { "fs", "# P2P searches discarded (queue length bound)"},
94 { "fs", "# replies received for local clients"},
95 { "fs", "# queries retransmitted to same target"},
96 { "fs", "cummulative artificial delay introduced (ms)"},
97 { "core", "# bytes decrypted"},
98 { "core", "# bytes encrypted"},
99 { "transport", "# bytes received via TCP"},
100 { "transport", "# bytes transmitted via TCP"},
101 { "datacache", "# bytes stored"},
107 * Callback function to process statistic values.
110 * @param subsystem name of subsystem that created the statistic
111 * @param name the name of the datum
112 * @param value the current value
113 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
114 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
117 print_stat (void *cls,
118 const char *subsystem,
123 struct StatMaster *sm = cls;
125 "Peer %2u: %12s/%50s = %12llu\n",
129 (unsigned long long) value);
135 * Function that gathers stats from all daemons.
139 const struct GNUNET_SCHEDULER_TaskContext *tc);
143 * Function called when GET operation on stats is done.
149 struct StatMaster *sm = cls;
150 GNUNET_break (GNUNET_OK == success);
152 GNUNET_SCHEDULER_add_now (&stat_run, sm);
157 * Function that gathers stats from all daemons.
161 const struct GNUNET_SCHEDULER_TaskContext *tc)
163 struct StatMaster *sm = cls;
165 if (stats[sm->value].name != NULL)
167 GNUNET_STATISTICS_get (sm->stat,
171 stats[sm->value].subsystem,
172 stats[sm->value].name,
174 GNUNET_TIME_UNIT_FOREVER_REL,
179 GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO);
182 if (sm->daemon == NUM_DAEMONS)
185 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
188 sm->stat = GNUNET_STATISTICS_create ("<driver>",
189 GNUNET_FS_TEST_get_configuration (daemons,
191 GNUNET_SCHEDULER_add_now (&stat_run, sm);
196 do_report (void *cls,
197 const struct GNUNET_SCHEDULER_TaskContext *tc)
199 struct GNUNET_TIME_Relative del;
201 struct StatMaster *sm;
203 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
205 del = GNUNET_TIME_absolute_get_duration (start_time);
206 if (del.rel_value == 0)
208 fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long)FILESIZE) * 1000LL / del.rel_value);
210 "Download speed was %s/s\n",
213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
214 "Finished download, shutting down\n",
215 (unsigned long long) FILESIZE);
216 sm = GNUNET_malloc (sizeof (struct StatMaster));
217 sm->stat = GNUNET_STATISTICS_create ("<driver>",
218 GNUNET_FS_TEST_get_configuration (daemons,
220 GNUNET_SCHEDULER_add_now (&stat_run, sm);
224 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
225 "Timeout during download, shutting down with error\n");
227 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
233 do_download (void *cls,
234 const struct GNUNET_FS_Uri *uri)
240 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
242 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
243 "Timeout during upload attempt, shutting down with error\n");
247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
248 "Downloading %llu bytes\n",
249 (unsigned long long) FILESIZE);
250 start_time = GNUNET_TIME_absolute_get ();
251 if (NULL != strstr (progname, "dht"))
255 GNUNET_FS_TEST_download (daemons[0],
257 anonymity, SEED, uri,
264 do_publish (void *cls,
272 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
274 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
275 "Error trying to connect: %s\n",
280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
281 "Publishing %llu bytes\n",
282 (unsigned long long) FILESIZE);
283 if (NULL != strstr (progname, "index"))
284 do_index = GNUNET_YES;
286 do_index = GNUNET_NO;
287 if (NULL != strstr (progname, "dht"))
292 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS-1],
295 do_index, FILESIZE, SEED,
302 do_connect (void *cls,
303 const struct GNUNET_SCHEDULER_TaskContext *tc)
305 struct GNUNET_TESTING_PeerGroup *pg;
307 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
309 "Daemons started, will now try to connect them\n");
310 pg = GNUNET_FS_TEST_get_group (daemons);
311 GNUNET_break ( (NUM_DAEMONS - 1) * 2
312 == (GNUNET_TESTING_create_topology (pg,
313 GNUNET_TESTING_TOPOLOGY_LINE,
314 GNUNET_TESTING_TOPOLOGY_NONE,
316 GNUNET_TESTING_connect_topology (pg,
317 GNUNET_TESTING_TOPOLOGY_LINE,
318 GNUNET_TESTING_TOPOLOGY_OPTION_NONE,
329 const struct GNUNET_CONFIGURATION_Handle *cfg)
331 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf",
341 main (int argc, char *argv[])
343 char *const argvx[] = {
344 "perf-gnunet-service-fs-p2p",
346 "fs_test_lib_data.conf",
352 struct GNUNET_GETOPT_CommandLineOption options[] = {
353 GNUNET_GETOPT_OPTION_END
356 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
357 GNUNET_log_setup ("perf_gnunet_service_fs_p2p_index",
364 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
365 argvx, "perf-gnunet-service-fs-p2p-index",
366 "nohelp", options, &run, NULL);
367 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
371 /* end of perf_gnunet_service_fs_p2p_index.c */