GNUnet  0.11.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 124 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().

125 {
126  struct GNUNET_LOAD_Value *ret;
127 
128  ret = GNUNET_new (struct GNUNET_LOAD_Value);
129  ret->autodecline = autodecline;
131  return ret;
132 }
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_Relative autodecline
How fast should the load decline if no values are added?
Definition: load.c:40
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:45
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 142 of file load.c.

References GNUNET_LOAD_Value::autodecline, and internal_update().

Referenced by GSF_update_peer_latency_().

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

201 {
202  internal_update (load);
203  calculate_load (load);
204  return load->load;
205 }
double load
How high is the load? 0 for below average, otherwise the number of std.
Definition: load.c:78
static void internal_update(struct GNUNET_LOAD_Value *load)
Definition: load.c:83
static void calculate_load(struct GNUNET_LOAD_Value *load)
Recalculate our load value.
Definition: load.c:156
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 215 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().

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

237 {
238  uint32_t dv;
239 
240  internal_update (load);
242  if (data > 64 * 1024)
243  {
244  /* very large */
245  load->load = 100.0;
246  return;
247  }
248  dv = (uint32_t) data;
249  load->cummulative_delay += dv;
250  load->cummulative_squared_delay += dv * dv;
252  load->runavg_delay = ((load->runavg_delay * 7.0) + dv) / 8.0;
253 }
double runavg_delay
Current running average datastore delay.
Definition: load.c:71
double load
How high is the load? 0 for below average, otherwise the number of std.
Definition: load.c:78
uint64_t cummulative_delay
Sum of all datastore delays ever observed (in ms).
Definition: load.c:52
uint64_t cummulative_request_count
Total number of requests included in the cummulative datastore delay values.
Definition: load.c:64
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:83
struct GNUNET_TIME_Absolute last_update
Last time this load value was updated by an event.
Definition: load.c:45
uint64_t cummulative_squared_delay
Sum of squares of all datastore delays ever observed (in ms).
Definition: load.c:59
uint32_t data
The data value.
Here is the call graph for this function:
Here is the caller graph for this function: