2 This file is part of GNUnet.
3 (C) 2011, 2012 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 stream/perf_stream_api.c
23 * @brief performance benchmarks for stream api
24 * @author Sree Harsha Totakura
27 /****************************************************************************************/
28 /* Test is setup into the following major steps: */
29 /* 1. Measurements over loopback (1 hop). i.e. we use only one peer and open */
30 /* stream connections over loopback. Messages will go through */
31 /* STREAM_API->MESH_API->MESH_SERVICE->MESH_API->STREAM_API. */
32 /* 2. Measurements over 2 peers (2 hops). We use testbed to create 2 peers, */
33 /* connect them and then create stream connections. Messages will go through */
34 /* STREAM_API->MESH_API->MESH_SERVICE->CORE1.....CORE2->MESH_API->STREAM_API */
35 /* 3. Measurements over 3 peers (3 hops). We use testbed to create 3 peers, */
36 /* connect them in a line topology: peer1->peer2->peer3. Messages will go */
38 /* STREAM_API->MESH_API->MESH_SERVICE->CORE1..CORE2..CORE3->MESH_API->STREAM_API. */
39 /****************************************************************************************/
42 #include "gnunet_common.h"
43 #include "gnunet_util_lib.h"
44 #include "gnunet_testbed_service.h"
48 * Simple struct to keep track of progress, and print a
49 * nice little percentage meter for long running tasks.
59 unsigned int completed;
73 * Single hop loopback testing
78 * Testing with 2 peers
83 * Testing with 3 peers
89 * Maximum size of the data which we will transfer during tests
91 #define DATA_SIZE 65536 /* 64KB */
94 * Random data block. Should generate data first
96 static uint32_t data[DATA_SIZE / 4]; /* 64KB array */
99 * Payload sizes to test each major test with
101 static uint16_t payload_size[] =
102 { 20, 500, 2000, 7000, 13000, 25000, 56000, 64000 };
105 * Handle for the progress meter
107 static struct ProgressMeter *meter;
110 * Current step of testing
112 static enum TestStep test_step;
115 * Index for choosing payload size
117 unsigned int payload_size_index;
120 * Create a meter to keep track of the progress of some task.
122 * @param total the total number of items to complete
123 * @param start_string a string to prefix the meter with (if printing)
124 * @param print GNUNET_YES to print the meter, GNUNET_NO to count
127 * @return the progress meter
129 static struct ProgressMeter *
130 create_meter (unsigned int total, char *start_string, int print)
132 struct ProgressMeter *ret;
134 ret = GNUNET_malloc (sizeof (struct ProgressMeter));
137 ret->modnum = total / 4;
138 if (ret->modnum == 0) /* Divide by zero check */
140 ret->dotnum = (total / 50) + 1;
141 if (start_string != NULL)
142 ret->startup_string = GNUNET_strdup (start_string);
144 ret->startup_string = GNUNET_strdup ("");
151 * Update progress meter (increment by one).
153 * @param meter the meter to update and print info for
155 * @return GNUNET_YES if called the total requested,
156 * GNUNET_NO if more items expected
159 update_meter (struct ProgressMeter *meter)
161 if (meter->print == GNUNET_YES)
163 if (meter->completed % meter->modnum == 0)
165 if (meter->completed == 0)
167 FPRINTF (stdout, "%sProgress: [0%%", meter->startup_string);
170 FPRINTF (stdout, "%d%%",
171 (int) (((float) meter->completed / meter->total) * 100));
173 else if (meter->completed % meter->dotnum == 0)
174 FPRINTF (stdout, "%s", ".");
176 if (meter->completed + 1 == meter->total)
177 FPRINTF (stdout, "%d%%]\n", 100);
182 if (meter->completed == meter->total)
184 if (meter->completed > meter->total)
185 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Progress meter overflow!!\n");
191 * Reset progress meter.
193 * @param meter the meter to reset
195 * @return GNUNET_YES if meter reset,
196 * GNUNET_SYSERR on error
199 reset_meter (struct ProgressMeter *meter)
202 return GNUNET_SYSERR;
204 meter->completed = 0;
210 * Release resources for meter
212 * @param meter the meter to free
215 free_meter (struct ProgressMeter *meter)
217 GNUNET_free_non_null (meter->startup_string);
223 * Initialize framework and start test
226 * @param cfg configuration of the peer that was started
227 * @param peer identity of the peer that was created
231 const struct GNUNET_CONFIGURATION_Handle *cfg,
232 struct GNUNET_TESTING_Peer *peer)
241 int main (int argc, char **argv)
246 meter = create_meter ((sizeof (data) / 4), "Generating random data\n", GNUNET_YES);
247 for (count=0; count < (sizeof (data) / 4); count++)
249 data[count] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
251 update_meter (meter);
255 test_step = TEST_STEP_1_HOP;
256 for (payload_size_index = 0;
257 payload_size_index < (sizeof (payload_size) / sizeof (uint16_t));
258 payload_size_index++)
260 ret = GNUNET_TESTING_peer_run ("test_stream_big", "test_stream_local.conf",
265 test_step = TEST_STEP_2_HOP;
266 for (payload_size_index = 0;
267 payload_size_index < (sizeof (payload_size) / sizeof (uint16_t));
268 payload_size_index++)
270 /* Initialize testbed here */
272 test_step = TEST_STEP_3_HOP;
273 for (payload_size_index = 0;
274 payload_size_index < (sizeof (payload_size) / sizeof (uint16_t));
275 payload_size_index++)
277 /* Initialize testbed here */