GNUnet  0.10.x
Macros | Functions
Load library

Load calculations. More...

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 79 of file gnunet_load_lib.h.

Referenced by GSF_peer_disconnect_handler(), GSF_pending_request_done_(), and shutdown_task().

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.

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

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

126 {
127  struct GNUNET_LOAD_Value *ret;
128 
129  ret = GNUNET_new (struct GNUNET_LOAD_Value);
130  ret->autodecline = autodecline;
132  return ret;
133 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_TIME_Relative autodecline
How fast should the load decline if no values are added?
Definition: load.c:41
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
Values we track for load calculations.
Definition: load.c:35
struct GNUNET_TIME_Absolute last_update
Last time this load value was updated by an event.
Definition: load.c:46
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.

References GNUNET_LOAD_Value::autodecline, and internal_update().

Referenced by GSF_update_peer_latency_().

145 {
146  internal_update (load);
147  load->autodecline = autodecline;
148 }
struct GNUNET_TIME_Relative autodecline
How fast should the load decline if no values are added?
Definition: load.c:41
static void internal_update(struct GNUNET_LOAD_Value *load)
Definition: load.c:85
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 202 of file load.c.

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

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

203 {
204  internal_update (load);
205  calculate_load (load);
206  return load->load;
207 }
double load
How high is the load? 0 for below average, otherwise the number of std.
Definition: load.c:79
static void internal_update(struct GNUNET_LOAD_Value *load)
Definition: load.c:85
static void calculate_load(struct GNUNET_LOAD_Value *load)
Recalculate our load value.
Definition: load.c:157
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 217 of file load.c.

References GNUNET_LOAD_Value::cummulative_delay, GNUNET_LOAD_Value::cummulative_request_count, and internal_update().

Referenced by handle_p2p_get(), and test_put_load_too_high().

218 {
219  double n;
220  double sum_val_i;
221 
222  internal_update (load);
223  if (load->cummulative_request_count == 0)
224  return 0.0;
225  n = ((double) load->cummulative_request_count);
226  sum_val_i = (double) load->cummulative_delay;
227  return sum_val_i / n;
228 }
uint64_t cummulative_delay
Sum of all datastore delays ever observed (in ms).
Definition: load.c:53
uint64_t cummulative_request_count
Total number of requests included in the cummulative datastore delay values.
Definition: load.c:65
static void internal_update(struct GNUNET_LOAD_Value *load)
Definition: load.c:85
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 238 of file load.c.

References GNUNET_LOAD_Value::cummulative_delay, GNUNET_LOAD_Value::cummulative_request_count, GNUNET_LOAD_Value::cummulative_squared_delay, GNUNET_TIME_absolute_get(), internal_update(), GNUNET_LOAD_Value::last_update, GNUNET_LOAD_Value::load, and GNUNET_LOAD_Value::runavg_delay.

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

239 {
240  uint32_t dv;
241 
242  internal_update (load);
244  if (data > 64 * 1024)
245  {
246  /* very large */
247  load->load = 100.0;
248  return;
249  }
250  dv = (uint32_t) data;
251  load->cummulative_delay += dv;
252  load->cummulative_squared_delay += dv * dv;
254  load->runavg_delay = ((load->runavg_delay * 7.0) + dv) / 8.0;
255 }
double runavg_delay
Current running average datastore delay.
Definition: load.c:72
double load
How high is the load? 0 for below average, otherwise the number of std.
Definition: load.c:79
uint64_t cummulative_delay
Sum of all datastore delays ever observed (in ms).
Definition: load.c:53
uint64_t cummulative_request_count
Total number of requests included in the cummulative datastore delay values.
Definition: load.c:65
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
static void internal_update(struct GNUNET_LOAD_Value *load)
Definition: load.c:85
struct GNUNET_TIME_Absolute last_update
Last time this load value was updated by an event.
Definition: load.c:46
uint64_t cummulative_squared_delay
Sum of squares of all datastore delays ever observed (in ms).
Definition: load.c:60
uint32_t data
The data value.
Here is the call graph for this function:
Here is the caller graph for this function: