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 * 10)
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;
55 do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
57 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
62 * Master context for 'stat_run'.
66 struct GNUNET_STATISTICS_Handle *stat;
73 const char *subsystem;
78 * Statistics we print out.
80 static struct StatValues stats[] = {
81 {"fs", "# artificial delays introduced (ms)"},
82 {"fs", "# queries forwarded"},
83 {"fs", "# replies received and matched"},
84 {"fs", "# results found locally"},
85 {"fs", "# requests forwarded due to high load"},
86 {"fs", "# requests done for free (low load)"},
87 {"fs", "# requests dropped, priority insufficient"},
88 {"fs", "# requests done for a price (normal load)"},
89 {"fs", "# requests dropped by datastore (queue length limit)"},
90 {"fs", "# P2P searches received"},
91 {"fs", "# P2P searches discarded (queue length bound)"},
92 {"fs", "# replies received for local clients"},
93 {"fs", "# queries retransmitted to same target"},
94 {"core", "# bytes decrypted"},
95 {"core", "# bytes encrypted"},
96 {"core", "# discarded CORE_SEND requests"},
97 {"core", "# discarded CORE_SEND request bytes"},
98 {"core", "# discarded lower priority CORE_SEND requests"},
99 {"core", "# discarded lower priority CORE_SEND request bytes"},
100 {"transport", "# bytes received via TCP"},
101 {"transport", "# bytes transmitted via TCP"},
102 {"datacache", "# bytes stored"},
108 * Callback function to process statistic values.
111 * @param subsystem name of subsystem that created the statistic
112 * @param name the name of the datum
113 * @param value the current value
114 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
115 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
118 print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
121 struct StatMaster *sm = cls;
123 FPRINTF (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem,
124 name, (unsigned long long) value);
130 * Function that gathers stats from all daemons.
133 stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
137 * Function called when GET operation on stats is done.
140 get_done (void *cls, int success)
142 struct StatMaster *sm = cls;
144 GNUNET_break (GNUNET_OK == success);
146 GNUNET_SCHEDULER_add_now (&stat_run, sm);
151 * Function that gathers stats from all daemons.
154 stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
156 struct StatMaster *sm = cls;
158 if (stats[sm->value].name != NULL)
160 GNUNET_STATISTICS_get (sm->stat,
164 stats[sm->value].subsystem, stats[sm->value].name,
166 GNUNET_TIME_UNIT_FOREVER_REL, &get_done, &print_stat,
170 GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO);
173 if (sm->daemon == NUM_DAEMONS)
176 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
180 GNUNET_STATISTICS_create ("<driver>",
181 GNUNET_FS_TEST_get_configuration (daemons,
183 GNUNET_SCHEDULER_add_now (&stat_run, sm);
188 do_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
190 struct GNUNET_TIME_Relative del;
192 struct StatMaster *sm;
194 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
196 del = GNUNET_TIME_absolute_get_duration (start_time);
197 if (del.rel_value == 0)
200 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
201 1000LL / del.rel_value);
202 FPRINTF (stdout, "Download speed was %s/s\n", fancy);
204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n",
205 (unsigned long long) FILESIZE);
206 sm = GNUNET_malloc (sizeof (struct StatMaster));
208 GNUNET_STATISTICS_create ("<driver>",
209 GNUNET_FS_TEST_get_configuration (daemons,
211 GNUNET_SCHEDULER_add_now (&stat_run, sm);
215 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
216 "Timeout during download, shutting down with error\n");
218 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
224 do_download (void *cls, const struct GNUNET_FS_Uri *uri)
230 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
232 "Timeout during upload attempt, shutting down with error\n");
236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
237 (unsigned long long) FILESIZE);
238 start_time = GNUNET_TIME_absolute_get ();
239 if (NULL != strstr (progname, "dht"))
243 GNUNET_FS_TEST_download (daemons[0], TIMEOUT, anonymity, SEED, uri, VERBOSE,
249 do_publish (void *cls, const char *emsg)
256 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
257 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg);
261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
262 (unsigned long long) FILESIZE);
263 if (NULL != strstr (progname, "index"))
264 do_index = GNUNET_YES;
266 do_index = GNUNET_NO;
267 if (NULL != strstr (progname, "dht"))
272 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity,
273 do_index, FILESIZE, SEED, VERBOSE, &do_download,
279 do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
281 struct GNUNET_TESTING_PeerGroup *pg;
283 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
285 "Daemons started, will now try to connect them\n");
286 pg = GNUNET_FS_TEST_get_group (daemons);
287 GNUNET_break ((NUM_DAEMONS - 1) * 2 ==
288 (GNUNET_TESTING_create_topology
289 (pg, GNUNET_TESTING_TOPOLOGY_LINE,
290 GNUNET_TESTING_TOPOLOGY_NONE, NULL)));
291 GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_LINE,
292 GNUNET_TESTING_TOPOLOGY_OPTION_NONE, 0.0,
293 TIMEOUT, NUM_DAEMONS, &do_publish, NULL);
298 run (void *cls, char *const *args, const char *cfgfile,
299 const struct GNUNET_CONFIGURATION_Handle *cfg)
301 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", TIMEOUT, NUM_DAEMONS,
302 daemons, &do_connect, NULL);
307 main (int argc, char *argv[])
309 char *const argvx[] = {
310 "perf-gnunet-service-fs-p2p",
312 "fs_test_lib_data.conf",
318 struct GNUNET_GETOPT_CommandLineOption options[] = {
319 GNUNET_GETOPT_OPTION_END
322 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
323 GNUNET_log_setup ("perf_gnunet_service_fs_p2p_index",
330 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
331 "perf-gnunet-service-fs-p2p-index", "nohelp", options,
333 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
337 /* end of perf_gnunet_service_fs_p2p.c */