aboutsummaryrefslogtreecommitdiff
path: root/src/ats/perf_ats_solver.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-05-12 16:47:50 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-05-12 16:47:50 +0000
commitac2be7dde06b71347d87ed491eb38d64a9163ad8 (patch)
treeeb96137d65b0305ad3ab008292466f068c3632d5 /src/ats/perf_ats_solver.c
parent6f1bbf8034e41837c33c5e3a7270c603a02e9d2e (diff)
downloadgnunet-ac2be7dde06b71347d87ed491eb38d64a9163ad8.tar.gz
gnunet-ac2be7dde06b71347d87ed491eb38d64a9163ad8.zip
fixes for the solver and perf tool
Diffstat (limited to 'src/ats/perf_ats_solver.c')
-rw-r--r--src/ats/perf_ats_solver.c218
1 files changed, 54 insertions, 164 deletions
diff --git a/src/ats/perf_ats_solver.c b/src/ats/perf_ats_solver.c
index 066a7d4ec..197414a6d 100644
--- a/src/ats/perf_ats_solver.c
+++ b/src/ats/perf_ats_solver.c
@@ -370,29 +370,36 @@ static void
370perf_update_address (struct ATS_Address *cur) 370perf_update_address (struct ATS_Address *cur)
371{ 371{
372 int r_type; 372 int r_type;
373 int r_val; 373 int abs_val;
374 double rel_val;
374 375
375 r_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2); 376 r_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2);
376 switch (r_type) 377 switch (r_type)
377 { 378 {
378 case 0: 379 case 0:
379 r_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); 380 abs_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
380 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 381 rel_val = (100 + (double) abs_val) / 100;
381 "Updating peer `%s' address %p type %s val %u\n", 382
382 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DELAY", r_val); 383 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
384 "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n",
385 GNUNET_i2s (&cur->peer), cur,
386 "GNUNET_ATS_QUALITY_NET_DELAY",
387 abs_val, rel_val);
383 ph.env.sf.s_address_update_property (ph.solver, cur, 388 ph.env.sf.s_address_update_property (ph.solver, cur,
384 GNUNET_ATS_QUALITY_NET_DELAY, 389 GNUNET_ATS_QUALITY_NET_DELAY,
385 r_val, (double) (100 + r_val / 100)); 390 abs_val, rel_val);
386 break; 391 break;
387 case 1: 392 case 1:
388 r_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10); 393 abs_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10);
394 rel_val = (100 + (double) abs_val) / 100;
389 395
390 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 396 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
391 "Updating peer `%s' address %p type %s val %u\n", 397 "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n",
392 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE", r_val); 398 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE",
399 abs_val, rel_val);
393 ph.env.sf.s_address_update_property (ph.solver, cur, 400 ph.env.sf.s_address_update_property (ph.solver, cur,
394 GNUNET_ATS_QUALITY_NET_DISTANCE, 401 GNUNET_ATS_QUALITY_NET_DISTANCE,
395 r_val, (double) (100 + r_val) / 100); 402 abs_val, rel_val);
396 break; 403 break;
397 default: 404 default:
398 break; 405 break;
@@ -446,15 +453,21 @@ perf_address_initial_update (void *solver,
446 struct GNUNET_CONTAINER_MultiPeerMap * addresses, 453 struct GNUNET_CONTAINER_MultiPeerMap * addresses,
447 struct ATS_Address *address) 454 struct ATS_Address *address)
448{ 455{
456 double delay;
457 double distance;
458 uint32_t random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
459 delay = (100 + (double) random) / 100;
449 ph.env.sf.s_address_update_property (solver, address, GNUNET_ATS_QUALITY_NET_DELAY, 460 ph.env.sf.s_address_update_property (solver, address, GNUNET_ATS_QUALITY_NET_DELAY,
450 100, 461 100, delay);
451 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100)) 462
452 / 100); 463 random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
464 distance = (100 + (double) random) / 100;
453 465
454 ph.env.sf.s_address_update_property (solver, address, 466 ph.env.sf.s_address_update_property (solver, address,
455 GNUNET_ATS_QUALITY_NET_DISTANCE, 10, 467 GNUNET_ATS_QUALITY_NET_DISTANCE, 10, distance);
456 (double) (100 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100)) 468
457 / 100); 469 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
470 "Initial update address %p : %.2f %.2f\n", address, delay, distance);
458} 471}
459 472
460/** 473/**
@@ -904,7 +917,7 @@ evaluate (int iteration)
904 cur_res->d_total.rel_value_us = 0; 917 cur_res->d_total.rel_value_us = 0;
905 if (GNUNET_YES == cur->valid) 918 if (GNUNET_YES == cur->valid)
906 cur_res->d_total.rel_value_us += cur->d_total.rel_value_us; 919 cur_res->d_total.rel_value_us += cur->d_total.rel_value_us;
907 fprintf (stderr, 920 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
908 "Total time to solve %s for %u peers %u addresses: %llu us\n", 921 "Total time to solve %s for %u peers %u addresses: %llu us\n",
909 (GNUNET_YES == cur->update) ? "updated" : "full", 922 (GNUNET_YES == cur->update) ? "updated" : "full",
910 cur->peers, cur->addresses, 923 cur->peers, cur->addresses,
@@ -920,7 +933,8 @@ evaluate (int iteration)
920 cur_res->d_setup.rel_value_us = 0; 933 cur_res->d_setup.rel_value_us = 0;
921 if (GNUNET_YES == cur->valid) 934 if (GNUNET_YES == cur->valid)
922 cur_res->d_setup.rel_value_us += cur->d_setup.rel_value_us; 935 cur_res->d_setup.rel_value_us += cur->d_setup.rel_value_us;
923 fprintf (stderr, "Total time to setup %s %u peers %u addresses: %llu us\n", 936 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
937 "Total time to setup %s %u peers %u addresses: %llu us\n",
924 (GNUNET_YES == cur->update) ? "updated" : "full", 938 (GNUNET_YES == cur->update) ? "updated" : "full",
925 cur->peers, cur->addresses, 939 cur->peers, cur->addresses,
926 (unsigned long long) cur->d_setup.rel_value_us); 940 (unsigned long long) cur->d_setup.rel_value_us);
@@ -936,7 +950,7 @@ evaluate (int iteration)
936 cur_res->d_lp.rel_value_us = 0; 950 cur_res->d_lp.rel_value_us = 0;
937 if (GNUNET_YES == cur->valid) 951 if (GNUNET_YES == cur->valid)
938 cur_res->d_lp.rel_value_us += cur->d_lp.rel_value_us; 952 cur_res->d_lp.rel_value_us += cur->d_lp.rel_value_us;
939 fprintf (stderr, 953 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
940 "Total time to solve %s LP for %u peers %u addresses: %llu us\n", 954 "Total time to solve %s LP for %u peers %u addresses: %llu us\n",
941 (GNUNET_YES == cur->update) ? "updated" : "full", 955 (GNUNET_YES == cur->update) ? "updated" : "full",
942 cur->peers, 956 cur->peers,
@@ -955,7 +969,8 @@ evaluate (int iteration)
955 if (GNUNET_YES == cur->valid) 969 if (GNUNET_YES == cur->valid)
956 cur_res->d_mlp.rel_value_us += cur->d_mlp.rel_value_us; 970 cur_res->d_mlp.rel_value_us += cur->d_mlp.rel_value_us;
957 971
958 fprintf (stderr, "Total time to solve %s MLP for %u peers %u addresses: %llu us\n", 972 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
973 "Total time to solve %s MLP for %u peers %u addresses: %llu us\n",
959 (GNUNET_YES == cur->update) ? "updated" : "full", 974 (GNUNET_YES == cur->update) ? "updated" : "full",
960 cur->peers, cur->addresses, 975 cur->peers, cur->addresses,
961 (unsigned long long )cur->d_mlp.rel_value_us); 976 (unsigned long long )cur->d_mlp.rel_value_us);
@@ -1024,7 +1039,6 @@ evaluate_average (void)
1024 1039
1025 struct GNUNET_DISK_FileHandle *f_full; 1040 struct GNUNET_DISK_FileHandle *f_full;
1026 struct GNUNET_DISK_FileHandle *f_update; 1041 struct GNUNET_DISK_FileHandle *f_update;
1027 struct Result *cur;
1028 char * data_fn_full; 1042 char * data_fn_full;
1029 char * data_fn_update; 1043 char * data_fn_update;
1030 char * data; 1044 char * data;
@@ -1058,7 +1072,7 @@ evaluate_average (void)
1058 if (NULL == f_full) 1072 if (NULL == f_full)
1059 { 1073 {
1060 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1074 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1061 "Cannot open gnuplot file `%s'\n", 1075 "Cannot open data file `%s'\n",
1062 data_fn_full); 1076 data_fn_full);
1063 GNUNET_free (data_fn_full); 1077 GNUNET_free (data_fn_full);
1064 return; 1078 return;
@@ -1109,7 +1123,6 @@ evaluate_average (void)
1109 data_fn_update); 1123 data_fn_update);
1110 } 1124 }
1111 1125
1112 /* NEW log */
1113 for (c_peer = ph.N_peers_start; c_peer <= ph.N_peers_end; c_peer ++) 1126 for (c_peer = ph.N_peers_start; c_peer <= ph.N_peers_end; c_peer ++)
1114 { 1127 {
1115 char * data_str; 1128 char * data_str;
@@ -1119,8 +1132,10 @@ evaluate_average (void)
1119 { 1132 {
1120 struct Result *cur_res; 1133 struct Result *cur_res;
1121 1134
1135 //fprintf (stderr, "P: %u I: %u == %p \n", c_peer, c_iteration, cur_res);
1122 cur_res = ph.iterations_results[c_iteration].results_array[c_peer -1]; 1136 cur_res = ph.iterations_results[c_iteration].results_array[c_peer -1];
1123 fprintf (stderr, "P: %u I: %u: P %i A %i\n", c_peer, c_iteration, cur_res->peers, cur_res->addresses); 1137 //fprintf (stderr, "P: %u I: %u: P %i A %i\n", c_peer, c_iteration, cur_res->peers, cur_res->addresses);
1138 fprintf (stderr, "D total: %llu\n", (long long unsigned int) cur_res->d_total.rel_value_us);
1124 fprintf (stderr, "D total: %llu\n", (long long unsigned int) cur_res->d_total.rel_value_us); 1139 fprintf (stderr, "D total: %llu\n", (long long unsigned int) cur_res->d_total.rel_value_us);
1125 1140
1126 data_tmp = GNUNET_strdup (data_str); 1141 data_tmp = GNUNET_strdup (data_str);
@@ -1137,7 +1152,6 @@ evaluate_average (void)
1137 GNUNET_DISK_file_write (f_full, data_str, strlen(data_str)); 1152 GNUNET_DISK_file_write (f_full, data_str, strlen(data_str));
1138 GNUNET_free (data_str); 1153 GNUNET_free (data_str);
1139 } 1154 }
1140 /* NEW log */
1141 1155
1142 if ((NULL != f_full) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_full))) 1156 if ((NULL != f_full) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_full)))
1143 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n", 1157 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
@@ -1148,139 +1162,6 @@ evaluate_average (void)
1148 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n", 1162 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1149 data_fn_update); 1163 data_fn_update);
1150 GNUNET_free_non_null (data_fn_update); 1164 GNUNET_free_non_null (data_fn_update);
1151
1152#if 0
1153 for (c_o = 0; c_o < 2; c_o++)
1154 {
1155 if (0 == c_o)
1156 fprintf (stderr,
1157 "Duration for a full solution averaged over %i iterations\n",
1158 ph.total_iterations);
1159 if (1 == c_o)
1160 fprintf (stderr,
1161 "Duration for a full solution averaged over %i iterations\n",
1162 ph.total_iterations);
1163
1164 for (c_i = 0; c_i <= ph.N_peers_end - ph.N_peers_start; c_i++)
1165 {
1166 if (0 == c_o)
1167 {
1168 cur = &ph.averaged_full_result[c_i];
1169 }
1170 else if ((GNUNET_YES == ph.measure_updates) && (1 == c_o))
1171 {
1172 cur = &ph.averaged_update_result[c_i];
1173 }
1174 else
1175 break;
1176
1177 if (0 == cur->peers)
1178 continue;
1179
1180 str_d_total = NULL;
1181 str_d_setup = NULL;
1182 str_d_lp = NULL;
1183 str_d_mlp = NULL;
1184
1185 if (0 >= cur->valid)
1186 {
1187 fprintf (stderr,
1188 "No valid results for %s for %u peers %u addresses!\n",
1189 (GNUNET_YES == cur->update) ? "updated" : "full",
1190 cur->peers, cur->addresses);
1191 continue;
1192 }
1193
1194 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_total.rel_value_us)
1195 {
1196 fprintf (stderr,
1197 "Average total time from %u iterations to solve %s for %u peers %u addresses: %llu us\n",
1198 cur->valid,
1199 (GNUNET_YES == cur->update) ? "updated" : "full",
1200 cur->peers, cur->addresses,
1201 (unsigned long long) cur->d_total.rel_value_us / cur->valid);
1202 GNUNET_asprintf(&str_d_total, "%llu",
1203 (unsigned long long) cur->d_total.rel_value_us / cur->valid);
1204 }
1205 else
1206 GNUNET_asprintf (&str_d_total, "-1");
1207
1208 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_setup.rel_value_us)
1209 {
1210 fprintf (stderr,
1211 "Average total time from %u iterations to setup for %u peers %u addresses: %llu us\n",
1212 cur->valid, cur->peers, cur->addresses,
1213 (unsigned long long) cur->d_setup.rel_value_us / cur->valid);
1214 GNUNET_asprintf(&str_d_setup, "%llu",
1215 (unsigned long long) cur->d_setup.rel_value_us / cur->valid);
1216
1217 }
1218 else
1219 GNUNET_asprintf (&str_d_setup, "-1");
1220
1221 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_lp.rel_value_us)
1222 {
1223 fprintf (stderr,
1224 "Average total time from %u iterations to solve lp %s for %u peers %u addresses: %llu us\n",
1225 cur->valid,
1226 (GNUNET_YES == cur->update) ? "updated" : "full",
1227 cur->peers, cur->addresses,
1228 (unsigned long long) cur->d_lp.rel_value_us / cur->valid);
1229 GNUNET_asprintf(&str_d_lp, "%llu",
1230 (unsigned long long) cur->d_lp.rel_value_us / ph.total_iterations);
1231 }
1232 else
1233 GNUNET_asprintf (&str_d_lp, "-1");
1234
1235 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_mlp.rel_value_us)
1236 {
1237 fprintf (stderr,
1238 "Average total time from %u iterations to solve mlp %s for %u peers %u addresses: %llu us\n",
1239 cur->valid,
1240 (GNUNET_YES == cur->update) ? "updated" : "full",
1241 cur->peers, cur->addresses,
1242 (unsigned long long) cur->d_mlp.rel_value_us / cur->valid);
1243 GNUNET_asprintf(&str_d_mlp, "%llu",
1244 (unsigned long long) cur->d_mlp.rel_value_us / cur->valid);
1245 }
1246 else
1247 GNUNET_asprintf (&str_d_mlp, "-1");
1248
1249 data = NULL;
1250 if (GNUNET_YES == ph.create_datafile)
1251 {
1252 GNUNET_asprintf (&data,
1253 "%u;%u;%s;%s;%s;%s\n",
1254 cur->peers, cur->addresses,
1255 str_d_total,
1256 str_d_setup,
1257 str_d_lp,
1258 str_d_mlp);
1259 if (cur->update == GNUNET_NO)
1260 {
1261 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_full, data, strlen(data)))
1262 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1263 "Cannot write data to log file `%s'\n",
1264 data_fn_full);
1265 }
1266 if ((cur->update == GNUNET_YES) && (NULL != f_update))
1267 {
1268 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data)))
1269 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1270 "Cannot write data to log file `%s'\n",
1271 data_fn_update);
1272 }
1273 GNUNET_free (data);
1274 }
1275
1276 GNUNET_free_non_null (str_d_total);
1277 GNUNET_free_non_null (str_d_setup);
1278 GNUNET_free_non_null (str_d_lp);
1279 GNUNET_free_non_null (str_d_mlp);
1280 }
1281 }
1282#endif
1283
1284} 1165}
1285 1166
1286/** 1167/**
@@ -1297,7 +1178,7 @@ perf_run_iteration (void)
1297 int count_p = ph.N_peers_end; 1178 int count_p = ph.N_peers_end;
1298 int count_a = ph.N_address; 1179 int count_a = ph.N_address;
1299 struct ATS_Address * cur_addr; 1180 struct ATS_Address * cur_addr;
1300 1181 uint32_t net;
1301 1182
1302 ph.iterations_results[ph.current_iteration-1].results_array = GNUNET_malloc ((count_p) * sizeof (struct Result *)); 1183 ph.iterations_results[ph.current_iteration-1].results_array = GNUNET_malloc ((count_p) * sizeof (struct Result *));
1303 ph.peers = GNUNET_malloc ((count_p) * sizeof (struct PerfPeer)); 1184 ph.peers = GNUNET_malloc ((count_p) * sizeof (struct PerfPeer));
@@ -1308,6 +1189,7 @@ perf_run_iteration (void)
1308 1189
1309 for (cp = 0; cp < count_p; cp++) 1190 for (cp = 0; cp < count_p; cp++)
1310 { 1191 {
1192 fprintf (stderr,"%u..", cp);
1311 if (GNUNET_NO == ph.bulk_running) 1193 if (GNUNET_NO == ph.bulk_running)
1312 { 1194 {
1313 ph.bulk_running = GNUNET_YES; 1195 ph.bulk_running = GNUNET_YES;
@@ -1318,7 +1200,14 @@ perf_run_iteration (void)
1318 { 1200 {
1319 cur_addr = perf_create_address (cp, ca); 1201 cur_addr = perf_create_address (cp, ca);
1320 /* Add address */ 1202 /* Add address */
1321 uint32_t net = 1 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_ATS_NetworkTypeCount - 1); 1203
1204 /* Random network selection */
1205 //net = 1 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_ATS_NetworkTypeCount - 1);
1206 /* Random equally distributed network selection */
1207 net = 1 + (ca % (GNUNET_ATS_NetworkTypeCount - 1));
1208 /* fprintf (stderr, "Network: %u `%s'\n",
1209 * mod_net , GNUNET_ATS_print_network_type(mod_net)); */
1210
1322 cur_addr->atsi = GNUNET_new (struct GNUNET_ATS_Information); 1211 cur_addr->atsi = GNUNET_new (struct GNUNET_ATS_Information);
1323 cur_addr->atsi_count = 1; 1212 cur_addr->atsi_count = 1;
1324 cur_addr->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); 1213 cur_addr->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
@@ -1327,8 +1216,9 @@ perf_run_iteration (void)
1327 1216
1328 ph.current_a = ca + 1; 1217 ph.current_a = ca + 1;
1329 perf_address_initial_update (ph.solver, ph.addresses, cur_addr); 1218 perf_address_initial_update (ph.solver, ph.addresses, cur_addr);
1330 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1219 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1331 "Adding address for peer %u address %u\n", cp, ca); 1220 "Adding address for peer %u address %u in network %s\n", cp, ca,
1221 GNUNET_ATS_print_network_type(net));
1332 } 1222 }
1333 /* Notify solver about request */ 1223 /* Notify solver about request */
1334 ph.env.sf.s_get (ph.solver, &ph.peers[cp].id); 1224 ph.env.sf.s_get (ph.solver, &ph.peers[cp].id);
@@ -1372,7 +1262,7 @@ perf_run_iteration (void)
1372 GNUNET_assert (GNUNET_NO == ph.bulk_running); 1262 GNUNET_assert (GNUNET_NO == ph.bulk_running);
1373 } 1263 }
1374 } 1264 }
1375 1265 fprintf (stderr,"\n");
1376 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1266 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1377 "Done, cleaning up addresses\n"); 1267 "Done, cleaning up addresses\n");
1378 if (GNUNET_NO == ph.bulk_running) 1268 if (GNUNET_NO == ph.bulk_running)