summaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-08-23 15:34:50 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-08-23 15:34:50 +0000
commit8830d27022a4c303baab008ad5d4dfeef0c0ee8e (patch)
tree213aa70cf04e8131f198cdd8600806011851138a /src/testbed
parentc60f24fa1d3db9f446d8cc6cc5606e4fd387529a (diff)
downloadgnunet-8830d27022a4c303baab008ad5d4dfeef0c0ee8e.tar.gz
gnunet-8830d27022a4c303baab008ad5d4dfeef0c0ee8e.zip
- negative deviation factor
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/test_testbed_api_sd.c11
-rw-r--r--src/testbed/testbed_api_operations.c16
-rw-r--r--src/testbed/testbed_api_sd.c27
-rw-r--r--src/testbed/testbed_api_sd.h5
4 files changed, 36 insertions, 23 deletions
diff --git a/src/testbed/test_testbed_api_sd.c b/src/testbed/test_testbed_api_sd.c
index 343d1650a..d4fa7af84 100644
--- a/src/testbed/test_testbed_api_sd.c
+++ b/src/testbed/test_testbed_api_sd.c
@@ -48,24 +48,26 @@ run (void *cls, char *const *args, const char *cfgfile,
48 const struct GNUNET_CONFIGURATION_Handle *config) 48 const struct GNUNET_CONFIGURATION_Handle *config)
49{ 49{
50 struct SDHandle *h = GNUNET_TESTBED_SD_init_ (20); 50 struct SDHandle *h = GNUNET_TESTBED_SD_init_ (20);
51 int sd;
51 52
52 ret = 0; 53 ret = 0;
53 GNUNET_TESTBED_SD_add_data_ (h, 40); 54 GNUNET_TESTBED_SD_add_data_ (h, 40);
54 if (GNUNET_SYSERR != GNUNET_TESTBED_SD_deviation_factor_ (h, 10)) 55 if (GNUNET_SYSERR != GNUNET_TESTBED_SD_deviation_factor_ (h, 10, &sd))
55 { 56 {
56 GNUNET_break (0); 57 GNUNET_break (0);
57 ret = 1; 58 ret = 1;
58 goto err; 59 goto err;
59 } 60 }
60 GNUNET_TESTBED_SD_add_data_ (h, 30); 61 GNUNET_TESTBED_SD_add_data_ (h, 30);
61 if (GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 80)) 62 if (GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 80, &sd))
62 { 63 {
63 GNUNET_break (0); 64 GNUNET_break (0);
64 ret = 1; 65 ret = 1;
65 goto err; 66 goto err;
66 } 67 }
67 GNUNET_TESTBED_SD_add_data_ (h, 40); 68 GNUNET_TESTBED_SD_add_data_ (h, 40);
68 if (0 != GNUNET_TESTBED_SD_deviation_factor_ (h, 10)) 69 if ((GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 30, &sd))
70 || (-2 != sd))
69 { 71 {
70 GNUNET_break (0); 72 GNUNET_break (0);
71 ret = 1; 73 ret = 1;
@@ -73,7 +75,8 @@ run (void *cls, char *const *args, const char *cfgfile,
73 } 75 }
74 GNUNET_TESTBED_SD_add_data_ (h, 10); 76 GNUNET_TESTBED_SD_add_data_ (h, 10);
75 GNUNET_TESTBED_SD_add_data_ (h, 30); 77 GNUNET_TESTBED_SD_add_data_ (h, 30);
76 if (3 != GNUNET_TESTBED_SD_deviation_factor_ (h, 60)) 78 if ((GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 60, &sd))
79 || (3 != sd))
77 { 80 {
78 GNUNET_break (0); 81 GNUNET_break (0);
79 ret = 1; 82 ret = 1;
diff --git a/src/testbed/testbed_api_operations.c b/src/testbed/testbed_api_operations.c
index e1034a18c..c09ec366a 100644
--- a/src/testbed/testbed_api_operations.c
+++ b/src/testbed/testbed_api_operations.c
@@ -854,17 +854,19 @@ adapt_parallelism (struct OperationQueue *queue, int fail)
854 } 854 }
855 GNUNET_assert (nvals >= queue->max_active); 855 GNUNET_assert (nvals >= queue->max_active);
856 avg = GNUNET_TIME_relative_divide (avg, nvals); 856 avg = GNUNET_TIME_relative_divide (avg, nvals);
857 sd = GNUNET_TESTBED_SD_deviation_factor_ (fctx->sd, (unsigned int) 857 if (GNUNET_SYSERR ==
858 avg.rel_value_us); 858 GNUNET_TESTBED_SD_deviation_factor_ (fctx->sd,
859 if ( (sd <= 5) || 859 (unsigned int) avg.rel_value_us,
860 (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 860 &sd))
861 queue->max_active)) )
862 GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us);
863 if (GNUNET_SYSERR == sd)
864 { 861 {
862 GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us);
865 adaptive_queue_set_max_active (queue, queue->max_active); /* no change */ 863 adaptive_queue_set_max_active (queue, queue->max_active); /* no change */
866 return; 864 return;
867 } 865 }
866 if ((0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, queue->max_active)))
867 GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us);
868 if (sd < 0)
869 sd = 0;
868 GNUNET_assert (0 <= sd); 870 GNUNET_assert (0 <= sd);
869 if ((0 == sd) && (! fail)) 871 if ((0 == sd) && (! fail))
870 { 872 {
diff --git a/src/testbed/testbed_api_sd.c b/src/testbed/testbed_api_sd.c
index cbafff08f..62f358de9 100644
--- a/src/testbed/testbed_api_sd.c
+++ b/src/testbed/testbed_api_sd.c
@@ -173,33 +173,40 @@ GNUNET_TESTBED_SD_add_data_ (struct SDHandle *h, unsigned int amount)
173 173
174 174
175/** 175/**
176 * Returns the factor by which the given amount differs from the standard deviation 176 * Calculates the factor by which the given amount differs
177 * 177 *
178 * @param h the SDhandle 178 * @param h the SDhandle
179 * @param amount the value for which the deviation is returned 179 * @param amount the value for which the deviation is returned
180 180 * @param factor the factor by which the given amont differs
181 * @return the deviation from the average; GNUNET_SYSERR if the deviation cannot 181 * @return GNUNET_SYSERR if the deviation cannot
182 * be calculated OR 0 if the given amount is less than or equal to the 182 * be calculated; GNUNET_OK if the deviation is returned through factor
183 * average; a maximum of 4 is returned for deviations equal to or
184 * larger than 4
185 */ 183 */
186int 184int
187GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount) 185GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount,
186 int *factor)
188{ 187{
189 double diff; 188 double diff;
190 unsigned int n; 189 int f;
190 int n;
191 191
192 if (h->cnt < 2) 192 if (h->cnt < 2)
193 return GNUNET_SYSERR; 193 return GNUNET_SYSERR;
194 if (((float) amount) > h->avg) 194 if (((float) amount) > h->avg)
195 {
195 diff = ((float) amount) - h->avg; 196 diff = ((float) amount) - h->avg;
197 f = 1;
198 }
196 else 199 else
197 return 0; //diff = h->avg - ((float) amount); 200 {
201 diff = h->avg - ((float) amount);
202 f = -1;
203 }
198 diff *= diff; 204 diff *= diff;
199 for (n = 1; n < 4; n++) 205 for (n = 1; n < 4; n++)
200 if (diff < (((double) (n * n)) * h->vr)) 206 if (diff < (((double) (n * n)) * h->vr))
201 break; 207 break;
202 return n; 208 *factor = f * n;
209 return GNUNET_OK;
203} 210}
204 211
205/* end of testbed_api_sd.c */ 212/* end of testbed_api_sd.c */
diff --git a/src/testbed/testbed_api_sd.h b/src/testbed/testbed_api_sd.h
index abef1d9c7..b3e19c0bd 100644
--- a/src/testbed/testbed_api_sd.h
+++ b/src/testbed/testbed_api_sd.h
@@ -68,13 +68,14 @@ GNUNET_TESTBED_SD_add_data_ (struct SDHandle *h, unsigned int amount);
68 * 68 *
69 * @param h the SDhandle 69 * @param h the SDhandle
70 * @param amount the value for which the deviation is returned 70 * @param amount the value for which the deviation is returned
71 71 * @param factor the factor by which the given amont differs
72 * @return the deviation from the average; GNUNET_SYSERR if the deviation cannot 72 * @return the deviation from the average; GNUNET_SYSERR if the deviation cannot
73 * be calculated OR 0 if the deviation is less than the average; a 73 * be calculated OR 0 if the deviation is less than the average; a
74 * maximum of 4 is returned for deviations equal to or larger than 4 74 * maximum of 4 is returned for deviations equal to or larger than 4
75 */ 75 */
76int 76int
77GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount); 77GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount,
78 int *factor);
78 79
79#endif 80#endif
80/* end of testbed_api.h */ 81/* end of testbed_api.h */