diff options
author | Kim Alvefur <zash@zash.se> | 2020-05-09 17:45:45 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2020-05-09 17:45:45 +0200 |
commit | 931adcf40c7d5afdd193cddcd565750fd384eff1 (patch) | |
tree | a45187eb84ed31da05be38a06670f9ad7869e422 /plugins/mod_csi_simple.lua | |
parent | de96139b6c5eabdb6ce053f38cae5397cf999df2 (diff) | |
download | prosody-931adcf40c7d5afdd193cddcd565750fd384eff1.tar.gz prosody-931adcf40c7d5afdd193cddcd565750fd384eff1.zip |
mod_csi_simple: Record stats of how long buffers are held
Telnet command `stats:show("buffer_hold"):histogram()` looks nice!
Diffstat (limited to 'plugins/mod_csi_simple.lua')
-rw-r--r-- | plugins/mod_csi_simple.lua | 16 |
1 files changed, 16 insertions, 0 deletions
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 |