GNUnet  0.20.0
Load library

Load calculations. More...

Collaboration diagram for Load library:

Macros

#define GNUNET_LOAD_value_free(lv)   GNUNET_free (lv)
 Free a load value. More...
 

Functions

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...
 
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

Load calculations.

Macro Definition Documentation

◆ GNUNET_LOAD_value_free

#define GNUNET_LOAD_value_free (   lv)    GNUNET_free (lv)

Free a load value.

Parameters
lvvalue to free

Definition at line 83 of file gnunet_load_lib.h.

Function Documentation

◆ GNUNET_LOAD_value_init()

struct GNUNET_LOAD_Value* GNUNET_LOAD_value_init ( struct GNUNET_TIME_Relative  autodecline)

Create a new load value.

Parameters
autodeclinespeed at which this value should automatically decline in the absence of external events; at the given frequency, 0-load values will be added to the load
Returns
the new load value

Definition at line 125 of file load.c.

126 {
127  struct GNUNET_LOAD_Value *ret;
128 
129  ret = GNUNET_new (struct GNUNET_LOAD_Value);
130  ret->autodecline = autodecline;
131  ret->last_update = GNUNET_TIME_absolute_get ();
132  return ret;
133 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
Values we track for load calculations.
Definition: load.c:37
struct GNUNET_TIME_Relative autodecline
How fast should the load decline if no values are added?
Definition: load.c:41

References GNUNET_LOAD_Value::autodecline, GNUNET_new, GNUNET_TIME_absolute_get(), and ret.

Referenced by GSF_peer_connect_handler(), GSF_pending_request_init_(), main_init(), and run().

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

◆ GNUNET_LOAD_value_set_decline()

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.

Parameters
loadload to update
autodeclinefrequency of load decline

Definition at line 143 of file load.c.

145 {
147  load->autodecline = autodecline;
148 }
static void load()
Load persistent values from disk.
static void internal_update(struct GNUNET_LOAD_Value *load)
Definition: load.c:84

References GNUNET_LOAD_Value::autodecline, internal_update(), and load().

Referenced by GSF_update_peer_latency_().

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

◆ GNUNET_LOAD_get_load()

double GNUNET_LOAD_get_load ( struct GNUNET_LOAD_Value load)

Get the current load.

Parameters
loadload handle
Returns
zero for below-average load, otherwise number of std. devs we are above average; 100 if the latest updates were so large that we could not do proper calculations

Definition at line 201 of file load.c.

202 {
205  return load->load;
206 }
static void calculate_load(struct GNUNET_LOAD_Value *load)
Recalculate our load value.
Definition: load.c:157

References calculate_load(), internal_update(), and load().

Referenced by GSF_test_get_load_too_high_(), handle_p2p_get(), handle_p2p_put(), and test_put_load_too_high().

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

◆ GNUNET_LOAD_get_average()

double GNUNET_LOAD_get_average ( struct GNUNET_LOAD_Value load)

Get the average value given to update so far.

Parameters
loadload handle
Returns
zero if update was never called

Definition at line 216 of file load.c.

217 {
218  double n;
219  double sum_val_i;
220 
222  if (load->cummulative_request_count == 0)
223  return 0.0;
224  n = ((double) load->cummulative_request_count);
225  sum_val_i = (double) load->cummulative_delay;
226  return sum_val_i / n;
227 }

References internal_update(), and load().

Referenced by handle_p2p_get(), and test_put_load_too_high().

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

◆ GNUNET_LOAD_update()

void GNUNET_LOAD_update ( struct GNUNET_LOAD_Value load,
uint64_t  data 
)

Update the current load.

Parameters
loadto update
datalatest measurement value (for example, delay)

Definition at line 237 of file load.c.

238 {
239  uint32_t dv;
240 
242  load->last_update = GNUNET_TIME_absolute_get ();
243  if (data > 64 * 1024)
244  {
245  /* very large */
246  load->load = 100.0;
247  return;
248  }
249  dv = (uint32_t) data;
250  load->cummulative_delay += dv;
251  load->cummulative_squared_delay += dv * dv;
252  load->cummulative_request_count++;
253  load->runavg_delay = ((load->runavg_delay * 7.0) + dv) / 8.0;
254 }
uint32_t data
The data value.

Referenced by GSF_update_datastore_delay_(), peer_transmit(), and put_migration_continuation().

Here is the caller graph for this function: