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 { "core", "# discarded CORE_SEND requests"},
100 { "core", "# discarded CORE_SEND request bytes"},
101 { "core", "# discarded lower priority CORE_SEND requests"},
102 { "core", "# discarded lower priority CORE_SEND request bytes"},
103 { "transport", "# bytes received via TCP"},
104 { "transport", "# bytes transmitted via TCP"},
105 { "datacache", "# bytes stored"},
111 * Callback function to process statistic values.
114 * @param subsystem name of subsystem that created the statistic
115 * @param name the name of the datum
116 * @param value the current value
117 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
118 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
121 print_stat (void *cls,
122 const char *subsystem,
127 struct StatMaster *sm = cls;
129 "Peer %2u: %12s/%50s = %12llu\n",
133 (unsigned long long) value);
139 * Function that gathers stats from all daemons.
143 const struct GNUNET_SCHEDULER_TaskContext *tc);
147 * Function called when GET operation on stats is done.
153 struct StatMaster *sm = cls;
154 GNUNET_break (GNUNET_OK == success);
156 GNUNET_SCHEDULER_add_now (&stat_run, sm);
161 * Function that gathers stats from all daemons.
165 const struct GNUNET_SCHEDULER_TaskContext *tc)
167 struct StatMaster *sm = cls;
169 if (stats[sm->value].name != NULL)
171 GNUNET_STATISTICS_get (sm->stat,
175 stats[sm->value].subsystem,
176 stats[sm->value].name,
178 GNUNET_TIME_UNIT_FOREVER_REL,
183 GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO);
186 if (sm->daemon == NUM_DAEMONS)
189 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
192 sm->stat = GNUNET_STATISTICS_create ("<driver>",
193 GNUNET_FS_TEST_get_configuration (daemons,
195 GNUNET_SCHEDULER_add_now (&stat_run, sm);
200 do_report (void *cls,
201 const struct GNUNET_SCHEDULER_TaskContext *tc)
203 struct GNUNET_TIME_Relative del;
205 struct StatMaster *sm;
207 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
209 del = GNUNET_TIME_absolute_get_duration (start_time);
210 if (del.rel_value == 0)
212 fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long)FILESIZE) * 1000LL / del.rel_value);
214 "Download speed was %s/s\n",
217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
218 "Finished download, shutting down\n",
219 (unsigned long long) FILESIZE);
220 sm = GNUNET_malloc (sizeof (struct StatMaster));
221 sm->stat = GNUNET_STATISTICS_create ("<driver>",
222 GNUNET_FS_TEST_get_configuration (daemons,
224 GNUNET_SCHEDULER_add_now (&stat_run, sm);
228 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
229 "Timeout during download, shutting down with error\n");
231 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
237 do_download (void *cls,
238 const struct GNUNET_FS_Uri *uri)
244 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
246 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
247 "Timeout during upload attempt, shutting down with error\n");
251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
252 "Downloading %llu bytes\n",
253 (unsigned long long) FILESIZE);
254 start_time = GNUNET_TIME_absolute_get ();
255 if (NULL != strstr (progname, "dht"))
259 GNUNET_FS_TEST_download (daemons[0],
261 anonymity, SEED, uri,
268 do_publish (void *cls,
276 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
278 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
279 "Error trying to connect: %s\n",
284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
285 "Publishing %llu bytes\n",
286 (unsigned long long) FILESIZE);
287 if (NULL != strstr (progname, "index"))
288 do_index = GNUNET_YES;
290 do_index = GNUNET_NO;
291 if (NULL != strstr (progname, "dht"))
296 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS-1],
299 do_index, FILESIZE, SEED,
306 do_connect (void *cls,
307 const struct GNUNET_SCHEDULER_TaskContext *tc)
309 struct GNUNET_TESTING_PeerGroup *pg;
311 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
313 "Daemons started, will now try to connect them\n");
314 pg = GNUNET_FS_TEST_get_group (daemons);
315 GNUNET_break ( (NUM_DAEMONS - 1) * 2
316 == (GNUNET_TESTING_create_topology (pg,
317 GNUNET_TESTING_TOPOLOGY_LINE,
318 GNUNET_TESTING_TOPOLOGY_NONE,
320 GNUNET_TESTING_connect_topology (pg,
321 GNUNET_TESTING_TOPOLOGY_LINE,
322 GNUNET_TESTING_TOPOLOGY_OPTION_NONE,
333 const struct GNUNET_CONFIGURATION_Handle *cfg)
335 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf",
345 main (int argc, char *argv[])
347 char *const argvx[] = {
348 "perf-gnunet-service-fs-p2p",
350 "fs_test_lib_data.conf",
356 struct GNUNET_GETOPT_CommandLineOption options[] = {
357 GNUNET_GETOPT_OPTION_END
360 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
361 GNUNET_log_setup ("perf_gnunet_service_fs_p2p_index",
368 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
369 argvx, "perf-gnunet-service-fs-p2p-index",
370 "nohelp", options, &run, NULL);
371 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
375 /* end of perf_gnunet_service_fs_p2p_index.c */