GNUnet 0.22.2
load.c File Reference

functions related to load calculations More...

#include "gnunet_load_lib.h"
Include dependency graph for load.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_LOAD_Value
 Values we track for load calculations. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "util-load", __VA_ARGS__)
 

Functions

static void internal_update (struct GNUNET_LOAD_Value *load)
 
struct GNUNET_LOAD_ValueGNUNET_LOAD_value_init (struct GNUNET_TIME_Relative autodecline)
 Create a new load value. More...
 
void GNUNET_LOAD_value_set_decline (struct GNUNET_LOAD_Value *load, struct GNUNET_TIME_Relative autodecline)
 Change the value by which the load automatically declines. More...
 
static void calculate_load (struct GNUNET_LOAD_Value *load)
 Recalculate our load value. More...
 
double GNUNET_LOAD_get_load (struct GNUNET_LOAD_Value *load)
 Get the current load. More...
 
double GNUNET_LOAD_get_average (struct GNUNET_LOAD_Value *load)
 Get the average value given to update so far. More...
 
void GNUNET_LOAD_update (struct GNUNET_LOAD_Value *load, uint64_t data)
 Update the current load. More...
 

Detailed Description

functions related to load calculations

Author
Christian Grothoff

Definition in file load.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "util-load", __VA_ARGS__)

Definition at line 30 of file load.c.

Function Documentation

◆ internal_update()

static void internal_update ( struct GNUNET_LOAD_Value load)
static

Definition at line 83 of file load.c.

84{
86 unsigned int n;
87
88 if (load->autodecline.rel_value_us ==
90 return;
92 if (delta.rel_value_us < load->autodecline.rel_value_us)
93 return;
94 if (0 == load->autodecline.rel_value_us)
95 {
96 load->runavg_delay = 0.0;
97 load->load = 0;
98 return;
99 }
100 n = delta.rel_value_us / load->autodecline.rel_value_us;
101 if (n > 16)
102 {
103 load->runavg_delay = 0.0;
104 load->load = 0;
105 return;
106 }
107 while (n > 0)
108 {
109 n--;
110 load->runavg_delay = (load->runavg_delay * 7.0) / 8.0;
111 }
112}
static void load()
Load persistent values from disk.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:438
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:36
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.

References delta, GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_UNIT_FOREVER_REL, load(), and GNUNET_TIME_Relative::rel_value_us.

Referenced by GNUNET_LOAD_get_average(), GNUNET_LOAD_get_load(), GNUNET_LOAD_update(), and GNUNET_LOAD_value_set_decline().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_load()

static void calculate_load ( struct GNUNET_LOAD_Value load)
static

Recalculate our load value.

Parameters
loadload to update

Definition at line 156 of file load.c.

157{
158 double stddev;
159 double avgdel;
160 double sum_val_i;
161 double n;
162 double nm1;
163
164 if (load->cummulative_request_count <= 1)
165 return;
166 /* calculate std dev of latency; we have for n values of "i" that:
167 *
168 * avg = (sum val_i) / n
169 * stddev = (sum (val_i - avg)^2) / (n-1)
170 * = (sum (val_i^2 - 2 avg val_i + avg^2) / (n-1)
171 * = (sum (val_i^2) - 2 avg sum (val_i) + n * avg^2) / (n-1)
172 */sum_val_i = (double) load->cummulative_delay;
173 n = ((double) load->cummulative_request_count);
174 nm1 = n - 1.0;
175 avgdel = sum_val_i / n;
176 stddev =
177 (((double) load->cummulative_squared_delay) - 2.0 * avgdel * sum_val_i
178 + n * avgdel * avgdel) / nm1;
179 if (stddev <= 0)
180 stddev = 0.01; /* must have been rounding error or zero; prevent division by zero */
181 /* now calculate load based on how far out we are from
182 * std dev; or if we are below average, simply assume load zero */
183 if (load->runavg_delay < avgdel)
184 load->load = 0.0;
185 else
186 load->load = (load->runavg_delay - avgdel) / stddev;
187}

References load().

Referenced by GNUNET_LOAD_get_load().

Here is the call graph for this function:
Here is the caller graph for this function: