Comparison

plugins/mod_csi_simple.lua @ 12552:b4bc5a715e65

mod_csi_simple: Collect stats on number of stanzas per flush Because interesting, gives some idea about the efficiency.
author Kim Alvefur <zash@zash.se>
date Tue, 14 Jun 2022 03:31:30 +0200
parent 12234:1c47162dd965
child 12977:74b9e05af71e
comparison
equal deleted inserted replaced
12551:3b7e97e0a8ef 12552:b4bc5a715e65
114 "counter", "flushes", "", 114 "counter", "flushes", "",
115 "CSI queue flushes", 115 "CSI queue flushes",
116 { "reason" } 116 { "reason" }
117 ); 117 );
118 118
119 local flush_sizes = module:metric("histogram", "flush_stanza_count", "", "Number of stanzas flushed at once", {},
120 { buckets = { 0, 1, 2, 4, 8, 16, 32, 64, 128, 256 } }):with_labels();
121
119 local function manage_buffer(stanza, session) 122 local function manage_buffer(stanza, session)
120 local ctr = session.csi_counter or 0; 123 local ctr = session.csi_counter or 0;
121 if session.state ~= "inactive" then 124 if session.state ~= "inactive" then
122 session.csi_counter = ctr + 1; 125 session.csi_counter = ctr + 1;
123 return stanza; 126 return stanza;
127 if session.csi_measure_buffer_hold then 130 if session.csi_measure_buffer_hold then
128 session.csi_measure_buffer_hold(); 131 session.csi_measure_buffer_hold();
129 session.csi_measure_buffer_hold = nil; 132 session.csi_measure_buffer_hold = nil;
130 end 133 end
131 flush_reasons:with_labels(why or "important"):add(1); 134 flush_reasons:with_labels(why or "important"):add(1);
135 flush_sizes:sample(ctr);
132 session.log("debug", "Flushing buffer (%s; queue size is %d)", why or "important", session.csi_counter); 136 session.log("debug", "Flushing buffer (%s; queue size is %d)", why or "important", session.csi_counter);
133 session.state = "flushing"; 137 session.state = "flushing";
134 module:fire_event("csi-flushing", { session = session }); 138 module:fire_event("csi-flushing", { session = session });
135 session.conn:resume_writes(); 139 session.conn:resume_writes();
136 else 140 else
145 local ctr = session.csi_counter or 0; 149 local ctr = session.csi_counter or 0;
146 if ctr == 0 or session.state ~= "inactive" then return data end 150 if ctr == 0 or session.state ~= "inactive" then return data end
147 session.log("debug", "Flushing buffer (%s; queue size is %d)", "client activity", session.csi_counter); 151 session.log("debug", "Flushing buffer (%s; queue size is %d)", "client activity", session.csi_counter);
148 session.state = "flushing"; 152 session.state = "flushing";
149 module:fire_event("csi-flushing", { session = session }); 153 module:fire_event("csi-flushing", { session = session });
154 flush_sizes:sample(ctr);
150 flush_reasons:with_labels("client activity"):add(1); 155 flush_reasons:with_labels("client activity"):add(1);
151 if session.csi_measure_buffer_hold then 156 if session.csi_measure_buffer_hold then
152 session.csi_measure_buffer_hold(); 157 session.csi_measure_buffer_hold();
153 session.csi_measure_buffer_hold = nil; 158 session.csi_measure_buffer_hold = nil;
154 end 159 end