aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-11-20 19:23:08 +0100
committerKim Alvefur <zash@zash.se>2021-11-20 19:23:08 +0100
commit3fb3e862280b90a743ac99ff044535b90ed2f4c0 (patch)
treebb9ef85485f6b82ab0323d6f0aab0aaf1a99a8a4
parent8756adf72bad6edbda41747267e74a8e04332916 (diff)
downloadprosody-3fb3e862280b90a743ac99ff044535b90ed2f4c0.tar.gz
prosody-3fb3e862280b90a743ac99ff044535b90ed2f4c0.zip
mod_csi_simple: Allow some straggler traffic after flushing buffer
Statistics from my server shows a high rate of very short buffer hold times, most of which are the result of replies to pings or other iq traffic, or mod_smacks acks and ack requests just after a flush was completed. This grace period should eliminate noise and quick flipping between flushing and inactive mode.
-rw-r--r--plugins/mod_csi_simple.lua23
1 files changed, 20 insertions, 3 deletions
diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua
index 3fbdf314..a727f427 100644
--- a/plugins/mod_csi_simple.lua
+++ b/plugins/mod_csi_simple.lua
@@ -10,8 +10,10 @@ local jid = require "util.jid";
local st = require "util.stanza";
local dt = require "util.datetime";
local filters = require "util.filters";
+local timer = require "util.timer";
local queue_size = module:get_option_number("csi_queue_size", 256);
+local resume_delay = module:get_option_number("csi_resume_inactive_delay", 5);
local important_payloads = module:get_option_set("csi_important_payloads", { });
@@ -194,15 +196,30 @@ module:hook("pre-resource-unbind", function (event)
disable_optimizations(session);
end, 1);
-module:hook("c2s-ondrain", function (event)
- local session = event.session;
- if (session.state == "flushing" or session.state == "inactive") and session.conn and session.conn.pause_writes then
+local function resume_optimizations(_, _, session)
+ if (session.state == "flushing" or session.state == "inactive") and session.conn and session.conn.pause_writes then
session.state = "inactive";
session.conn:pause_writes();
session.csi_measure_buffer_hold = measure_buffer_hold();
session.log("debug", "Buffer flushed, resuming inactive mode (queue size was %d)", session.csi_counter);
session.csi_counter = 0;
end
+ session.csi_resume = nil;
+end
+
+module:hook("c2s-ondrain", function (event)
+ local session = event.session;
+ if (session.state == "flushing" or session.state == "inactive") and session.conn and session.conn.pause_writes then
+ -- After flushing, remain in pseudo-flushing state for a moment to allow
+ -- some followup traffic, iq replies, smacks acks to be sent without having
+ -- to go back and forth between inactive and flush mode.
+ if not session.csi_resume then
+ session.csi_resume = timer.add_task(resume_delay, resume_optimizations, session);
+ end
+ -- Should further noise in this short grace period push back the delay?
+ -- Probably not great if the session can be kept in pseudo-active mode
+ -- indefinitely.
+ end
end);
function module.load()