930 Commits
Author SHA1 Message Date
Wez Furlong 667d1a91cb docs: fix check-liveness links 2024-09-09 09:50:46 -07:00
Wez Furlong 84cb629c91 docs: fix doc build after tsa page was removed 2024-09-09 06:46:59 -07:00
Mike Hillyer 88fa36cbe0 Remove TSA page 2024-09-07 18:32:08 -04:00
Mike Hillyer c247db63d8 Quick update and format. 2024-09-07 18:30:22 -04:00
Mike Hillyer a0c4f17bef Inital Publish of Updated Traffic Shaping Section. 2024-09-07 18:25:40 -04:00
Wez Furlong 76d8192d8f docs: fmt 2024-09-06 17:17:29 -07:00
Wez Furlong 4fa23e9a7d http injector: add deferred generation
There's big explanation about this in the included docs change.

The TL;DR is: we can now optionally queue the request and generate it
asynchronously wrt. the incoming injection request.

There's also a throttle that can be used to constrain this, because
the asynchronous submission disconnects the injection request from
any kind of back pressure that we'd otherwise have to indicate to
the injector that there might be load related issues.
2024-09-06 10:12:33 -07:00
Wez Furlong 5e833a8642 dns-resolver: randomize the list of hosts at a given pref level
Previously, we would deterministically produce the list of hosts
and use the same thing for each session that we established outbound.
This could result in biasing the outgoing traffic onto a single host
and result in lower overall throughput.

This commit shuffles the set of hosts at a given preference level
to probabalistically distribute the load among them.
2024-09-05 16:40:25 -07:00
Wez Furlong c3c4d12acf http inject: deferred_spool is not a required parameter 2024-09-05 07:33:56 -07:00
Wez Furlong 9b45903d44 http inject: add optional deferred_spool parameter
This can increase injection performance, trading increased risk
of loss of accountability for increased speed.
2024-09-04 14:56:14 -07:00
Mike Hillyer 4a1995e772 Update the shaping files to show a better sample usage, add Intercom to the documentation site. 2024-09-04 16:59:10 -04:00
Wez Furlong 4e04efc497 docs: add docs for new amqprs client 2024-09-03 22:28:50 -07:00
Wez Furlong ce8b8c991e docs: update kcli for new trace params 2024-09-03 22:28:21 -07:00
Wez Furlong b5eb78b72b dkim_sign.lua: make base and domain optional
When splitting the config across multiple files, we should not
raise an error if the base or domain section is missing from
the file that is currently being processed.

Let's also show which file is currently being processed.
2024-09-03 14:54:09 -07:00
Wez Furlong b384fb73a4 kcli trace-smtp-(client|server): improve usage for busy sites
This commit adds a couple of options that make it a bit easier
to make sense of high traffic environments.

It also fixes an issue with displaying timing: previously, if
we'd never seen the official start of a session, we'd never
show a reasonable time delta, and every record for that session
would be reported as `0ns`.

Now we assume that the first record for a session is as good as
the starting time for the session. That allows us to show
some meaningful timing information in the case that we attach
to an in-flight session for which we missing the start.
2024-09-03 06:25:09 -07:00
Wez Furlong 054f1eec15 docs: fix title for the most recent stable release changelog 2024-09-02 14:09:43 -07:00
Wez Furlong 7fe88f34a6 queue: make the default strategy SingletonTimerWheel 2024-09-02 14:08:48 -07:00
Wez Furlong 3ae6ef4223 docs: add some brief notes about what is now in main 2024-09-02 10:52:41 -07:00
Wez Furlong 541b8f28e4 shaping: add provider concept to shaping helper
This enables shaping based on MX hostname and domain name matching
rules.

At a lower level, this is supported via two new options:
additional_connection_limits and additional_message_rate_throttles that
allow specifying arbitrarily scoped named limits and throttles, which
in addition to allowing provider-based rules in the shaping helper,
allow things like global or other more esoteric scoping of constraints.

closes: https://github.com/KumoCorp/kumomta/pull/260
2024-09-02 10:42:15 -07:00
Wez Furlong f7e68070d1 config: introduce ConfigEpoch and policy file monitoring
This commit adds a background task that periodically evaluates
a glob expression that defaults to the recommended configuration
location and filename suffixes, and a set of additional paths
to observe.

Whenever the hash of that combined set of files changes it causes the
ConfigEpoch to increment and broadcast to subscribers that the
configuration has changed in some fashion.

The QueueConfig struct has a new refresh_strategy which can select
between the earlier Ttl based refresh for the queue config, or
the new Epoch refresh.

When the epoch changes, the config refresh task will cause each of
the scheduled queues that is using the Epoch strategy to re-evaluate
the get_queue_config event to update their configuration.

The queues helper sets the refresh strategy to Epoch.

A new HTTP endpoint has been added: it can force a bump in the
current epoch, effectively causing all epoch subscribers to
wake up and perform a refresh.

These changes avoid doing O(number-of-scheduled-queues) get_queue_config
callouts every refresh_interval; instead, the work is performed only
when an appropriate change is detected or triggered.
2024-09-02 10:42:14 -07:00
Wez Furlong 276bf9f8cb docs: update changelog for 2024.09.02-c5476b89 2024-09-02 07:29:27 -07:00
Wez Furlong a42871cb11 docs: update since dev -> 2024.09.02-c5476b89 2024-09-02 07:27:50 -07:00
Wez Furlong a18308a3b2 docs: mention SingletonTimerWheel 2024-09-01 15:38:12 -07:00
Mike Hillyer d261986699 Get rid of linter complaints. 2024-08-26 16:53:53 -04:00
Mike Hillyer ad5b393e55 Update the cluster scaling page. 2024-08-26 16:52:56 -04:00
Wez Furlong 3d4a5d2194 mailparsing: relax Content-ID and Message-ID parsing
This is an area where conformance is inconsistently applied by
various clients, so we're relaxing our parser to try the current
strict rules first, which can normalize stuff like `<"foo"@id>`,
but then allow falling back to anything between `<>`.

We will still blow up for wonky stuff like `<<wat>>`, as proven
by our existing test coverage.

closes: #259
2024-08-26 08:11:20 -07:00
Wez Furlong b1b6a99fe9 queue: add experimental strategy="SingletonTimerWheel"
As mentioned in a prior commit, when there are very large numbers
of scheduled queues (hundreds of thousands), the tokio timer/task
infrastructure becomes over-burdened and the system bogs down.

This commit introduces a SingletonTimerWheel strategy for the
scheduled queues.  When this strategy is in use, each scheduled
queue maintains a local HashSet of Messages rather than an
individual wheel or skip list.  The time ordering is instead
handled by a global singleton timerwheel that holds weak references
to the messages.

The definitive ownership of the Message belongs to the per-Queue
HashSet.

The global wheel ticks over once every 3 seconds for ALL queues
that have delayed messages, popping off the weak references
and attempting to upgrade them to a full Message reference.

From there, the message is resolved back to its containing queue,
and if it is found in the HashSet then it is reinserted into the
ready queue.

If either the upgrade or HashSet check fails then the message
has been either bounced or rebound and requires no further
processing.

This change makes the number of scheduled tasks for delayed
messages O(1), rather than O(number-of-queues), at the cost
of a small loss in precision of promoting the delayed messages
to the ready queue, and double the amount of Message handles;
previously it would be approx:
  number-of-delayed-messages * sizeof(pointer)
now it is 2x that amount (~ + some misc overhead)

I don't plan to add a SingletonSkipList strategy: since the list is
global it can have potentially millions of delayed messages (the entire
server's delayed mail) so we really do want O(1) insertion for this
rather than the skip lists worse insertion complexity.

Since this change eliminates the maintainer task, we need an alternative
approach for processing configuration refreshes, so this commit moves
that out of the per-queue maintainer and into a separate task that wakes
up periodically to assess all scheduled queues to see if they are due
for a refresh (according to their individual refresh_intervals) and
perform the refresh.

This change makes the config refresh a sequential operation:
only the refresh task will zip through and perform the refreshes.
Previously, you could expect to see most/all of the qmaint threads
doing this.
2024-08-24 20:47:28 -07:00
Wez Furlong 0c2a41290c docs: format generate-toc.py 2024-08-24 08:17:38 -07:00
Mike Hillyer 279d3637ae Update Userguide Index to link to new chapters. 2024-08-23 16:00:59 -04:00
Mike Hillyer dab23cde0c Fix change of deployment page. 2024-08-23 15:52:50 -04:00
Mike Hillyer 42ab54d1b3 Initial Clustering Chapter 2024-08-22 18:14:18 -04:00
Tom Mairs ad20d58302 update metrics sample 2024-08-21 22:00:37 +00:00
Wez Furlong bf3d8d45f7 tsa: default pre_filter to enabled
Graduate this to default to enabled; it's generally the right
trade.
2024-08-20 07:28:12 -07:00
Wez Furlong 7961bff955 docs: split configure_local_logs into multiple pages 2024-08-18 22:28:41 -07:00
Wez Furlong 75e8a32b59 docs: split start_http_listener into multiple pages 2024-08-18 22:18:59 -07:00
Wez Furlong 1b32aa1b4b docs: split start_esmtp_listener into multiple pages 2024-08-18 20:02:35 -07:00
Wez Furlong 34df28bbb1 docs: fixup a few links from page splitting 2024-08-18 19:52:19 -07:00
Wez Furlong bf060ca171 docs: fixup links to implicit Gen child pages 2024-08-18 19:50:16 -07:00
Wez Furlong dbdd69a8c7 docs: split make_egress_source into separate files 2024-08-18 19:47:35 -07:00
Wez Furlong 632357ac70 docs: split make_egress_pool into separate pages 2024-08-18 19:40:47 -07:00
Wez Furlong b775816885 docs: split make_egress_path into separate pages 2024-08-18 19:33:31 -07:00
Wez Furlong 1bd2b00b4e docs: move make_listener_domain options to their own pages 2024-08-18 19:19:30 -07:00
Wez Furlong 4af9c7035f docs: move make_queue_config fields to their own pages
This makes them easier to search for, and find.
2024-08-18 19:14:34 -07:00
Wez Furlong 84056ffb44 add disk space monitoring
This commit adds disk space monitors for the configured spool
and local log file locations.

Incoming messages will be rejected when the available space is below
the configured amount.

The default minimum is 10%.
2024-08-18 09:17:42 -07:00
Wez Furlong 12d1569973 improve bounce classification performance
For large classifier rulesets (more than 3,000 rules), the cost
of classifying any single response can be as high as 2ms.

This is significant; given that the loggers are each single threaded a
2ms overhead limits the maximum throughput to 500 messages per second.

This commit improves the structure of the code in order to mitigate
the potential for a bottleneck:

* Don't bother categorizing Reception records. They are not bounces
  and are generated by the local machine.  It's a waste of CPU and
  introduces the potential to put back pressure on the injector.
* Introduce a cache for classification results. The cache is split
  into two parts so that unclassified results don't churn out the
  successfully classified results.
* Introduce a bounce-classification thread pool. If we are unlucky
  and encounter a long series of "random" responses with no cache
  hits, and have up to 2ms per classification constraining us to
  around 500 msgs/s, then we need to apply more CPU cores to the
  classifier to achieve multiples of that throughput, and that is
  what we have here. We spawn 1/4 the number of cores threads
  into this thread pool.
2024-08-16 21:16:49 -07:00
Wez Furlong 77777a19cd http: don't skip parsing Authentication header from trusted host
This is a bit esoteric... previously, the http authentication
process would essentially short-cut things when a request was
made from a trusted host, ignoring any Auth header
that may have been present.

The rationale was that the host was trusted, so the peer would
succeed simply by omitting that header.

This commit changes the flow so that we only set the trusted
host status if no Auth header was provided.

If an Authentication header is present, it will be validated
before allowing the request to continue.

If the header is invalid then the request will be denied, even
if the peer is a trusted host.

This tightens things up slightly by making the auth validation
behavior most consistent, but it doesn't materially affect
the security posture: the trusted host can still successfully
make calls by simply omitting the authentication header.

It does mean that what was previously allowed (an invalid Auth header
from a trusted host) is no longer allowed.
2024-08-13 20:22:44 -07:00
Wez Furlong e8e0f208ee queue: add strategy option choose between skiplist and timerwheel
Previously we were using only our timeq module, which is built on top of
hashed hierarchical timer wheels.

Timer wheels have O(1) insertion and removal which are excellent
properties for larger delayed queues.

However, they do not know how to answer the question "when is the
next item due", but only "what is due in the next tick".

The underlying timer wheel implementation assumes a 1ms granularity
which is a little bit at-odds with our pragmatic view of the scheduled
queue, which is "if it's in there, precision timing isn't important, and
it's generally fine to consider once per minute", requiring that we
either aggressively scheduled a maintainer task to wake up every 1ms per
scheduled queue (untenable!) or have it wake up no more than once per
second but ideally closer to once per minute to then tick however
milliseconds are necessary to advance the wheel to the current slot.

For small numbers of scheduled queues with sufficiently large retry
intervals this hasn't bubbled up as an issue so far, but it bothers
me that it isn't as efficient as it could be because we have to wake up
reasonably frequently to keep things ticking over, and that introduces
higher continual CPU utilization. It's small, but I worry about
the aggregate cost spread over very large numbers of scheduled queues.

What I really want here is a a timer wheel that I can tick with
arbitrary granularity and with that in mind I took a look at adapting
the handful of existing implementations and found that we're already
using the cleanest implementation, and it would take some effort that I
didn't really want to spend right now.

I opted for a reasonably simple alternative option, which is to adopt a
skiplist for the queue. This has O(log n) insertion to maintain ordering
with O(1) removal and can answer "when is the next item due".  What this
means is that we pay a slightly higher insertion cost one-time in
exchange for being able to put the maintainer for the queue asleep until
we need it, and not have to keep waking up between times, which should
scale better.

What this means in practice is that we now wake up the maintainer either
when the next message is due, or once per minute to re-evaluate the
queue configuration hook, so we're slightly better off, but totally
where I'd like to be.

I've introduced a reap_interval (default 10 minutes) and a
refresh_interval (default 1 minute) as parameters in get_queue_config so
that you can increase that 1m interval for reloading.

What I'd like to do in a follow up commit is introduce a way to define
the refresh policy. For example, it would be neat to say "watch my
policy directory and refresh when it changes", which would make things
the most efficient for many users.  For those that are loading their
config from a remote datasource, we'd need to consider some other
mechanism for this; maybe some kind of long-poll or pubsub, but will
obviously still be able to support the current interval based polling.

Now, with all of that said: I didn't want to switch the product
default over and hope for best, so what I did was add a strategy
option to allow this to be adopted on a per-queue basis.

Since I was in here adding some options, I also added an option
that allows explicitly setting the interval used for timerwheel
ticks, so you now have a lot more opportunities for tuning this
stuff.
2024-08-13 16:46:34 -07:00
Wez Furlong 2c396abcd2 logging: fully respect back_pressure for log hooks
When hooks were developed, they were essentially "forked" from the log
file implementation and the back_pressure setting and semantics were
carried over from there.

Those semantics were to put an upper bound on the number of log records
that could be submitted to the logger, causing the submitter to block
until the logger could catch up and reducing system pressure overall by
slowing things down.

With log hooks we're spawning a parallel task in the tail end which
meant that the back pressure was only partially effective: it didn't
apply to the end-to-end processing of a log hook.

This commit addresses that issue by introducing a semaphore that permits
up to the configured back_pressure number of concurrent log hook tasks
to be running at once, slowing things down when that limit is reached.
2024-08-11 08:31:51 -07:00
Wez Furlong 481b55b0ff logging: fix max_segment_duration on busy systems
The expiration check was only allowed to run when the logging
thread was idle, leading to segments lasting longer than intended.
2024-08-11 08:13:26 -07:00
Wez Furlong 9e757c36d3 add max_connections limit to esmtp_listener
Previously we'd go as far as the OS would let us.

This introduces the ability to set an upper bound, and our default for
this is 32k connections, or half of the possible u16 port space.  I
picked half because the ideal for an MTA is using half of its resources
to receive and the other half to send.  The math for that is more
complex for multi-homed machines or systems using proxies, but it feels
like a reasonable default; not too low that it will be painfully
surprising for existing users to discover on upgrade, and not so high
that new installations are as easily overwhelmed in the face of high
incoming traffic.

A new total_connections_denied counter is added that is bumped
whenever this or the over-memory limit are reached and we turn
away a session with a 421. The idea is that the operator may
want to investigate these events, and we don't otherwise have
a stream of information about them because they are deliberately
not logged to the normal delivery logs.
2024-08-10 08:28:04 -07:00