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_YES
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, 300)
46 static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS];
48 static struct GNUNET_SCHEDULER_Handle *sched;
52 static struct GNUNET_TIME_Absolute start_time;
56 const struct GNUNET_SCHEDULER_TaskContext *tc)
58 GNUNET_FS_TEST_daemons_stop (sched,
65 * Master context for 'stat_run'.
69 struct GNUNET_STATISTICS_Handle *stat;
76 const char *subsystem;
81 * Statistics we print out.
83 static struct StatValues stats[] =
85 { "fs", "# queries forwarded"},
86 { "fs", "# replies received and matched"},
87 { "fs", "# results found locally"},
88 { "fs", "# requests forwarded due to high load"},
89 { "fs", "# requests done for free (low load)"},
90 { "fs", "# P2P searches received"},
91 { "fs", "# replies received for local clients"},
92 { "fs", "# P2P searches discarded (queue length bound)"},
93 { "fs", "# requests dropped due to high load"},
94 { "fs", "# requests dropped by datastore (queue length limit)"},
95 { "fs", "# queries retransmitted to same target"},
96 { "fs", "cummulative artificial delay introduced (ms)"},
97 { "core", "# bytes decrypted"},
98 { "core", "# bytes encrypted"},
99 { "core", "# transmissions delayed due to corking"},
100 { "transport", "# bytes received via TCP"},
101 { "transport", "# bytes transmitted via TCP"},
102 { "datacache", "# bytes stored"},
103 { "dht", "# DHT ROUTE Requests Seen"},
104 { "dht", "# DHT ROUTE Requests Forwarded"},
110 * Callback function to process statistic values.
113 * @param subsystem name of subsystem that created the statistic
114 * @param name the name of the datum
115 * @param value the current value
116 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
117 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
120 print_stat (void *cls,
121 const char *subsystem,
126 struct StatMaster *sm = cls;
128 "Peer %2u: %12s/%50s = %12llu\n",
132 (unsigned long long) value);
138 * Function that gathers stats from all daemons.
142 const struct GNUNET_SCHEDULER_TaskContext *tc);
146 * Function called when GET operation on stats is done.
152 struct StatMaster *sm = cls;
153 GNUNET_break (GNUNET_OK == success);
155 GNUNET_SCHEDULER_add_now (sched, &stat_run, sm);
160 * Function that gathers stats from all daemons.
164 const struct GNUNET_SCHEDULER_TaskContext *tc)
166 struct StatMaster *sm = cls;
168 if (stats[sm->value].name != NULL)
170 GNUNET_STATISTICS_get (sm->stat,
174 stats[sm->value].subsystem,
175 stats[sm->value].name,
177 GNUNET_TIME_UNIT_FOREVER_REL,
182 GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO);
185 if (sm->daemon == NUM_DAEMONS)
188 GNUNET_SCHEDULER_add_now (sched, &do_stop, NULL);
191 sm->stat = GNUNET_STATISTICS_create (sched, "<driver>",
192 GNUNET_FS_TEST_get_configuration (daemons,
194 GNUNET_SCHEDULER_add_now (sched, &stat_run, sm);
199 do_report (void *cls,
200 const struct GNUNET_SCHEDULER_TaskContext *tc)
202 struct GNUNET_TIME_Relative del;
204 struct StatMaster *sm;
206 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
208 del = GNUNET_TIME_absolute_get_duration (start_time);
211 fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long)FILESIZE) * 1000LL / del.value);
213 "Download speed was %s/s\n",
216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
217 "Finished download, shutting down\n",
218 (unsigned long long) FILESIZE);
219 sm = GNUNET_malloc (sizeof (struct StatMaster));
220 sm->stat = GNUNET_STATISTICS_create (sched, "<driver>",
221 GNUNET_FS_TEST_get_configuration (daemons,
223 GNUNET_SCHEDULER_add_now (sched, &stat_run, sm);
227 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
228 "Timeout during download, shutting down with error\n");
230 GNUNET_SCHEDULER_add_now (sched, &do_stop, NULL);
236 do_download (void *cls,
237 const struct GNUNET_FS_Uri *uri)
241 GNUNET_FS_TEST_daemons_stop (sched,
244 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
245 "Timeout during upload attempt, shutting down with error\n");
249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
250 "Downloading %llu bytes\n",
251 (unsigned long long) FILESIZE);
252 start_time = GNUNET_TIME_absolute_get ();
253 GNUNET_FS_TEST_download (sched,
263 do_publish (void *cls,
268 GNUNET_FS_TEST_daemons_stop (sched,
271 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
272 "Error trying to connect: %s\n",
277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
278 "Publishing %llu bytes\n",
279 (unsigned long long) FILESIZE);
280 GNUNET_FS_TEST_publish (sched,
281 daemons[NUM_DAEMONS-1],
283 1, GNUNET_NO, FILESIZE, SEED,
290 do_connect (void *cls,
291 const struct GNUNET_SCHEDULER_TaskContext *tc)
293 struct GNUNET_TESTING_PeerGroup *pg;
295 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
297 "Daemons started, will now try to connect them\n");
298 pg = GNUNET_FS_TEST_get_group (daemons);
299 GNUNET_break ( (NUM_DAEMONS - 1) * 2
300 == (GNUNET_TESTING_create_topology (pg,
301 GNUNET_TESTING_TOPOLOGY_LINE,
302 GNUNET_TESTING_TOPOLOGY_NONE,
304 GNUNET_TESTING_connect_topology (pg,
305 GNUNET_TESTING_TOPOLOGY_LINE,
306 GNUNET_TESTING_TOPOLOGY_OPTION_NONE,
315 struct GNUNET_SCHEDULER_Handle *s,
318 const struct GNUNET_CONFIGURATION_Handle *cfg)
321 GNUNET_FS_TEST_daemons_start (sched,
322 "fs_test_lib_data.conf",
332 main (int argc, char *argv[])
334 char *const argvx[] = {
335 "perf-gnunet-service-fs-p2p",
337 "fs_test_lib_data.conf",
343 struct GNUNET_GETOPT_CommandLineOption options[] = {
344 GNUNET_GETOPT_OPTION_END
347 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
348 GNUNET_log_setup ("perf_gnunet_service_fs_p2p",
355 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
356 argvx, "perf-gnunet-service-fs-p2p",
357 "nohelp", options, &run, NULL);
358 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
362 /* end of perf_gnunet_service_fs_p2p.c */