49 lines
2.2 KiB
C
49 lines
2.2 KiB
C
/* Баланс логической очереди DATA: ключи представлены курсорами, содержимое остаётся в кольце.
|
|
* A/D/X — накопительные packets/bytes; Q = A-D-X. D означает принятие ETCP, не доставку.
|
|
* 200-мс интервалы имеют фактическую длительность; история 10с, рост до искусственных удалений — за 1с.
|
|
* Смена состава выдач исключает смешанный интервал из оценки роста и сбрасывает подтверждение перегрузки. */
|
|
#ifndef STREAM_LOAD_H
|
|
#define STREAM_LOAD_H
|
|
|
|
#include "stream_proto.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define STREAM_LOAD_PERIOD_MS 200
|
|
#define STREAM_LOAD_HISTORY 50
|
|
#define STREAM_LOAD_CONFIRM_MS 500
|
|
#define STREAM_LOAD_GRACE_MS 2000
|
|
#define STREAM_LOAD_MAX_AGE_MS 4000
|
|
|
|
struct stream_load_counts { uint64_t packets, bytes; };
|
|
struct stream_load_interval {
|
|
uint64_t begin_ms, end_ms, revision;
|
|
struct stream_load_counts arrivals, sent, removed;
|
|
};
|
|
struct stream_load_snapshot {
|
|
struct stream_load_counts arrivals, sent, removed, queued;
|
|
uint64_t rejected, input_rate, output_rate, growth_rate, oldest_age_ms, interval_ms;
|
|
int valid, pressure, confirmed;
|
|
};
|
|
struct stream_load {
|
|
struct stream_load_interval history[STREAM_LOAD_HISTORY];
|
|
struct stream_load_snapshot snapshot;
|
|
struct stream_load_counts arrivals, sent, removed, queued;
|
|
struct stream_load_counts previous_a, previous_d, previous_x;
|
|
uint64_t rejected, previous_ms, revision, previous_revision, since_ms, last_d;
|
|
unsigned head, count;
|
|
int candidate;
|
|
};
|
|
|
|
void stream_load_init(struct stream_load *load, uint64_t now_ms);
|
|
int stream_load_add(struct stream_load *load, uint64_t packets, uint64_t bytes);
|
|
int stream_load_remove(struct stream_load *load, uint64_t packets, uint64_t bytes, int sent);
|
|
void stream_load_changed(struct stream_load *load);
|
|
int stream_load_poll(struct stream_load *load, uint64_t now_ms, uint64_t oldest_age_ms, struct stream_load_snapshot *snapshot);
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif
|