aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_hosts.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-08-19 14:13:19 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-08-19 14:13:19 +0000
commit9dd0824b40e7afeaf948a564d544b384db12cadf (patch)
tree4d98c8d27669e8eca6259a9601e32fddfa67e39c /src/testbed/testbed_api_hosts.c
parentd4051630bbc5f521142f302baad60212b75f8b7f (diff)
downloadgnunet-9dd0824b40e7afeaf948a564d544b384db12cadf.tar.gz
gnunet-9dd0824b40e7afeaf948a564d544b384db12cadf.zip
fix 2893: Move adaptive parallelisation mechanism to operation queues
Diffstat (limited to 'src/testbed/testbed_api_hosts.c')
-rw-r--r--src/testbed/testbed_api_hosts.c238
1 files changed, 2 insertions, 236 deletions
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c
index cd805dca1..b7c824bc2 100644
--- a/src/testbed/testbed_api_hosts.c
+++ b/src/testbed/testbed_api_hosts.c
@@ -35,7 +35,6 @@
35#include "testbed_api_hosts.h" 35#include "testbed_api_hosts.h"
36#include "testbed_helper.h" 36#include "testbed_helper.h"
37#include "testbed_api_operations.h" 37#include "testbed_api_operations.h"
38#include "testbed_api_sd.h"
39 38
40#include <zlib.h> 39#include <zlib.h>
41 40
@@ -97,28 +96,6 @@ struct RegisteredController
97 96
98 97
99/** 98/**
100 * A slot to record time taken by an overlay connect operation
101 */
102struct TimeSlot
103{
104 /**
105 * A key to identify this timeslot
106 */
107 void *key;
108
109 /**
110 * Time
111 */
112 struct GNUNET_TIME_Relative time;
113
114 /**
115 * Number of timing values accumulated
116 */
117 unsigned int nvals;
118};
119
120
121/**
122 * Opaque handle to a host running experiments managed by the testing framework. 99 * Opaque handle to a host running experiments managed by the testing framework.
123 * The master process must be able to SSH to this host without password (via 100 * The master process must be able to SSH to this host without password (via
124 * ssh-agent). 101 * ssh-agent).
@@ -161,28 +138,6 @@ struct GNUNET_TESTBED_Host
161 struct OperationQueue *opq_parallel_overlay_connect_operations; 138 struct OperationQueue *opq_parallel_overlay_connect_operations;
162 139
163 /** 140 /**
164 * An array of timing slots; size should be equal to the current number of parallel
165 * overlay connects
166 */
167 struct TimeSlot *tslots;
168
169 /**
170 * Handle for SD calculations amount parallel overlay connect operation finish
171 * times
172 */
173 struct SDHandle *poc_sd;
174
175 /**
176 * The number of parallel overlay connects we do currently
177 */
178 unsigned int num_parallel_connects;
179
180 /**
181 * Counter to indicate when all the available time slots are filled
182 */
183 unsigned int tslots_filled;
184
185 /**
186 * Is a controller started on this host? FIXME: Is this needed? 141 * Is a controller started on this host? FIXME: Is this needed?
187 */ 142 */
188 int controller_started; 143 int controller_started;
@@ -382,9 +337,8 @@ GNUNET_TESTBED_host_create_with_id (uint32_t id, const char *hostname,
382 host->port = (0 == port) ? 22 : port; 337 host->port = (0 == port) ? 22 : port;
383 host->cfg = GNUNET_CONFIGURATION_dup (cfg); 338 host->cfg = GNUNET_CONFIGURATION_dup (cfg);
384 host->opq_parallel_overlay_connect_operations = 339 host->opq_parallel_overlay_connect_operations =
385 GNUNET_TESTBED_operation_queue_create_ (0); 340 GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_ADAPTIVE,
386 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (host, 1); 341 UINT_MAX);
387 host->poc_sd = GNUNET_TESTBED_SD_init_ (10);
388 new_size = host_list_size; 342 new_size = host_list_size;
389 while (id >= new_size) 343 while (id >= new_size)
390 new_size += HOST_LIST_GROW_STEP; 344 new_size += HOST_LIST_GROW_STEP;
@@ -740,8 +694,6 @@ GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host)
740 GNUNET_free_non_null ((char *) host->hostname); 694 GNUNET_free_non_null ((char *) host->hostname);
741 GNUNET_TESTBED_operation_queue_destroy_ 695 GNUNET_TESTBED_operation_queue_destroy_
742 (host->opq_parallel_overlay_connect_operations); 696 (host->opq_parallel_overlay_connect_operations);
743 GNUNET_TESTBED_SD_destroy_ (host->poc_sd);
744 GNUNET_free_non_null (host->tslots);
745 GNUNET_CONFIGURATION_destroy (host->cfg); 697 GNUNET_CONFIGURATION_destroy (host->cfg);
746 GNUNET_free (host); 698 GNUNET_free (host);
747 while (host_list_size >= HOST_LIST_GROW_STEP) 699 while (host_list_size >= HOST_LIST_GROW_STEP)
@@ -1624,192 +1576,6 @@ GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
1624 1576
1625 1577
1626/** 1578/**
1627 * Initializes the operation queue for parallel overlay connects
1628 *
1629 * @param h the host handle
1630 * @param npoc the number of parallel overlay connects - the queue size
1631 */
1632void
1633GNUNET_TESTBED_set_num_parallel_overlay_connects_ (struct
1634 GNUNET_TESTBED_Host *h,
1635 unsigned int npoc)
1636{
1637 //fprintf (stderr, "%d", npoc);
1638 GNUNET_free_non_null (h->tslots);
1639 h->tslots_filled = 0;
1640 h->num_parallel_connects = npoc;
1641 h->tslots = GNUNET_malloc (npoc * sizeof (struct TimeSlot));
1642 GNUNET_TESTBED_operation_queue_reset_max_active_
1643 (h->opq_parallel_overlay_connect_operations, npoc);
1644}
1645
1646
1647/**
1648 * Returns a timing slot which will be exclusively locked
1649 *
1650 * @param h the host handle
1651 * @param key a pointer which is associated to the returned slot; should not be
1652 * NULL. It serves as a key to determine the correct owner of the slot
1653 * @return the time slot index in the array of time slots in the controller
1654 * handle
1655 */
1656unsigned int
1657GNUNET_TESTBED_get_tslot_ (struct GNUNET_TESTBED_Host *h, void *key)
1658{
1659 unsigned int slot;
1660
1661 GNUNET_assert (NULL != h->tslots);
1662 GNUNET_assert (NULL != key);
1663 for (slot = 0; slot < h->num_parallel_connects; slot++)
1664 if (NULL == h->tslots[slot].key)
1665 {
1666 h->tslots[slot].key = key;
1667 return slot;
1668 }
1669 GNUNET_assert (0); /* We should always find a free tslot */
1670}
1671
1672
1673/**
1674 * Decides whether any change in the number of parallel overlay connects is
1675 * necessary to adapt to the load on the system
1676 *
1677 * @param h the host handle
1678 */
1679static void
1680decide_npoc (struct GNUNET_TESTBED_Host *h)
1681{
1682 struct GNUNET_TIME_Relative avg;
1683 int sd;
1684 unsigned int slot;
1685 unsigned int nvals;
1686
1687 if (h->tslots_filled != h->num_parallel_connects)
1688 return;
1689 avg = GNUNET_TIME_UNIT_ZERO;
1690 nvals = 0;
1691 for (slot = 0; slot < h->num_parallel_connects; slot++)
1692 {
1693 avg = GNUNET_TIME_relative_add (avg, h->tslots[slot].time);
1694 nvals += h->tslots[slot].nvals;
1695 }
1696 GNUNET_assert (nvals >= h->num_parallel_connects);
1697 avg = GNUNET_TIME_relative_divide (avg, nvals);
1698 GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != avg.rel_value_us);
1699 sd = GNUNET_TESTBED_SD_deviation_factor_ (h->poc_sd, (unsigned int) avg.rel_value_us);
1700 if ( (sd <= 5) ||
1701 (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1702 h->num_parallel_connects)) )
1703 GNUNET_TESTBED_SD_add_data_ (h->poc_sd, (unsigned int) avg.rel_value_us);
1704 if (GNUNET_SYSERR == sd)
1705 {
1706 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
1707 h->num_parallel_connects);
1708 return;
1709 }
1710 GNUNET_assert (0 <= sd);
1711 if (0 == sd)
1712 {
1713 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
1714 h->num_parallel_connects
1715 * 2);
1716 return;
1717 }
1718 if (1 == sd)
1719 {
1720 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
1721 h->num_parallel_connects
1722 + 1);
1723 return;
1724 }
1725 if (1 == h->num_parallel_connects)
1726 {
1727 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h, 1);
1728 return;
1729 }
1730 if (2 == sd)
1731 {
1732 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
1733 h->num_parallel_connects
1734 - 1);
1735 return;
1736 }
1737 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
1738 h->num_parallel_connects /
1739 2);
1740}
1741
1742
1743/**
1744 * Releases a time slot thus making it available for be used again
1745 *
1746 * @param h the host handle
1747 * @param index the index of the the time slot
1748 * @param key the key to prove ownership of the timeslot
1749 * @return GNUNET_YES if the time slot is successfully removed; GNUNET_NO if the
1750 * time slot cannot be removed - this could be because of the index
1751 * greater than existing number of time slots or `key' being different
1752 */
1753int
1754GNUNET_TESTBED_release_time_slot_ (struct GNUNET_TESTBED_Host *h,
1755 unsigned int index, void *key)
1756{
1757 struct TimeSlot *slot;
1758
1759 GNUNET_assert (NULL != key);
1760 if (index >= h->num_parallel_connects)
1761 return GNUNET_NO;
1762 slot = &h->tslots[index];
1763 if (key != slot->key)
1764 return GNUNET_NO;
1765 slot->key = NULL;
1766 return GNUNET_YES;
1767}
1768
1769
1770/**
1771 * Function to update a time slot
1772 *
1773 * @param h the host handle
1774 * @param index the index of the time slot to update
1775 * @param key the key to identify ownership of the slot
1776 * @param time the new time
1777 * @param failed should this reading be treated as coming from a fail event
1778 */
1779void
1780GNUNET_TESTBED_update_time_slot_ (struct GNUNET_TESTBED_Host *h,
1781 unsigned int index, void *key,
1782 struct GNUNET_TIME_Relative time, int failed)
1783{
1784 struct TimeSlot *slot;
1785
1786 if (GNUNET_YES == failed)
1787 {
1788 if (1 == h->num_parallel_connects)
1789 {
1790 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h, 1);
1791 return;
1792 }
1793 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
1794 h->num_parallel_connects
1795 - 1);
1796 }
1797 if (GNUNET_NO == GNUNET_TESTBED_release_time_slot_ (h, index, key))
1798 return;
1799 slot = &h->tslots[index];
1800 slot->nvals++;
1801 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == slot->time.rel_value_us)
1802 {
1803 slot->time = time;
1804 h->tslots_filled++;
1805 decide_npoc (h);
1806 return;
1807 }
1808 slot->time = GNUNET_TIME_relative_add (slot->time, time);
1809}
1810
1811
1812/**
1813 * Queues the given operation in the queue for parallel overlay connects of the 1579 * Queues the given operation in the queue for parallel overlay connects of the
1814 * given host 1580 * given host
1815 * 1581 *