aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_group.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2011-03-08 13:23:25 +0000
committerNathan S. Evans <evans@in.tum.de>2011-03-08 13:23:25 +0000
commitb242f351fde95f5ab9c06325071e3be1e621b512 (patch)
treeb895711253cb5cd882967546a3aa864548bce502 /src/testing/testing_group.c
parentf41e8a193500a4a6ab185627a272d6b3765d5efc (diff)
downloadgnunet-b242f351fde95f5ab9c06325071e3be1e621b512.tar.gz
gnunet-b242f351fde95f5ab9c06325071e3be1e621b512.zip
1000x speedup when reading large topology files
Diffstat (limited to 'src/testing/testing_group.c')
-rw-r--r--src/testing/testing_group.c79
1 files changed, 29 insertions, 50 deletions
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c
index fb6d9adda..0da1131ba 100644
--- a/src/testing/testing_group.c
+++ b/src/testing/testing_group.c
@@ -42,6 +42,8 @@
42 42
43#define TOPOLOGY_HACK GNUNET_YES 43#define TOPOLOGY_HACK GNUNET_YES
44 44
45#define AVOID_CONN_MALLOC GNUNET_YES
46
45/** 47/**
46 * Lowest port used for GNUnet testing. Should be high enough to not 48 * Lowest port used for GNUnet testing. Should be high enough to not
47 * conflict with other applications running on the hosts but be low 49 * conflict with other applications running on the hosts but be low
@@ -782,6 +784,12 @@ struct GNUNET_TESTING_PeerGroup
782 * Connection context for peer group. 784 * Connection context for peer group.
783 */ 785 */
784 struct ConnectTopologyContext ct_ctx; 786 struct ConnectTopologyContext ct_ctx;
787
788#if AVOID_CONN_MALLOC
789 struct PeerConnection working_peer_connections[200000];
790
791 unsigned int current_peer_connection;
792#endif
785}; 793};
786 794
787struct UpdateContext 795struct UpdateContext
@@ -1569,7 +1577,7 @@ add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first,
1569 int added; 1577 int added;
1570 int add_first; 1578 int add_first;
1571 int add_second; 1579 int add_second;
1572#if OLD 1580
1573 struct PeerConnection **first_list; 1581 struct PeerConnection **first_list;
1574 struct PeerConnection **second_list; 1582 struct PeerConnection **second_list;
1575 struct PeerConnection *first_iter; 1583 struct PeerConnection *first_iter;
@@ -1578,15 +1586,7 @@ add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first,
1578 struct PeerConnection *new_second; 1586 struct PeerConnection *new_second;
1579 struct PeerConnection **first_tail; 1587 struct PeerConnection **first_tail;
1580 struct PeerConnection **second_tail; 1588 struct PeerConnection **second_tail;
1581#else
1582 GNUNET_HashCode hash_first;
1583 GNUNET_HashCode hash_second;
1584
1585 hash_from_uid (first, &hash_first);
1586 hash_from_uid (second, &hash_second);
1587#endif
1588 1589
1589#if OLD
1590 switch (list) 1590 switch (list)
1591 { 1591 {
1592 case ALLOWED: 1592 case ALLOWED:
@@ -1645,59 +1645,32 @@ add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first,
1645 second_iter = second_iter->next; 1645 second_iter = second_iter->next;
1646 } 1646 }
1647 } 1647 }
1648#else
1649 if (GNUNET_NO ==
1650 GNUNET_CONTAINER_multihashmap_contains (pg->peers[first].blacklisted_peers,
1651 &hash_second))
1652 {
1653 add_first = GNUNET_YES;
1654 }
1655
1656 if (GNUNET_NO ==
1657 GNUNET_CONTAINER_multihashmap_contains (pg->peers[second].blacklisted_peers,
1658 &hash_first))
1659 {
1660 add_second = GNUNET_YES;
1661 }
1662#endif
1663 1648
1664 added = 0; 1649 added = 0;
1665 if (add_first) 1650 if (add_first)
1666 { 1651 {
1667#if OLD 1652#if AVOID_CONN_MALLOC
1653 new_first = &pg->working_peer_connections[pg->current_peer_connection];
1654 pg->current_peer_connection++;
1655#else
1668 new_first = GNUNET_malloc (sizeof (struct PeerConnection)); 1656 new_first = GNUNET_malloc (sizeof (struct PeerConnection));
1657#endif
1669 new_first->index = second; 1658 new_first->index = second;
1670 GNUNET_CONTAINER_DLL_insert(*first_list, *first_tail, new_first); 1659 GNUNET_CONTAINER_DLL_insert(*first_list, *first_tail, new_first);
1671#else
1672 GNUNET_assert (GNUNET_OK ==
1673 GNUNET_CONTAINER_multihashmap_put (pg->
1674 peers
1675 [first].blacklisted_peers,
1676 &hash_second,
1677 pg->
1678 peers[second].daemon,
1679 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1680#endif
1681 pg->peers[first].num_connections++; 1660 pg->peers[first].num_connections++;
1682 added++; 1661 added++;
1683 } 1662 }
1684 1663
1685 if (add_second) 1664 if (add_second)
1686 { 1665 {
1687#if OLD 1666#if AVOID_CONN_MALLOC
1667 new_second = &pg->working_peer_connections[pg->current_peer_connection];
1668 pg->current_peer_connection++;
1669#else
1688 new_second = GNUNET_malloc (sizeof (struct PeerConnection)); 1670 new_second = GNUNET_malloc (sizeof (struct PeerConnection));
1671#endif
1689 new_second->index = first; 1672 new_second->index = first;
1690 GNUNET_CONTAINER_DLL_insert(*second_list, *second_tail, new_second); 1673 GNUNET_CONTAINER_DLL_insert(*second_list, *second_tail, new_second);
1691#else
1692 GNUNET_assert (GNUNET_OK ==
1693 GNUNET_CONTAINER_multihashmap_put (pg->
1694 peers
1695 [second].blacklisted_peers,
1696 &hash_first,
1697 pg->
1698 peers[first].daemon,
1699 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1700#endif
1701 pg->peers[second].num_connections++; 1674 pg->peers[second].num_connections++;
1702 added++; 1675 added++;
1703 } 1676 }
@@ -2593,7 +2566,9 @@ create_from_file(struct GNUNET_TESTING_PeerGroup *pg, char *filename,
2593 switch (curr_state) 2566 switch (curr_state)
2594 { 2567 {
2595 case NUM_PEERS: 2568 case NUM_PEERS:
2596 if (1 != sscanf (&buf[count], "%u", &total_peers)) 2569 errno = 0;
2570 total_peers = strtoul(&buf[count], NULL, 10);
2571 if (errno != 0)
2597 { 2572 {
2598 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2573 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2599 "Failed to read number of peers from topology file!\n"); 2574 "Failed to read number of peers from topology file!\n");
@@ -2609,7 +2584,9 @@ create_from_file(struct GNUNET_TESTING_PeerGroup *pg, char *filename,
2609 count++; 2584 count++;
2610 break; 2585 break;
2611 case PEER_INDEX: 2586 case PEER_INDEX:
2612 if (1 != sscanf (&buf[count], "%u", &first_peer_index)) 2587 errno = 0;
2588 first_peer_index = strtoul(&buf[count], NULL, 10);
2589 if (errno != 0)
2613 { 2590 {
2614 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2591 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2615 "Failed to read peer index from topology file!\n"); 2592 "Failed to read peer index from topology file!\n");
@@ -2627,7 +2604,9 @@ create_from_file(struct GNUNET_TESTING_PeerGroup *pg, char *filename,
2627 count++; 2604 count++;
2628 break; 2605 break;
2629 case OTHER_PEER_INDEX: 2606 case OTHER_PEER_INDEX:
2630 if (1 != sscanf (&buf[count], "%u", &second_peer_index)) 2607 errno = 0;
2608 second_peer_index = strtoul(&buf[count], NULL, 10);
2609 if (errno != 0)
2631 { 2610 {
2632 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2611 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2633 "Failed to peer index from topology file!\n"); 2612 "Failed to peer index from topology file!\n");
@@ -2636,7 +2615,7 @@ create_from_file(struct GNUNET_TESTING_PeerGroup *pg, char *filename,
2636 } 2615 }
2637 /* Assume file is written with first peer 1, but array index is 0 */ 2616 /* Assume file is written with first peer 1, but array index is 0 */
2638 connect_attempts += proc (pg, first_peer_index - 1, second_peer_index 2617 connect_attempts += proc (pg, first_peer_index - 1, second_peer_index
2639 - 1, list, GNUNET_YES); 2618 - 1, list, GNUNET_YES);
2640 while ((buf[count] != '\n') && (buf[count] != ',') && (count 2619 while ((buf[count] != '\n') && (buf[count] != ',') && (count
2641 < frstat.st_size - 1)) 2620 < frstat.st_size - 1))
2642 count++; 2621 count++;