From 8e68b0dd1adfcd7932f368a0b00dd2019c95db38 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 24 Nov 2018 02:25:44 +0100 Subject: mod_csi_simple: Use write locks in net.server if available --- plugins/mod_csi_simple.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index da2dd953..abe65fce 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -86,7 +86,9 @@ end, -1); module:hook("csi-client-inactive", function (event) local session = event.origin; - if session.pump then + if session.conn and session.conn and session.conn.pause_writes then + session.conn:pause_writes(); + elseif session.pump then session.pump:pause(); else local bare_jid = jid.join(session.username, session.host); @@ -115,6 +117,8 @@ module:hook("csi-client-active", function (event) local session = event.origin; if session.pump then session.pump:resume(); + elseif session.conn and session.conn and session.conn.resume_writes then + session.conn:resume_writes(); end end); -- cgit v1.2.3 From e5885c928a79604dea999d24cf57104150b55898 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 24 Mar 2019 18:32:50 +0100 Subject: mod_csi_simple: Break out stanza timestamping into a function for future reuse --- plugins/mod_csi_simple.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index abe65fce..6bd6c0bf 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -84,6 +84,14 @@ module:hook("csi-is-stanza-important", function (event) return true; end, -1); +local function with_timestamp(stanza, from) + if st.is_stanza(stanza) and stanza.attr.xmlns == nil and stanza.name ~= "iq" then + stanza = st.clone(stanza); + stanza:add_direct_child(st.stanza("delay", {xmlns = "urn:xmpp:delay", from = from, stamp = dt.datetime()})); + end + return stanza; +end + module:hook("csi-client-inactive", function (event) local session = event.origin; if session.conn and session.conn and session.conn.pause_writes then @@ -102,11 +110,7 @@ module:hook("csi-client-inactive", function (event) pump:flush(); send(stanza); else - if st.is_stanza(stanza) and stanza.attr.xmlns == nil and stanza.name ~= "iq" then - stanza = st.clone(stanza); - stanza:add_direct_child(st.stanza("delay", {xmlns = "urn:xmpp:delay", from = bare_jid, stamp = dt.datetime()})); - end - pump:push(stanza); + pump:push(with_timestamp(stanza, bare_jid)); end return true; end -- cgit v1.2.3 From 643c317b1627da95e839bab0e397d89ab6f6a589 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 24 Mar 2019 18:33:38 +0100 Subject: mod_csi_simple: Count buffered items and flush when it reaches configured limit In this mode, stanzas have been serialized to strings in the internal net.server buffer, so it is difficult to count them after the fact. --- plugins/mod_csi_simple.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 6bd6c0bf..5c829179 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -10,6 +10,7 @@ local jid = require "util.jid"; local st = require "util.stanza"; local dt = require "util.datetime"; local new_queue = require "util.queue".new; +local filters = require "util.filters"; local function new_pump(output, ...) -- luacheck: ignore 212/self @@ -92,10 +93,22 @@ local function with_timestamp(stanza, from) return stanza; end +local function manage_buffer(stanza, session) + local ctr = session.csi_counter or 0; + if ctr >= queue_size or module:fire_event("csi-is-stanza-important", { stanza = stanza, session = session }) then + session.conn:resume_writes(); + else + stanza = with_timestamp(stanza, jid.join(session.username, session.host)) + end + session.csi_counter = ctr + 1; + return stanza; +end + module:hook("csi-client-inactive", function (event) local session = event.origin; if session.conn and session.conn and session.conn.pause_writes then session.conn:pause_writes(); + filters.add_filter(session, "stanzas/out", manage_buffer); elseif session.pump then session.pump:pause(); else @@ -122,7 +135,16 @@ module:hook("csi-client-active", function (event) if session.pump then session.pump:resume(); elseif session.conn and session.conn and session.conn.resume_writes then + filters.remove_filter(session, "stanzas/out", manage_buffer); session.conn:resume_writes(); end end); + +module:hook("c2s-ondrain", function (event) + local session = event.session; + if session.state == "inactive" and session.conn and session.conn and session.conn.pause_writes then + session.csi_counter = 0; + session.conn:pause_writes(); + end +end); -- cgit v1.2.3 From 141c5d3fbe257cf63249eeec528dd36b3266b25e Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 24 Mar 2019 18:58:53 +0100 Subject: mod_csi_simple: Trigger buffer flush on seeing incoming data I.e. the client sent us something, which means its network / radio is active. --- plugins/mod_csi_simple.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 5c829179..07a8cfb3 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -104,11 +104,17 @@ local function manage_buffer(stanza, session) return stanza; end +local function flush_buffer(data, session) + session.conn:resume_writes(); + return data; +end + module:hook("csi-client-inactive", function (event) local session = event.origin; if session.conn and session.conn and session.conn.pause_writes then session.conn:pause_writes(); filters.add_filter(session, "stanzas/out", manage_buffer); + filters.add_filter(session, "bytes/in", flush_buffer); elseif session.pump then session.pump:pause(); else @@ -136,6 +142,7 @@ module:hook("csi-client-active", function (event) session.pump:resume(); elseif session.conn and session.conn and session.conn.resume_writes then filters.remove_filter(session, "stanzas/out", manage_buffer); + filters.remove_filter(session, "bytes/in", flush_buffer); session.conn:resume_writes(); end end); -- cgit v1.2.3 From 3a1498ebd335a15a987e3087f84089620b5507c5 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 24 Mar 2019 19:02:40 +0100 Subject: mod_csi_simple: Also flush buffer in "pump" mode --- plugins/mod_csi_simple.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 07a8cfb3..ee7e01c9 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -109,9 +109,15 @@ local function flush_buffer(data, session) return data; end +local function flush_pump(data, session) + session.pump:flush(); + return data; +end + module:hook("csi-client-inactive", function (event) local session = event.origin; if session.conn and session.conn and session.conn.pause_writes then + session.log("info", "Native net.server buffer management mode"); session.conn:pause_writes(); filters.add_filter(session, "stanzas/out", manage_buffer); filters.add_filter(session, "bytes/in", flush_buffer); @@ -124,6 +130,7 @@ module:hook("csi-client-inactive", function (event) local pump = new_pump(session.send, queue_size); pump:pause(); session.pump = pump; + filters.add_filter(session, "bytes/in", flush_pump); function session.send(stanza) if session.state == "active" or module:fire_event("csi-is-stanza-important", { stanza = stanza, session = session }) then pump:flush(); -- cgit v1.2.3 From 6c89a86e0df62c51e0fb12596d3999324245c9fe Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 24 Mar 2019 20:22:01 +0100 Subject: mod_csi_simple: Remove old "pump" queue/buffer method, handled in net.server now --- plugins/mod_csi_simple.lua | 63 ++-------------------------------------------- 1 file changed, 2 insertions(+), 61 deletions(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index ee7e01c9..0fa0d083 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -9,42 +9,8 @@ module:depends"csi" local jid = require "util.jid"; local st = require "util.stanza"; local dt = require "util.datetime"; -local new_queue = require "util.queue".new; local filters = require "util.filters"; -local function new_pump(output, ...) - -- luacheck: ignore 212/self - local q = new_queue(...); - local flush = true; - function q:pause() - flush = false; - end - function q:resume() - flush = true; - return q:flush(); - end - local push = q.push; - function q:push(item) - local ok = push(self, item); - if not ok then - q:flush(); - output(item, self); - elseif flush then - return q:flush(); - end - return true; - end - function q:flush() - local item = self:pop(); - while item do - output(item, self); - item = self:pop(); - end - return true; - end - return q; -end - local queue_size = module:get_option_number("csi_queue_size", 256); module:hook("csi-is-stanza-important", function (event) @@ -109,45 +75,20 @@ local function flush_buffer(data, session) return data; end -local function flush_pump(data, session) - session.pump:flush(); - return data; -end - module:hook("csi-client-inactive", function (event) local session = event.origin; if session.conn and session.conn and session.conn.pause_writes then - session.log("info", "Native net.server buffer management mode"); session.conn:pause_writes(); filters.add_filter(session, "stanzas/out", manage_buffer); filters.add_filter(session, "bytes/in", flush_buffer); - elseif session.pump then - session.pump:pause(); else - local bare_jid = jid.join(session.username, session.host); - local send = session.send; - session._orig_send = send; - local pump = new_pump(session.send, queue_size); - pump:pause(); - session.pump = pump; - filters.add_filter(session, "bytes/in", flush_pump); - function session.send(stanza) - if session.state == "active" or module:fire_event("csi-is-stanza-important", { stanza = stanza, session = session }) then - pump:flush(); - send(stanza); - else - pump:push(with_timestamp(stanza, bare_jid)); - end - return true; - end + session.log("warn", "Session connection does not support write pausing"); end end); module:hook("csi-client-active", function (event) local session = event.origin; - if session.pump then - session.pump:resume(); - elseif session.conn and session.conn and session.conn.resume_writes then + if session.conn and session.conn and session.conn.resume_writes then filters.remove_filter(session, "stanzas/out", manage_buffer); filters.remove_filter(session, "bytes/in", flush_buffer); session.conn:resume_writes(); -- cgit v1.2.3 From 1e77bb6ed2ac00b1e5f64f39da41ec140fe425ce Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 24 Mar 2019 20:41:25 +0100 Subject: mod_csi_simple: Separate out functions to enable/disable optimizations This allows reusing this logic outside the events. Letting the functions be module globals makes it easier to access from eg the telnet console. --- plugins/mod_csi_simple.lua | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 0fa0d083..14abbc68 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -75,8 +75,7 @@ local function flush_buffer(data, session) return data; end -module:hook("csi-client-inactive", function (event) - local session = event.origin; +function enable_optimizations(session) if session.conn and session.conn and session.conn.pause_writes then session.conn:pause_writes(); filters.add_filter(session, "stanzas/out", manage_buffer); @@ -84,15 +83,24 @@ module:hook("csi-client-inactive", function (event) else session.log("warn", "Session connection does not support write pausing"); end -end); +end -module:hook("csi-client-active", function (event) - local session = event.origin; +function disble_optimizations(session) if session.conn and session.conn and session.conn.resume_writes then filters.remove_filter(session, "stanzas/out", manage_buffer); filters.remove_filter(session, "bytes/in", flush_buffer); session.conn:resume_writes(); end +end + +module:hook("csi-client-inactive", function (event) + local session = event.origin; + enable_optimizations(session); +end); + +module:hook("csi-client-active", function (event) + local session = event.origin; + disble_optimizations(session); end); -- cgit v1.2.3 From e887ed5cad52d2853ba66dfe1a7ec0762f4624df Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 24 Mar 2019 20:43:15 +0100 Subject: mod_csi_simple: Disable optimizations on unload and re-enable on load --- plugins/mod_csi_simple.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 14abbc68..d0de222e 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -111,3 +111,24 @@ module:hook("c2s-ondrain", function (event) session.conn:pause_writes(); end end); + +function module.load() + for _, user_session in pairs(prosody.hosts[module.host].sessions) do + for _, session in pairs(user_session.sessions) do + if session.state == "inactive" then + enable_optimizations(session); + end + end + end +end + +function module.unload() + for _, user_session in pairs(prosody.hosts[module.host].sessions) do + for _, session in pairs(user_session.sessions) do + if session.state == "inactive" then + disble_optimizations(session); + end + end + end +end + -- cgit v1.2.3 From 684a26f5be5a29e4d8eb82af0f9b2d9a87f98267 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 24 Mar 2019 20:53:49 +0100 Subject: mod_csi_simple: Add some debug logging --- plugins/mod_csi_simple.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index d0de222e..ff1fa86c 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -71,6 +71,7 @@ local function manage_buffer(stanza, session) end local function flush_buffer(data, session) + session.log("debug", "Client sent something, flushing buffer once"); session.conn:resume_writes(); return data; end @@ -109,6 +110,7 @@ module:hook("c2s-ondrain", function (event) if session.state == "inactive" and session.conn and session.conn and session.conn.pause_writes then session.csi_counter = 0; session.conn:pause_writes(); + session.log("debug", "Buffer flushed, resuming inactive mode"); end end); -- cgit v1.2.3 From ba9e50592452854fe03cc12b1c376c17b8091c80 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 24 Mar 2019 22:01:36 +0100 Subject: mod_csi_simple: Improve debug logs by mentioing why the buffer gets flushed --- plugins/mod_csi_simple.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index ff1fa86c..2dda1c42 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -61,7 +61,11 @@ end local function manage_buffer(stanza, session) local ctr = session.csi_counter or 0; - if ctr >= queue_size or module:fire_event("csi-is-stanza-important", { stanza = stanza, session = session }) then + if ctr >= queue_size then + session.log("debug", "Queue size limit hit, flushing buffer"); + session.conn:resume_writes(); + elseif module:fire_event("csi-is-stanza-important", { stanza = stanza, session = session }) then + session.log("debug", "Important stanza, flushing buffer"); session.conn:resume_writes(); else stanza = with_timestamp(stanza, jid.join(session.username, session.host)) -- cgit v1.2.3 From 5074566d79830e5a6ecba2b13fd9cdad2e1fb902 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 25 Mar 2019 10:32:39 +0000 Subject: mod_csi_simple: Fix type in function name --- plugins/mod_csi_simple.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 2dda1c42..c79c56fc 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -90,7 +90,7 @@ function enable_optimizations(session) end end -function disble_optimizations(session) +function disable_optimizations(session) if session.conn and session.conn and session.conn.resume_writes then filters.remove_filter(session, "stanzas/out", manage_buffer); filters.remove_filter(session, "bytes/in", flush_buffer); @@ -105,7 +105,7 @@ end); module:hook("csi-client-active", function (event) local session = event.origin; - disble_optimizations(session); + disable_optimizations(session); end); @@ -132,9 +132,8 @@ function module.unload() for _, user_session in pairs(prosody.hosts[module.host].sessions) do for _, session in pairs(user_session.sessions) do if session.state == "inactive" then - disble_optimizations(session); + disable_optimizations(session); end end end end - -- cgit v1.2.3 From 096ebc3bcfde419b5c9c387f08d9c41c4d65b847 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 25 Mar 2019 15:20:28 +0100 Subject: mod_csi_simple: Include queue size in debug messages --- plugins/mod_csi_simple.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index c79c56fc..a9148618 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -62,10 +62,10 @@ end local function manage_buffer(stanza, session) local ctr = session.csi_counter or 0; if ctr >= queue_size then - session.log("debug", "Queue size limit hit, flushing buffer"); + session.log("debug", "Queue size limit hit, flushing buffer (queue size is %d)", session.csi_counter); session.conn:resume_writes(); elseif module:fire_event("csi-is-stanza-important", { stanza = stanza, session = session }) then - session.log("debug", "Important stanza, flushing buffer"); + session.log("debug", "Important stanza, flushing buffer (queue size is %d)", session.csi_counter); session.conn:resume_writes(); else stanza = with_timestamp(stanza, jid.join(session.username, session.host)) @@ -75,7 +75,7 @@ local function manage_buffer(stanza, session) end local function flush_buffer(data, session) - session.log("debug", "Client sent something, flushing buffer once"); + session.log("debug", "Client sent something, flushing buffer once (queue size is %d)", session.csi_counter); session.conn:resume_writes(); return data; end @@ -112,9 +112,9 @@ end); module:hook("c2s-ondrain", function (event) local session = event.session; if session.state == "inactive" and session.conn and session.conn and session.conn.pause_writes then - session.csi_counter = 0; session.conn:pause_writes(); - session.log("debug", "Buffer flushed, resuming inactive mode"); + session.log("debug", "Buffer flushed, resuming inactive mode (queue size was %d)", session.csi_counter); + session.csi_counter = 0; end end); -- cgit v1.2.3 From 6fcaa64f6139a5093a328b2458ea4ac74a153d51 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 26 May 2019 15:04:16 +0200 Subject: mod_csi_simple: Disable optimizations on disconnect (fixes #1358) The connection becomes invalid here, regardless of 3rd party modules that might keep the session alive. --- plugins/mod_csi_simple.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index a9148618..13002ea8 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -108,6 +108,10 @@ module:hook("csi-client-active", function (event) disable_optimizations(session); end); +module:hook("pre-resource-unbind", function (event) + local session = event.session; + disable_optimizations(session); +end); module:hook("c2s-ondrain", function (event) local session = event.session; -- cgit v1.2.3 From fad52c768601de198e5c277d547528bfac1f6166 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 28 Sep 2019 22:59:29 +0200 Subject: mod_csi_simple: Remove duplicated check for connection --- plugins/mod_csi_simple.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 13002ea8..4e2b95e1 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -81,7 +81,7 @@ local function flush_buffer(data, session) end function enable_optimizations(session) - if session.conn and session.conn and session.conn.pause_writes then + if session.conn and session.conn.pause_writes then session.conn:pause_writes(); filters.add_filter(session, "stanzas/out", manage_buffer); filters.add_filter(session, "bytes/in", flush_buffer); @@ -91,7 +91,7 @@ function enable_optimizations(session) end function disable_optimizations(session) - if session.conn and session.conn and session.conn.resume_writes then + if session.conn and session.conn.resume_writes then filters.remove_filter(session, "stanzas/out", manage_buffer); filters.remove_filter(session, "bytes/in", flush_buffer); session.conn:resume_writes(); @@ -115,7 +115,7 @@ end); module:hook("c2s-ondrain", function (event) local session = event.session; - if session.state == "inactive" and session.conn and session.conn and session.conn.pause_writes then + if session.state == "inactive" and session.conn and session.conn.pause_writes then session.conn:pause_writes(); session.log("debug", "Buffer flushed, resuming inactive mode (queue size was %d)", session.csi_counter); session.csi_counter = 0; -- cgit v1.2.3 From 1356b90c3a135009a5b6ba5c56b2f4a407f7fc3a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 5 Oct 2019 16:50:41 +0200 Subject: mod_csi_simple: Try not to flush buffer while already flushing it Reduces log noice --- plugins/mod_csi_simple.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 4e2b95e1..b99aaab3 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -75,6 +75,10 @@ local function manage_buffer(stanza, session) end local function flush_buffer(data, session) + if session.csi_flushing then + return data; + end + session.csi_flushing = true; session.log("debug", "Client sent something, flushing buffer once (queue size is %d)", session.csi_counter); session.conn:resume_writes(); return data; @@ -92,6 +96,7 @@ end function disable_optimizations(session) if session.conn and session.conn.resume_writes then + session.csi_flushing = nil; filters.remove_filter(session, "stanzas/out", manage_buffer); filters.remove_filter(session, "bytes/in", flush_buffer); session.conn:resume_writes(); -- cgit v1.2.3 From 2e1a43906f35d4feaa7398eb1f4848fcdda3bd5c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 5 Oct 2019 16:55:58 +0200 Subject: mod_csi_simple: Always remove session filters when disabling CSI Only guard the actual pausing of outgoing data on the method existing. This prevents the filters from lingering in case something happened to the connection. Removing already removed filters should be a safe noop. --- plugins/mod_csi_simple.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index b99aaab3..24a2f1ce 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -95,10 +95,10 @@ function enable_optimizations(session) end function disable_optimizations(session) + session.csi_flushing = nil; + filters.remove_filter(session, "stanzas/out", manage_buffer); + filters.remove_filter(session, "bytes/in", flush_buffer); if session.conn and session.conn.resume_writes then - session.csi_flushing = nil; - filters.remove_filter(session, "stanzas/out", manage_buffer); - filters.remove_filter(session, "bytes/in", flush_buffer); session.conn:resume_writes(); end end -- cgit v1.2.3 From 2a7715e94b907989fcd58e4b86980c5ae4cbf7b1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 17 Nov 2019 17:59:56 +0100 Subject: mod_csi_simple: Make sure to disable optimizations before mod_smacks (thanks pep.) --- plugins/mod_csi_simple.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 24a2f1ce..4a87f06c 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -116,7 +116,7 @@ end); module:hook("pre-resource-unbind", function (event) local session = event.session; disable_optimizations(session); -end); +end, 1); module:hook("c2s-ondrain", function (event) local session = event.session; -- cgit v1.2.3 From 4b33a7aac8b77777c3a59e94b2f82d365e421877 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 18 Apr 2020 16:18:41 +0200 Subject: mod_csi_simple: Allow configuring extra tags indicating importance --- plugins/mod_csi_simple.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 4a87f06c..e439bf38 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -1,4 +1,4 @@ --- Copyright (C) 2016-2018 Kim Alvefur +-- Copyright (C) 2016-2020 Kim Alvefur -- -- This project is MIT/X11 licensed. Please see the -- COPYING file in the source package for more information. @@ -13,6 +13,8 @@ local filters = require "util.filters"; local queue_size = module:get_option_number("csi_queue_size", 256); +local important_payloads = module:get_option_set("csi_important_payloads", { }); + module:hook("csi-is-stanza-important", function (event) local stanza = event.stanza; if not st.is_stanza(stanza) then @@ -46,6 +48,11 @@ module:hook("csi-is-stanza-important", function (event) if stanza:get_child("encryption", "urn:xmpp:eme:0") then return true; end + for important in important_payloads do + if stanza:find(important) then + return true; + end + end return false; end return true; -- cgit v1.2.3 From 8f77033238b4cf72377ae0b45d5951c32324892d Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 18 Apr 2020 19:36:26 +0200 Subject: mod_csi_simple: Consider MUC invites important Both mediated invites defined by XEP-0045: Multi-User Chat and direct invites defined by XEP-0249: Direct MUC Invitations --- plugins/mod_csi_simple.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index e439bf38..cc15f033 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -48,6 +48,9 @@ module:hook("csi-is-stanza-important", function (event) if stanza:get_child("encryption", "urn:xmpp:eme:0") then return true; end + if stanza:get_child("x", "jabber:x:conference") or stanza:find("{http://jabber.org/protocol/muc#user}x/invite") then + return true; + end for important in important_payloads do if stanza:find(important) then return true; -- cgit v1.2.3 From fc3bee71fdc30f8bc253d226124656582189ffa8 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 26 Apr 2020 10:58:22 +0200 Subject: mod_csi_simple: Explicitly consider errors important This was already the case for presence and iq stanzas but not messages. --- plugins/mod_csi_simple.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index cc15f033..df7ce045 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -23,6 +23,9 @@ module:hook("csi-is-stanza-important", function (event) local st_name = stanza.name; if not st_name then return false; end local st_type = stanza.attr.type; + if st_type == "error" then + return true; + end if st_name == "presence" then if st_type == nil or st_type == "unavailable" then return false; -- cgit v1.2.3 From ea91b4cc7bdc77c297fdd7c0d4b0eb9c8bbfd276 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 26 Apr 2020 11:13:01 +0200 Subject: mod_csi_simple: Consider nonzas important This case was previously handled by fall-trough at the end of the function. --- plugins/mod_csi_simple.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index df7ce045..e509bef8 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -20,6 +20,10 @@ module:hook("csi-is-stanza-important", function (event) if not st.is_stanza(stanza) then return true; end + if stanza.attr.xmlns ~= nil then + -- stream errors, stream management etc + return true; + end local st_name = stanza.name; if not st_name then return false; end local st_type = stanza.attr.type; -- cgit v1.2.3 From 37a42fa6052f1b55cae4728a71f1bfbdf7743630 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 26 Apr 2020 11:13:25 +0200 Subject: mod_csi_simple: Clarify what might not be stanzas here --- plugins/mod_csi_simple.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index e509bef8..bfbcd029 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -18,6 +18,7 @@ local important_payloads = module:get_option_set("csi_important_payloads", { }); module:hook("csi-is-stanza-important", function (event) local stanza = event.stanza; if not st.is_stanza(stanza) then + -- whitespace pings etc return true; end if stanza.attr.xmlns ~= nil then -- cgit v1.2.3 From 0085d410b206f1899a2841064a798eac2161d764 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 26 Apr 2020 11:40:48 +0200 Subject: mod_csi_simple: Explicitly mention iq stanzas Should be more obvious that all iq stanzas are considered important. Changes behavior for invalid things in the default namespace. --- plugins/mod_csi_simple.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index bfbcd029..d3bf3a9f 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -65,8 +65,9 @@ module:hook("csi-is-stanza-important", function (event) end end return false; + elseif st_name == "iq" then + return true; end - return true; end, -1); local function with_timestamp(stanza, from) -- cgit v1.2.3 From 9339ebb8e37a72fae02bd5d928f7ce22beff1a80 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 5 May 2020 23:08:47 +0200 Subject: mod_csi_simple: Don't consider presence errors as important A large share of `` appears to be noise from large public channels and failed presence probes. The later at least should count as presence updates, which are currently considered unimportant. See also 8cecb85e4bc4 which is partly reverted here. The intent there was probably mostly about message (delivery) errors, which should be considered important. --- plugins/mod_csi_simple.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index d3bf3a9f..05650957 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -28,18 +28,19 @@ module:hook("csi-is-stanza-important", function (event) local st_name = stanza.name; if not st_name then return false; end local st_type = stanza.attr.type; - if st_type == "error" then - return true; - end if st_name == "presence" then - if st_type == nil or st_type == "unavailable" then + if st_type == nil or st_type == "unavailable" or st_name == "error" then return false; end + -- TODO Some MUC awareness, e.g. check for the 'this relates to you' status code return true; elseif st_name == "message" then if st_type == "headline" then return false; end + if st_type == "error" then + return true; + end if stanza:get_child("sent", "urn:xmpp:carbons:2") then return true; end -- cgit v1.2.3 From 44847d620cf0b7f690682e4906dfcbea8cd3ef03 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 7 May 2020 21:55:29 +0200 Subject: mod_csi_simple: Refactor to allow logging reason for buffer flush Same style as mod_mam and mod_carbons allows easy comparison. BC: Log format changes --- plugins/mod_csi_simple.lua | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 05650957..7b8b3741 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -15,8 +15,7 @@ local queue_size = module:get_option_number("csi_queue_size", 256); local important_payloads = module:get_option_set("csi_important_payloads", { }); -module:hook("csi-is-stanza-important", function (event) - local stanza = event.stanza; +function is_important(stanza) --> boolean, reason: string if not st.is_stanza(stanza) then -- whitespace pings etc return true; @@ -69,8 +68,23 @@ module:hook("csi-is-stanza-important", function (event) elseif st_name == "iq" then return true; end +end + +module:hook("csi-is-stanza-important", function (event) + local important, why = is_important(event.stanza); + event.reason = why; + return important; end, -1); +local function should_flush(stanza, session, ctr) --> boolean, reason: string + if ctr >= queue_size then + return true, "queue size limit reached"; + end + local event = { stanza = stanza, session = session }; + local ret = module:fire_event("csi-is-stanza-important", event) + return ret, event.reason; +end + local function with_timestamp(stanza, from) if st.is_stanza(stanza) and stanza.attr.xmlns == nil and stanza.name ~= "iq" then stanza = st.clone(stanza); @@ -81,11 +95,9 @@ end local function manage_buffer(stanza, session) local ctr = session.csi_counter or 0; - if ctr >= queue_size then - session.log("debug", "Queue size limit hit, flushing buffer (queue size is %d)", session.csi_counter); - session.conn:resume_writes(); - elseif module:fire_event("csi-is-stanza-important", { stanza = stanza, session = session }) then - session.log("debug", "Important stanza, flushing buffer (queue size is %d)", session.csi_counter); + local flush, why = should_flush(stanza, session, ctr); + if flush then + session.log("debug", "Flushing buffer (%s; queue size is %d)", why or "important", session.csi_counter); session.conn:resume_writes(); else stanza = with_timestamp(stanza, jid.join(session.username, session.host)) -- cgit v1.2.3 From a9ba50343ca6fc47d8bf50b0714ca943f38b1410 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 7 May 2020 22:56:30 +0200 Subject: mod_csi_simple: Add short reasons to report Should improve quality of debug logs --- plugins/mod_csi_simple.lua | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 7b8b3741..6274dcb3 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -22,42 +22,46 @@ function is_important(stanza) --> boolean, reason: string end if stanza.attr.xmlns ~= nil then -- stream errors, stream management etc - return true; + return true, "nonza"; end local st_name = stanza.name; if not st_name then return false; end local st_type = stanza.attr.type; if st_name == "presence" then if st_type == nil or st_type == "unavailable" or st_name == "error" then - return false; + return false, "presence update"; end -- TODO Some MUC awareness, e.g. check for the 'this relates to you' status code - return true; + return true, "subscription request"; elseif st_name == "message" then if st_type == "headline" then - return false; + -- Headline messages are ephemeral by definition + return false, "headline"; end if st_type == "error" then - return true; + return true, "delivery failure"; end if stanza:get_child("sent", "urn:xmpp:carbons:2") then - return true; + return true, "carbon"; end local forwarded = stanza:find("{urn:xmpp:carbons:2}received/{urn:xmpp:forward:0}/{jabber:client}message"); if forwarded then stanza = forwarded; end if stanza:get_child("body") then - return true; + return true, "body"; end if stanza:get_child("subject") then - return true; + -- Last step of a MUC join + return true, "subject"; end if stanza:get_child("encryption", "urn:xmpp:eme:0") then - return true; + -- Since we can't know what an encrypted message contains, we assume it's important + -- XXX Experimental XEP + return true, "encrypted"; end if stanza:get_child("x", "jabber:x:conference") or stanza:find("{http://jabber.org/protocol/muc#user}x/invite") then - return true; + return true, "invite"; end for important in important_payloads do if stanza:find(important) then -- cgit v1.2.3 From b2baba11247243446e60bea10884d2d2193e9f48 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 7 May 2020 23:02:47 +0200 Subject: mod_csi_simple: Log reasons for not flushing --- plugins/mod_csi_simple.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 6274dcb3..bb8f757a 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -104,6 +104,7 @@ local function manage_buffer(stanza, session) session.log("debug", "Flushing buffer (%s; queue size is %d)", why or "important", session.csi_counter); session.conn:resume_writes(); else + session.log("debug", "Holding buffer (%s; queue size is %d)", why or "unimportant", session.csi_counter); stanza = with_timestamp(stanza, jid.join(session.username, session.host)) end session.csi_counter = ctr + 1; -- cgit v1.2.3 From fc8a50cd73d43df270a88710d26fec550e33752e Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 May 2020 01:01:01 +0200 Subject: mod_csi_simple: Fix unintentional order of rules from merge --- plugins/mod_csi_simple.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 3bad872d..a62b7841 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -63,14 +63,14 @@ function is_important(stanza) --> boolean, reason: string if stanza:get_child("x", "jabber:x:conference") or stanza:find("{http://jabber.org/protocol/muc#user}x/invite") then return true, "invite"; end + if stanza:get_child(nil, "urn:xmpp:jingle-message:0") then + return true, "jingle call"; + end for important in important_payloads do if stanza:find(important) then return true; end end - if stanza:get_child(nil, "urn:xmpp:jingle-message:0") then - return true; - end return false; elseif st_name == "iq" then return true; -- cgit v1.2.3 From ade3caf1ad39b977ea3233238ba86a1f8635a334 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 May 2020 01:01:03 +0200 Subject: mod_csi_simple: Add comment highlighting that XEP-0353 is experimental To make it easier to find implemented Experimental XEPs later. Also at the time of this commit it has been Proposed as mentinoed in the comment but hopefully that will be resolved soon. --- plugins/mod_csi_simple.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index a62b7841..2c3b3042 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -64,6 +64,7 @@ function is_important(stanza) --> boolean, reason: string return true, "invite"; end if stanza:get_child(nil, "urn:xmpp:jingle-message:0") then + -- XXX Experimental XEP stuck in Proposed for almost a year at the time of this comment return true, "jingle call"; end for important in important_payloads do -- cgit v1.2.3 From 749ed917c1c1a5d34ffb92b0da4cf1cc3f22cf50 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 May 2020 13:33:26 +0200 Subject: mod_csi_simple: Fix treating presence errors as presence updates Autocomplete fail probably. --- plugins/mod_csi_simple.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 2c3b3042..8c6f75c8 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -28,7 +28,7 @@ function is_important(stanza) --> boolean, reason: string if not st_name then return false; end local st_type = stanza.attr.type; if st_name == "presence" then - if st_type == nil or st_type == "unavailable" or st_name == "error" then + if st_type == nil or st_type == "unavailable" or st_type == "error" then return false, "presence update"; end -- TODO Some MUC awareness, e.g. check for the 'this relates to you' status code -- cgit v1.2.3 From cabd89913a6d1101defb663f964116c6ec9ba37b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 May 2020 13:50:58 +0200 Subject: mod_csi_simple: Fix flushing when client sent something Forgot to unset the flag afterwards, so it would only work once. The flag is not even needed, it works as intended without it. --- plugins/mod_csi_simple.lua | 5 ----- 1 file changed, 5 deletions(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 8c6f75c8..a44237d1 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -116,10 +116,6 @@ local function manage_buffer(stanza, session) end local function flush_buffer(data, session) - if session.csi_flushing then - return data; - end - session.csi_flushing = true; session.log("debug", "Client sent something, flushing buffer once (queue size is %d)", session.csi_counter); session.conn:resume_writes(); return data; @@ -136,7 +132,6 @@ function enable_optimizations(session) end function disable_optimizations(session) - session.csi_flushing = nil; filters.remove_filter(session, "stanzas/out", manage_buffer); filters.remove_filter(session, "bytes/in", flush_buffer); if session.conn and session.conn.resume_writes then -- cgit v1.2.3 From 859c3650e5ad8a3fd101154a5f435ca2589ca4d6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 May 2020 17:05:46 +0200 Subject: mod_csi_simple: Forget queue counter when disabling optimizations Otherwise it might not start from zero when enabled again. --- plugins/mod_csi_simple.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index a44237d1..fb3d80c5 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -134,6 +134,7 @@ end function disable_optimizations(session) filters.remove_filter(session, "stanzas/out", manage_buffer); filters.remove_filter(session, "bytes/in", flush_buffer); + session.csi_counter = nil; if session.conn and session.conn.resume_writes then session.conn:resume_writes(); end -- cgit v1.2.3 From e1a3982654d6f10ebaa4b6efda5bf72d55c40413 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 May 2020 17:07:43 +0200 Subject: mod_csi_simple: Reset queue counter to zero when enabling For symmetry. --- plugins/mod_csi_simple.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index fb3d80c5..a4ce258b 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -124,6 +124,7 @@ end function enable_optimizations(session) if session.conn and session.conn.pause_writes then session.conn:pause_writes(); + session.csi_counter = 0; filters.add_filter(session, "stanzas/out", manage_buffer); filters.add_filter(session, "bytes/in", flush_buffer); else -- cgit v1.2.3 From 4053cca7dc5b7356cbf53a0ee4e42420000cef35 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 May 2020 17:38:13 +0200 Subject: mod_csi_simple: Change debug message of client-triggered flush for coherence It now matches other the other source of flush reason logging. --- plugins/mod_csi_simple.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index a4ce258b..0678b5d4 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -116,7 +116,7 @@ local function manage_buffer(stanza, session) end local function flush_buffer(data, session) - session.log("debug", "Client sent something, flushing buffer once (queue size is %d)", session.csi_counter); + session.log("debug", "Flushing buffer (%s; queue size is %d)", "client activity", session.csi_counter); session.conn:resume_writes(); return data; end -- cgit v1.2.3 From edd59660621f044d6402966a4a77ca9867d1f619 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 May 2020 17:45:45 +0200 Subject: mod_csi_simple: Record stats of how long buffers are held Telnet command `stats:show("buffer_hold"):histogram()` looks nice! --- plugins/mod_csi_simple.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 0678b5d4..c0871c8d 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -101,10 +101,16 @@ local function with_timestamp(stanza, from) return stanza; end +local measure_buffer_hold = module:measure("buffer_hold", "times"); + local function manage_buffer(stanza, session) local ctr = session.csi_counter or 0; local flush, why = should_flush(stanza, session, ctr); if flush then + if session.csi_measure_buffer_hold then + session.csi_measure_buffer_hold(); + session.csi_measure_buffer_hold = nil; + end session.log("debug", "Flushing buffer (%s; queue size is %d)", why or "important", session.csi_counter); session.conn:resume_writes(); else @@ -117,6 +123,10 @@ end local function flush_buffer(data, session) session.log("debug", "Flushing buffer (%s; queue size is %d)", "client activity", session.csi_counter); + if session.csi_measure_buffer_hold then + session.csi_measure_buffer_hold(); + session.csi_measure_buffer_hold = nil; + end session.conn:resume_writes(); return data; end @@ -124,6 +134,7 @@ end function enable_optimizations(session) if session.conn and session.conn.pause_writes then session.conn:pause_writes(); + session.csi_measure_buffer_hold = measure_buffer_hold(); session.csi_counter = 0; filters.add_filter(session, "stanzas/out", manage_buffer); filters.add_filter(session, "bytes/in", flush_buffer); @@ -136,6 +147,10 @@ function disable_optimizations(session) filters.remove_filter(session, "stanzas/out", manage_buffer); filters.remove_filter(session, "bytes/in", flush_buffer); session.csi_counter = nil; + if session.csi_measure_buffer_hold then + session.csi_measure_buffer_hold(); + session.csi_measure_buffer_hold = nil; + end if session.conn and session.conn.resume_writes then session.conn:resume_writes(); end @@ -160,6 +175,7 @@ module:hook("c2s-ondrain", function (event) local session = event.session; if session.state == "inactive" and session.conn and session.conn.pause_writes then 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 -- cgit v1.2.3 From d4c1384269b98e3a0e21b4cf3615a6d116100fd6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 May 2020 17:47:03 +0200 Subject: mod_csi_simple: Collect stats on flush reasons --- plugins/mod_csi_simple.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index c0871c8d..0c428c4a 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -103,6 +103,15 @@ end local measure_buffer_hold = module:measure("buffer_hold", "times"); +local flush_reasons = setmetatable({}, { + __index = function (t, reason) + local m = module:measure("flush_reason."..reason:gsub("%W", "_"), "rate"); + t[reason] = m; + return m; + end; + }); + + local function manage_buffer(stanza, session) local ctr = session.csi_counter or 0; local flush, why = should_flush(stanza, session, ctr); @@ -111,6 +120,7 @@ local function manage_buffer(stanza, session) session.csi_measure_buffer_hold(); session.csi_measure_buffer_hold = nil; end + flush_reasons[why or "important"](); session.log("debug", "Flushing buffer (%s; queue size is %d)", why or "important", session.csi_counter); session.conn:resume_writes(); else @@ -123,6 +133,7 @@ end local function flush_buffer(data, session) session.log("debug", "Flushing buffer (%s; queue size is %d)", "client activity", session.csi_counter); + flush_reasons["client activity"](); if session.csi_measure_buffer_hold then session.csi_measure_buffer_hold(); session.csi_measure_buffer_hold = nil; -- cgit v1.2.3 From 9b7ab06ef37d1271d76f2ef9cba6b8f72af199ce Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 10 May 2020 23:06:21 +0200 Subject: mod_csi_simple: Identify raw string data in logging and stats --- plugins/mod_csi_simple.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 0c428c4a..3f3271f0 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -16,8 +16,10 @@ local queue_size = module:get_option_number("csi_queue_size", 256); local important_payloads = module:get_option_set("csi_important_payloads", { }); function is_important(stanza) --> boolean, reason: string - if not st.is_stanza(stanza) then + if type(stanza) == "string" then -- whitespace pings etc + return true, "raw data"; + elseif not st.is_stanza(stanza) then return true; end if stanza.attr.xmlns ~= nil then -- cgit v1.2.3 From c34f2c9ebf519ae400018cb81bb0d8141d75af64 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 10 May 2020 23:09:15 +0200 Subject: mod_csi_simple: Report whitespace keepalives Single space character is sent by mod_c2s when a session has been silent for some time. This should account for the vast majority of raw strings passing through here. If this is not the case then having stats to say otherwise will be interesting. --- plugins/mod_csi_simple.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 3f3271f0..679f9b48 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -16,8 +16,9 @@ local queue_size = module:get_option_number("csi_queue_size", 256); local important_payloads = module:get_option_set("csi_important_payloads", { }); function is_important(stanza) --> boolean, reason: string - if type(stanza) == "string" then - -- whitespace pings etc + if stanza == " " then + return true, "whitespace keepalive"; + elseif type(stanza) == "string" then return true, "raw data"; elseif not st.is_stanza(stanza) then return true; -- cgit v1.2.3 From e856c00107938f0442342e3550baae4bab3f3901 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 10 May 2020 23:12:33 +0200 Subject: mod_csi_simple: Report whatever's not a stirng and not a stanza This is either dead code or actually a type error, but catching that should be the responsibility of the session.send function. This type check is left since everything after it assumes a stanza object. These last few commits aren't meant to change any behavior and it did mark things not stanzas as important, but those would have been mostly raw strings which are now specially handled. --- plugins/mod_csi_simple.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'plugins/mod_csi_simple.lua') diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 679f9b48..d814f083 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -21,7 +21,8 @@ function is_important(stanza) --> boolean, reason: string elseif type(stanza) == "string" then return true, "raw data"; elseif not st.is_stanza(stanza) then - return true; + -- This should probably never happen + return true, type(stanza); end if stanza.attr.xmlns ~= nil then -- stream errors, stream management etc -- cgit v1.2.3