feature: periodically remove stale gateway messages (#5312)

* add timestamp to stored client messages

* removed dead code

* starting node task to remove old messages

* added log for number of removed messages

* debug log on task finishing
This commit is contained in:
Jędrzej Stuczyński
2025-01-09 10:03:19 +01:00
committed by GitHub
parent 3d2914b3e5
commit 226c040a13
19 changed files with 199 additions and 477 deletions
+54
View File
@@ -47,6 +47,10 @@ pub struct Debug {
/// Number of messages from offline client that can be pulled at once (i.e. with a single SQL query) from the storage.
pub message_retrieval_limit: i64,
pub stale_messages: StaleMessageDebug,
pub client_bandwidth: ClientBandwidthDebug,
pub zk_nym_tickets: ZkNymTicketHandlerDebug,
}
@@ -58,6 +62,8 @@ impl Default for Debug {
fn default() -> Self {
Debug {
message_retrieval_limit: Self::DEFAULT_MESSAGE_RETRIEVAL_LIMIT,
stale_messages: Default::default(),
client_bandwidth: Default::default(),
zk_nym_tickets: Default::default(),
}
}
@@ -129,6 +135,54 @@ impl Default for ZkNymTicketHandlerDebug {
}
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct ClientBandwidthDebug {
/// Defines maximum delay between client bandwidth information being flushed to the persistent storage.
pub max_flushing_rate: Duration,
/// Defines a maximum change in client bandwidth before it gets flushed to the persistent storage.
pub max_delta_flushing_amount: i64,
}
impl ClientBandwidthDebug {
const DEFAULT_CLIENT_BANDWIDTH_MAX_FLUSHING_RATE: Duration = Duration::from_millis(5);
const DEFAULT_CLIENT_BANDWIDTH_MAX_DELTA_FLUSHING_AMOUNT: i64 = 512 * 1024; // 512kB
}
impl Default for ClientBandwidthDebug {
fn default() -> Self {
ClientBandwidthDebug {
max_flushing_rate: Self::DEFAULT_CLIENT_BANDWIDTH_MAX_FLUSHING_RATE,
max_delta_flushing_amount: Self::DEFAULT_CLIENT_BANDWIDTH_MAX_DELTA_FLUSHING_AMOUNT,
}
}
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct StaleMessageDebug {
/// Specifies how often the clean-up task should check for stale data.
#[serde(with = "humantime_serde")]
pub cleaner_run_interval: Duration,
/// Specifies maximum age of stored messages before they are removed from the storage
#[serde(with = "humantime_serde")]
pub max_age: Duration,
}
impl StaleMessageDebug {
const DEFAULT_STALE_MESSAGES_CLEANER_RUN_INTERVAL: Duration = Duration::from_secs(60 * 60);
const DEFAULT_STALE_MESSAGES_MAX_AGE: Duration = Duration::from_secs(24 * 60 * 60);
}
impl Default for StaleMessageDebug {
fn default() -> Self {
StaleMessageDebug {
cleaner_run_interval: Self::DEFAULT_STALE_MESSAGES_CLEANER_RUN_INTERVAL,
max_age: Self::DEFAULT_STALE_MESSAGES_MAX_AGE,
}
}
}
impl GatewayTasksConfig {
pub fn new_default<P: AsRef<Path>>(data_dir: P) -> Self {
GatewayTasksConfig {
+16 -4
View File
@@ -24,10 +24,22 @@ fn ephemeral_gateway_config(config: &Config) -> nym_gateway::config::Config {
enabled: config.service_providers.network_requester.debug.enabled,
},
nym_gateway::config::Debug {
client_bandwidth_max_flushing_rate:
nym_gateway::config::DEFAULT_CLIENT_BANDWIDTH_MAX_FLUSHING_RATE,
client_bandwidth_max_delta_flushing_amount:
nym_gateway::config::DEFAULT_CLIENT_BANDWIDTH_MAX_DELTA_FLUSHING_AMOUNT,
client_bandwidth_max_flushing_rate: config
.gateway_tasks
.debug
.client_bandwidth
.max_flushing_rate,
client_bandwidth_max_delta_flushing_amount: config
.gateway_tasks
.debug
.client_bandwidth
.max_delta_flushing_amount,
stale_messages_cleaner_run_interval: config
.gateway_tasks
.debug
.stale_messages
.cleaner_run_interval,
stale_messages_max_age: config.gateway_tasks.debug.stale_messages.max_age,
zk_nym_tickets: nym_gateway::config::ZkNymTicketHandlerDebug {
revocation_bandwidth_penalty: config
.gateway_tasks
@@ -1095,6 +1095,7 @@ pub async fn try_upgrade_config_v6<P: AsRef<Path>>(
.zk_nym_tickets
.maximum_time_between_redemption,
},
..Default::default()
},
},
service_providers: ServiceProvidersConfig {
+4
View File
@@ -665,6 +665,10 @@ impl NymNode {
info!("node not running with wireguard: authenticator service provider and wireguard will remain unavailable");
}
// start task for removing stale and un-retrieved client messages
let stale_messages_cleaner = gateway_tasks_builder.build_stale_messages_cleaner();
stale_messages_cleaner.start();
Ok(())
}