Commit Graph

134 Commits

Author SHA1 Message Date
Wez Furlong bee7153872 docs: update configure_redis_throttles redis-cell info 2024-10-08 13:39:07 -07:00
Wez Furlong 1cc1c703a4 docs: add thread pool tuning functions
These could do with some more exposition and explanation,
but just getting them into the docs is good enough for now
2024-09-24 18:43:53 -07:00
Wez Furlong 667d1a91cb docs: fix check-liveness links 2024-09-09 09:50:46 -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 7fe88f34a6 queue: make the default strategy SingletonTimerWheel 2024-09-02 14:08:48 -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 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
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 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 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 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
Wez Furlong d014237eb7 docs: more tweaks to sources
try to nudge folks away from adopting copypasta of the advanced
section; we've seen more than few people using this when they
should just use the sources policy helper.

Add the note about the weighted robin implementation to make_egress_pool
as well.
2024-07-27 07:08:31 -07:00
Wez Furlong d62781e7fa rfc5321 client: add openssl and rustls cipher/options 2024-07-20 16:16:47 -07:00
Wez Furlong b003e49c9c rfc5321: split out banner_timeout from connect_timeout
The motivation for this is:

My test environment is not permitted to reach outbound port 25.
If I run an ad-hoc test without setting up an explicit sink,
I end up with messages that try to reach the public internet.
Since they are blocked at a firewall, each of the MX hosts in
the connection plan is subject to a 60s wait before trying the next
thing.

In addition, this can cause the shutdown to take longer while
we wait for the in-flight delivery attempts to complete.

Making a separate configuration option allows the local administrator
to decide how to split the time waiting for a connection from
the time waiting for the banner.

refs: https://github.com/KumoCorp/kumomta/issues/196
2024-07-12 07:54:43 -07:00
Tom Mairs 53b16cefb4 fix typo 2024-07-08 20:40:32 +00:00
Wez Furlong f7604a3f7f docs: cut over toml examples to toml_data data macro
refs: https://github.com/KumoCorp/kumomta/issues/212
2024-07-03 16:09:52 -07:00
Wez Furlong e683fed556 docs: move Log Record to its own reference page
This makes it a bit easier to find and link to.
2024-06-27 08:28:45 -07:00
Wez Furlong f8c3429738 serde: move json/toml to new kumo.serde module. Added YAML.
This helps to avoid bloating kumo-server-common, and makes it
easier to group related functions together in the docs.

The original names are still usable; we'll remove them in a
future release.
2024-06-26 11:08:15 -07:00
Wez Furlong 8673045fff docs: update for latest release 2024-06-10 09:30:17 -07:00
Wez Furlong 4dad617d14 remove EgressPathConfig::suspended logic
When this was added, it was to enable TSA daemon to express
and convey that a given path should be suspended.

The implementation was objectively unpleasant, turning the
fast path of egress source assignment from a simple single
iteration of the weighted round robin logic to N (where N
is the number of sources in a pool) iterations to try
and figure out if a suspension is active.

Now that we have TSA subscriptions that update the admin
suspension information in realtime, we can now simply
rely on that source of information.

This commit removes the logic associated with the deprecated
suspended flag and tidies up the code, making that fast
path a little more fast, and making the code a bit easier
to reason about.
2024-05-02 06:18:14 -07:00
Wez Furlong 9e95303e6b add kumo.available_parallelism()
This can be helpful for writing configuration files for systems
that scale to the available compute resources.
2024-04-29 08:23:27 -07:00
Wez Furlong e94506fd96 Add new Rejection log event
We skip logging the 421 we generate while shutting down because
it feels a bit redundant; you'll see the server shutting down
in the journal anyway.

refs: https://github.com/KumoCorp/kumomta/issues/88
2024-03-29 16:37:37 -07:00
Wez Furlong 755eb848e2 add glob, read_dir
closes: https://github.com/KumoCorp/kumomta/issues/161
2024-03-29 08:25:51 -07:00
Wez Furlong 0c5794ba31 TSA: Add SuspendTenant, SuspendCampaign
refs: https://github.com/KumoCorp/kumomta/issues/113
2024-03-28 13:08:45 -07:00
Wez Furlong e41b4297ea tsa: hook up websocket suspension stream
This commit connects the new websocket based suspension feed
up to shaping.lua. This allows ready-q suspensions to be
enacted in realtime, as well as sets things up to support
scheduled queue suspensions in a later commit.

refs: https://github.com/KumoCorp/kumomta/issues/113
2024-03-28 07:14:36 -07:00
Wez Furlong 6003976a10 new: kumo.spawn_task function
This function will spawn a new thread that runs a tokio
localset, which in turn will trigger the specified event
and run it.

On it's own it doesn't do a lot, but it provides a way
to perform background tasks in lua.

```lua
kumo.on('init', function()
  kumo.spawn_task {
    event_name = 'my.task',
    args = { 'hello', 'there' },
  }
end)

kumo.on('my.task', function(args)
  -- Prints: `I am the task.  ["hello","there"]`
  print('I am the task.', kumo.json_encode(args))
end)
```
2024-03-28 07:14:35 -07:00
Wez Furlong a209a470ff docs: clarify how to access headers in logging templates 2024-03-22 08:08:14 -07:00
Wez Furlong 5596d7cf99 http_listener: allow configuring max request size 2024-03-17 09:35:02 -07:00
Tom Mairs d285a7f71a Update timeout defaults 2024-03-15 15:18:06 -06:00
Wez Furlong 5a1999a1b1 Add kumo.make_throttle and throttle_insert_ready_queue event
These allow performing arbitrary rate limiting operations
at both reception time and when messages are moved from the
scheduled queue and into the ready queue.

refs:  https://github.com/KumoCorp/kumomta/issues/149
2024-03-15 12:21:57 -07:00
Wez Furlong 8c43dfe209 add scheduled queue max_message_rate throttle
Needs testing, but I think this will do the job at the raw configuration
level. TSA support for adjusting this setting is a bigger endeavor and
is not included in this commit.

refs: https://github.com/KumoCorp/kumomta/issues/143
2024-03-07 11:00:18 -07:00
Wez Furlong b1375f8e6b docs: update for latest release 2024-01-03 13:49:55 -07:00
Wez Furlong 5d206834ce docs: fixup outdated source + pool information
Some sections didn't get updated to match changes
around how pools and sources are retrieved from the
configuration.

Thanks to @farhadhf for raising this

closes: https://github.com/KumoCorp/kumomta/pull/107
2023-12-14 17:17:06 -07:00
Wez Furlong 2925c7f565 docs: add missing socks5 config to reference section 2023-12-14 17:17:06 -07:00
Wez Furlong cdfe11cf22 Allow simple wildcard suffixes for header names in logs
refs: https://github.com/KumoCorp/kumomta/issues/74
2023-12-04 12:10:15 -07:00
Wez Furlong ec937b52ef Allow using arbitrary bounce classification labels
refs: https://github.com/KumoCorp/kumomta/issues/98
2023-11-29 12:09:05 -07:00
Wez Furlong 8af7e85c6b docs: update version info for latest release 2023-11-29 12:08:34 -07:00
Wez Furlong a03fcb2bf1 docs: fix sqlite auth example 2023-11-10 07:01:58 -07:00
Wez Furlong 8cbc60410d docs: update for dane 2023-10-26 17:03:00 -07:00
Wez Furlong 903189d873 add tls info to Delivery log records
refs: https://github.com/KumoCorp/kumomta/issues/39
refs: https://github.com/KumoCorp/kumomta/issues/8
2023-10-26 17:03:00 -07:00