annotate mod_log_events_by_memory/mod_log_events_by_memory.lua @ 4203:c4002aae4ad3

mod_s2s_keepalive: Use timestamp as iq @id RFC 6120 implies that the id attribute must be unique within a stream. This should fix problems with remote servers that enforce uniqueness and don't answer duplicated ids. If it doesn't do that, then at least you can get a guesstimate at round-trip time from the difference between the result iq stanza and the timestamp it was logged without having to go look for when it was sent, or needing to keep state.
author Kim Alvefur <zash@zash.se>
date Wed, 14 Oct 2020 18:02:10 +0200
parents 5fe34e5f9829
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3615
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 module:set_global();
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local treshold = module:get_option_number("log_memory_threshold", 20*1024);
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 function event_wrapper(handlers, event_name, event_data)
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 local memory_before = collectgarbage("count")*1024;
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local ret = handlers(event_name, event_data);
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local memory_after = collectgarbage("count")*1024;
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 if (memory_after - memory_before) > treshold then
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 module:log("warn", "Memory increased by %g bytes while processing event '%s'", (memory_after - memory_before), event_name);
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 end
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 return ret;
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 end
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 local http_events = require "net.http.server"._events;
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 module:wrap_object_event(http_events, false, event_wrapper);
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 module:wrap_event(false, event_wrapper);
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 function module.add_host(module)
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 module:wrap_event(false, event_wrapper);
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 end