mirror of
https://github.com/mailscope/kumomta.git
synced 2026-08-20 11:28:17 +00:00
b8310da8be
TL;DR: you can easily halve your system performance by logging headers vs. logging meta. This is one of those things that is easy to overlook or forget, but: whenever you need to operate on the message data, rather than its metadata, the aggregate cost is high. In this case, we were recently troubleshooting a system where the CPU was bogged down and we traced it to the logging configuration: a number of message headers were being logged in a configuration that made heavy use of throttles and limits in its traffic shaping, and thus had a large number of Delayed and TransientFailure events being written to the logs. When logging headers, each one of those events requires loading the message from the spool and parsing out the headers. When the average message size is ~100KB this imposes a notable overhead on the CPU and IO utilization of the system. What we recommend instead of logging headers directly is capturing the information that you want to log into the message metadata at the time that the message is received. The message meta is usually already loaded, but is also typically much smaller and easier to decode than the full message content in the cases where it is not loaded. As a result, it is much cheaper to log meta than to log headers. This commit adds some warnings and cross links to help folks be aware of this, and to generally navigate related meta and logging topics more easily via tags.
1.1 KiB
1.1 KiB
tags
| tags | |
|---|---|
|
message:import_x_headers([NAMES])
When called with no parameters, iterates the headers of the message, and for
each header with an "X-" prefix, imports the header into the message
metadata.
When called with a list of header names, only those headers, if present in the
message, will be imported to the message metadata. Header names passed in this
way do not need to have an X- prefix, making it convenient to use this method
as a way to import an arbitrary list of headers for logging purposes.
When importing an X- header, the header name is normalized to lowercase and any
- are transformed to underscores _.
For example, with a message content of:
X-Campaign-ID: 12345
X-Mailer: foobar
Subject: the subject
The body
calling:
message:import_x_headers()
print(message:get_meta 'x_campaign_id') -- prints 12345
print(message:get_meta 'x_mailer') -- prints foobar
but calling:
message:import_x_headers { 'x-campaign-id' }
print(message:get_meta 'x_campaign_id') -- prints 12345
print(message:get_meta 'x_mailer') -- prints nothing