GNUnet  0.20.0
load.c File Reference

functions related to load calculations More...

#include "platform.h"
#include "gnunet_util_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 31 of file load.c.

Function Documentation

◆ internal_update()

static void internal_update ( struct GNUNET_LOAD_Value load)
static

Definition at line 84 of file load.c.

85 {
87  unsigned int n;
88 
89  if (load->autodecline.rel_value_us ==
90  GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
91  return;
93  if (delta.rel_value_us < load->autodecline.rel_value_us)
94  return;
95  if (0 == load->autodecline.rel_value_us)
96  {
97  load->runavg_delay = 0.0;
98  load->load = 0;
99  return;
100  }
101  n = delta.rel_value_us / load->autodecline.rel_value_us;
102  if (n > 16)
103  {
104  load->runavg_delay = 0.0;
105  load->load = 0;
106  return;
107  }
108  while (n > 0)
109  {
110  n--;
111  load->runavg_delay = (load->runavg_delay * 7.0) / 8.0;
112  }
113 }
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:436
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(), 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 157 of file load.c.

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

References load().

Referenced by GNUNET_LOAD_get_load().

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