diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-04-19 16:47:01 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-04-19 16:47:01 +0000 |
commit | 88466b920cfad65d6bf41802b262b86ae76f5791 (patch) | |
tree | dce12e1249ba26e74cece7e34c35b0118cc7b3a8 /src/ats | |
parent | 99c66999a525b2783982ffa7590c988529184482 (diff) | |
download | gnunet-88466b920cfad65d6bf41802b262b86ae76f5791.tar.gz gnunet-88466b920cfad65d6bf41802b262b86ae76f5791.zip |
- added benchmarking for updates
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/perf_ats_mlp.c | 149 |
1 files changed, 131 insertions, 18 deletions
diff --git a/src/ats/perf_ats_mlp.c b/src/ats/perf_ats_mlp.c index ec7234fcc..f5be6bac1 100644 --- a/src/ats/perf_ats_mlp.c +++ b/src/ats/perf_ats_mlp.c | |||
@@ -37,11 +37,14 @@ | |||
37 | 37 | ||
38 | #define DEF_PEERS 10 | 38 | #define DEF_PEERS 10 |
39 | #define DEF_ADDRESSES_PER_PEER 5 | 39 | #define DEF_ADDRESSES_PER_PEER 5 |
40 | #define DEF_ATS_VALUES 2 | ||
41 | #define DEF_ATS_MAX_DELAY 30 | ||
42 | #define DEF_ATS_MAX_DISTANCE 3 | ||
40 | 43 | ||
41 | static unsigned int peers; | 44 | static unsigned int peers; |
42 | static unsigned int addresses; | 45 | static unsigned int addresses; |
43 | static unsigned int numeric; | 46 | static unsigned int numeric; |
44 | static unsigned int updates; | 47 | static unsigned int update_percentage; |
45 | 48 | ||
46 | static int start; | 49 | static int start; |
47 | static int end; | 50 | static int end; |
@@ -111,6 +114,63 @@ do_shutdown (void *cls, | |||
111 | 114 | ||
112 | } | 115 | } |
113 | 116 | ||
117 | static void | ||
118 | update_addresses (struct ATS_Address * a, unsigned int addrs, unsigned int percentage) | ||
119 | { | ||
120 | if (percentage == 0) | ||
121 | return; | ||
122 | |||
123 | unsigned int ua = (addrs) * ((float) percentage / 100); | ||
124 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Updating %u of %u addresses per peer\n", ua, addrs); | ||
125 | |||
126 | unsigned int updated[addrs]; | ||
127 | unsigned int u_types[DEF_ATS_VALUES]; | ||
128 | unsigned int updates = 0; | ||
129 | unsigned int u_type = 0; | ||
130 | unsigned int u_val = 0; | ||
131 | unsigned int cur = 0; | ||
132 | |||
133 | u_types[0] = 0; | ||
134 | u_types[1] = 0; | ||
135 | |||
136 | while (updates < ua) | ||
137 | { | ||
138 | cur = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, addrs); | ||
139 | if (0 == updated[cur]) | ||
140 | { | ||
141 | u_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DEF_ATS_VALUES); | ||
142 | switch (u_type) { | ||
143 | case 0: | ||
144 | do | ||
145 | { | ||
146 | u_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DEF_ATS_MAX_DELAY); | ||
147 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating DELAY from %u to %u\n",a[cur].ats[u_type].value, u_val); | ||
148 | } | ||
149 | while (a[cur].ats[u_type].value == u_val); | ||
150 | break; | ||
151 | case 1: | ||
152 | do | ||
153 | { | ||
154 | u_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DEF_ATS_MAX_DISTANCE); | ||
155 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating DISTANCE from %u to %u\n",a[cur].ats[u_type].value, u_val); | ||
156 | } | ||
157 | while (a[cur].ats[u_type].value == u_val); | ||
158 | break; | ||
159 | default: | ||
160 | GNUNET_break (0); | ||
161 | break; | ||
162 | } | ||
163 | u_types[u_type]++; | ||
164 | |||
165 | a[cur].ats[u_type].value = u_val; | ||
166 | updated[cur] = 1; | ||
167 | updates++; | ||
168 | } | ||
169 | } | ||
170 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Updated %u delay and %u distance values\n", u_types[0], u_types[1]); | ||
171 | |||
172 | } | ||
173 | |||
114 | 174 | ||
115 | static void | 175 | static void |
116 | check (void *cls, char *const *args, const char *cfgfile, | 176 | check (void *cls, char *const *args, const char *cfgfile, |
@@ -119,6 +179,9 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
119 | unsigned int c = 0; | 179 | unsigned int c = 0; |
120 | unsigned int c2 = 0; | 180 | unsigned int c2 = 0; |
121 | unsigned int ca = 0; | 181 | unsigned int ca = 0; |
182 | int update = GNUNET_NO; | ||
183 | int range = GNUNET_NO; | ||
184 | int res; | ||
122 | 185 | ||
123 | #if !HAVE_LIBGLPK | 186 | #if !HAVE_LIBGLPK |
124 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!"); | 187 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!"); |
@@ -154,9 +217,25 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
154 | if (end == 0) | 217 | if (end == 0) |
155 | end = -1; | 218 | end = -1; |
156 | if ((start != -1) && (end != -1)) | 219 | if ((start != -1) && (end != -1)) |
220 | { | ||
157 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Solving problem starting from %u to %u\n", start , end); | 221 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Solving problem starting from %u to %u\n", start , end); |
222 | range = GNUNET_YES; | ||
223 | } | ||
158 | else | 224 | else |
159 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Solving problem for %u peers\n", peers); | 225 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Solving problem for %u peers\n", peers); |
226 | |||
227 | if ((update_percentage >= 0) && (update_percentage <= 100)) | ||
228 | { | ||
229 | update = GNUNET_YES; | ||
230 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Benchmarking with existing presolution and %u \% updated addresses\n", update_percentage); | ||
231 | } | ||
232 | else if ((update_percentage > 100) && (update_percentage != UINT_MAX)) | ||
233 | { | ||
234 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Invalid percentage: %u\n", update_percentage); | ||
235 | ret = 1; | ||
236 | return; | ||
237 | } | ||
238 | |||
160 | for (c=0; c < peers; c++) | 239 | for (c=0; c < peers; c++) |
161 | { | 240 | { |
162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up peer %u\n", c); | 241 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up peer %u\n", c); |
@@ -175,11 +254,11 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
175 | a[ca].plugin = strdup("test"); | 254 | a[ca].plugin = strdup("test"); |
176 | a[ca].atsp_network_type = GNUNET_ATS_NET_LOOPBACK; | 255 | a[ca].atsp_network_type = GNUNET_ATS_NET_LOOPBACK; |
177 | 256 | ||
178 | a[ca].ats = GNUNET_malloc (2 * sizeof (struct GNUNET_ATS_Information)); | 257 | a[ca].ats = GNUNET_malloc (DEF_ATS_VALUES * sizeof (struct GNUNET_ATS_Information)); |
179 | a[ca].ats[0].type = GNUNET_ATS_QUALITY_NET_DELAY; | 258 | a[ca].ats[0].type = GNUNET_ATS_QUALITY_NET_DELAY; |
180 | a[ca].ats[0].value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 10); | 259 | a[ca].ats[0].value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, DEF_ATS_MAX_DELAY); |
181 | a[ca].ats[1].type = GNUNET_ATS_QUALITY_NET_DISTANCE; | 260 | a[ca].ats[1].type = GNUNET_ATS_QUALITY_NET_DISTANCE; |
182 | a[ca].ats[1].value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2); | 261 | a[ca].ats[1].value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, DEF_ATS_MAX_DISTANCE); |
183 | a[ca].ats_count = 2; | 262 | a[ca].ats_count = 2; |
184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up address %u\n", ca); | 263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up address %u\n", ca); |
185 | GNUNET_CONTAINER_multihashmap_put (amap, &a[ca].peer.hashPubKey, &a[ca], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 264 | GNUNET_CONTAINER_multihashmap_put (amap, &a[ca].peer.hashPubKey, &a[ca], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
@@ -189,7 +268,7 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
189 | 268 | ||
190 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Problem contains %u peers and %u adresses\n", mlp->c_p, mlp->addr_in_problem); | 269 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Problem contains %u peers and %u adresses\n", mlp->c_p, mlp->addr_in_problem); |
191 | 270 | ||
192 | if ((((start >= 0) && ((c+1) >= start)) && (c <= end)) || ((c+1) == peers)) | 271 | if (((GNUNET_YES == range) && (((start >= 0) && ((c+1) >= start)) && (c <= end))) || ((c+1) == peers)) |
193 | { | 272 | { |
194 | GNUNET_assert ((c+1) == mlp->c_p); | 273 | GNUNET_assert ((c+1) == mlp->c_p); |
195 | GNUNET_assert ((c+1) * addresses == mlp->addr_in_problem); | 274 | GNUNET_assert ((c+1) * addresses == mlp->addr_in_problem); |
@@ -197,19 +276,49 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
197 | /* Solving the problem */ | 276 | /* Solving the problem */ |
198 | struct GAS_MLP_SolutionContext ctx; | 277 | struct GAS_MLP_SolutionContext ctx; |
199 | 278 | ||
200 | if (GNUNET_OK == GAS_mlp_solve_problem(mlp, &ctx)) | 279 | res = GAS_mlp_solve_problem(mlp, &ctx); |
280 | |||
281 | if (GNUNET_NO == update) | ||
201 | { | 282 | { |
202 | GNUNET_assert (GNUNET_OK == ctx.lp_result); | 283 | if (GNUNET_OK == res) |
203 | GNUNET_assert (GNUNET_OK == ctx.mlp_result); | 284 | { |
204 | if (GNUNET_YES == numeric) | 285 | GNUNET_assert (GNUNET_OK == ctx.lp_result); |
205 | printf ("%u;%u;%llu;%llu\n",mlp->c_p, mlp->addr_in_problem, (long long unsigned int) ctx.lp_duration.rel_value, (long long unsigned int) ctx.mlp_duration.rel_value); | 286 | GNUNET_assert (GNUNET_OK == ctx.mlp_result); |
287 | if (GNUNET_YES == numeric) | ||
288 | printf ("%u;%u;%llu;%llu\n",mlp->c_p, mlp->addr_in_problem, (long long unsigned int) ctx.lp_duration.rel_value, (long long unsigned int) ctx.mlp_duration.rel_value); | ||
289 | else | ||
290 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Problem solved for %u peers with %u address successfully (LP: %llu ms / MLP: %llu ms)\n", | ||
291 | mlp->c_p, mlp->addr_in_problem, ctx.lp_duration.rel_value, ctx.mlp_duration.rel_value); | ||
292 | } | ||
206 | else | 293 | else |
207 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Problem solved for %u peers with %u address successfully (LP: %llu ms / MLP: %llu ms)\n", | 294 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Solving problem with %u peers and %u addresses failed\n", c, c2); |
208 | mlp->c_p, mlp->addr_in_problem, ctx.lp_duration.rel_value, ctx.mlp_duration.rel_value); | ||
209 | |||
210 | } | 295 | } |
211 | else | 296 | else |
212 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Solving problem with %u peers and %u addresses failed\n", peers, addresses); | 297 | { |
298 | struct GAS_MLP_SolutionContext uctx; | ||
299 | /* Update addresses */ | ||
300 | update_addresses (a, (c+1) * c2, update_percentage); | ||
301 | |||
302 | /* Solve again */ | ||
303 | res = GAS_mlp_solve_problem(mlp, &uctx); | ||
304 | |||
305 | if (GNUNET_OK == res) | ||
306 | { | ||
307 | GNUNET_assert (GNUNET_OK == uctx.lp_result); | ||
308 | GNUNET_assert (GNUNET_OK == uctx.mlp_result); | ||
309 | if (GNUNET_YES == numeric) | ||
310 | printf ("%u;%u;%llu;%llu;%llu;%llu\n",mlp->c_p, mlp->addr_in_problem, | ||
311 | (long long unsigned int) ctx.lp_duration.rel_value, (long long unsigned int) ctx.mlp_duration.rel_value, | ||
312 | (long long unsigned int) uctx.lp_duration.rel_value, (long long unsigned int) uctx.mlp_duration.rel_value); | ||
313 | else | ||
314 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Updated Problem solved for %u peers with %u address successfully (Initial: LP/MLP: %llu/%llu ms, Update: %llu/%llu ms)\n", | ||
315 | mlp->c_p, mlp->addr_in_problem, | ||
316 | (long long unsigned int) ctx.lp_duration.rel_value, (long long unsigned int) ctx.mlp_duration.rel_value, | ||
317 | (long long unsigned int) uctx.lp_duration.rel_value, (long long unsigned int) uctx.mlp_duration.rel_value); | ||
318 | } | ||
319 | else | ||
320 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Solving updated problem with %u peers and %u addresses failed\n", c, c2); | ||
321 | } | ||
213 | } | 322 | } |
214 | } | 323 | } |
215 | 324 | ||
@@ -223,7 +332,8 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
223 | int | 332 | int |
224 | main (int argc, char *argv[]) | 333 | main (int argc, char *argv[]) |
225 | { | 334 | { |
226 | 335 | /* Init invalid */ | |
336 | update_percentage = UINT_MAX; | ||
227 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 337 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
228 | {'a', "addresses", NULL, | 338 | {'a', "addresses", NULL, |
229 | gettext_noop ("addresses per peer"), 1, | 339 | gettext_noop ("addresses per peer"), 1, |
@@ -237,9 +347,12 @@ main (int argc, char *argv[]) | |||
237 | {'e', "end", NULL, | 347 | {'e', "end", NULL, |
238 | gettext_noop ("end solving problem"), 1, | 348 | gettext_noop ("end solving problem"), 1, |
239 | &GNUNET_GETOPT_set_uint, &end}, | 349 | &GNUNET_GETOPT_set_uint, &end}, |
240 | {'s', "start", NULL, | 350 | {'s', "start", NULL, |
241 | gettext_noop ("start solving problem"), 1, | 351 | gettext_noop ("start solving problem"), 1, |
242 | &GNUNET_GETOPT_set_uint, &start}, | 352 | &GNUNET_GETOPT_set_uint, &start}, |
353 | {'u', "update", NULL, | ||
354 | gettext_noop ("benchmark with existing solution (address updates)"), 1, | ||
355 | &GNUNET_GETOPT_set_uint, &update_percentage}, | ||
243 | GNUNET_GETOPT_OPTION_END | 356 | GNUNET_GETOPT_OPTION_END |
244 | }; | 357 | }; |
245 | 358 | ||