GNUnet  0.10.x
Data Structures | Macros | Functions
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 30 of file load.c.

Function Documentation

◆ internal_update()

static void internal_update ( struct GNUNET_LOAD_Value load)
static

Definition at line 82 of file load.c.

References GNUNET_LOAD_Value::autodecline, GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_LOAD_Value::last_update, GNUNET_LOAD_Value::load, GNUNET_TIME_Relative::rel_value_us, and GNUNET_LOAD_Value::runavg_delay.

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

83 {
85  unsigned int n;
86 
87  if (load->autodecline.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
88  return;
91  return;
92  if (0 == load->autodecline.rel_value_us)
93  {
94  load->runavg_delay = 0.0;
95  load->load = 0;
96  return;
97  }
99  if (n > 16)
100  {
101  load->runavg_delay = 0.0;
102  load->load = 0;
103  return;
104  }
105  while (n > 0)
106  {
107  n--;
108  load->runavg_delay = (load->runavg_delay * 7.0) / 8.0;
109  }
110 }
double runavg_delay
Current running average datastore delay.
Definition: load.c:70
uint64_t rel_value_us
The actual value.
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:35
double load
How high is the load? 0 for below average, otherwise the number of std.
Definition: load.c:77
struct GNUNET_TIME_Relative autodecline
How fast should the load decline if no values are added?
Definition: load.c:39
#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:373
struct GNUNET_TIME_Absolute last_update
Last time this load value was updated by an event.
Definition: load.c:44
Time for relative time used by GNUnet, in microseconds.
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 154 of file load.c.

References GNUNET_LOAD_Value::cummulative_delay, GNUNET_LOAD_Value::cummulative_request_count, GNUNET_LOAD_Value::cummulative_squared_delay, GNUNET_LOAD_Value::load, and GNUNET_LOAD_Value::runavg_delay.

Referenced by GNUNET_LOAD_get_load().

155 {
156  double stddev;
157  double avgdel;
158  double sum_val_i;
159  double n;
160  double nm1;
161 
162  if (load->cummulative_request_count <= 1)
163  return;
164  /* calcuate std dev of latency; we have for n values of "i" that:
165  *
166  * avg = (sum val_i) / n
167  * stddev = (sum (val_i - avg)^2) / (n-1)
168  * = (sum (val_i^2 - 2 avg val_i + avg^2) / (n-1)
169  * = (sum (val_i^2) - 2 avg sum (val_i) + n * avg^2) / (n-1)
170  */
171  sum_val_i = (double)load->cummulative_delay;
172  n = ((double)load->cummulative_request_count);
173  nm1 = n - 1.0;
174  avgdel = sum_val_i / n;
175  stddev =
176  (((double)load->cummulative_squared_delay) - 2.0 * avgdel * sum_val_i +
177  n * avgdel * avgdel) / nm1;
178  if (stddev <= 0)
179  stddev = 0.01; /* must have been rounding error or zero; prevent division by zero */
180  /* now calculate load based on how far out we are from
181  * std dev; or if we are below average, simply assume load zero */
182  if (load->runavg_delay < avgdel)
183  load->load = 0.0;
184  else
185  load->load = (load->runavg_delay - avgdel) / stddev;
186 }
double runavg_delay
Current running average datastore delay.
Definition: load.c:70
double load
How high is the load? 0 for below average, otherwise the number of std.
Definition: load.c:77
uint64_t cummulative_delay
Sum of all datastore delays ever observed (in ms).
Definition: load.c:51
uint64_t cummulative_request_count
Total number of requests included in the cummulative datastore delay values.
Definition: load.c:63
uint64_t cummulative_squared_delay
Sum of squares of all datastore delays ever observed (in ms).
Definition: load.c:58
Here is the caller graph for this function: