![]() |
Mads
Multi-Agent Distributed System
|
Namespaces | |
| namespace | fd_limit_impl |
Classes | |
| struct | FdLimitOutcome |
| The result of acting on a plan. More... | |
| struct | FdLimitPlan |
| struct | FdLimits |
| struct | SocketOptions |
| struct | WireHeader |
Enumerations | |
| enum class | Comp : uint8_t { None = 0 , Snappy = 1 } |
Functions | |
| const std::string & | clock_domain_id () |
| Stable identifier for the clock this process reads. Computed once (function-local static, thread-safe init) and cached for the life of the process. | |
| uint64_t | agent_capacity (uint64_t soft) |
| How many agents a given soft limit leaves room for. | |
| FdLimits | query_fd_limits () |
Reads the limits currently in force, with hard clamped as described above. | |
| std::string | describe_fd_limits (const FdLimits &limits) |
| Renders e.g. "1024 soft / 1048576 hard, about 492 agents". | |
| std::string | fd_limit_hint () |
| The hint appended to every message that reports a limit worth raising. | |
| FdLimitPlan | plan_fd_limit (std::optional< int64_t > requested, const FdLimits &limits) |
| FdLimitOutcome | apply_fd_limit (const FdLimitPlan &plan) |
| bool | is_fd_exhaustion (int err) |
| mongocxx::instance & | mongo_instance () |
| Return the process-wide mongocxx driver instance. | |
| uint64_t | fnv1a64 (const void *data, size_t len) |
| std::string | digest_hex (std::string_view bytes) |
| std::filesystem::path | attachment_cache_root () |
| void | sweep_stale (const std::filesystem::path &agent_dir, std::string_view keep_digest, const std::string &name, const std::string &ext) |
| std::filesystem::path | store_attachment (const std::string &name, const std::string &ext, const std::string &bytes) |
| Persist a broker-served attachment under its content digest and return the path to load it from. | |
| template<typename T > | |
| std::optional< T > | resolve_setting (toml::node_view< toml::node > fleet_cfg, toml::node_view< toml::node > agent_cfg, std::string_view key) |
| std::string | make_wire_header (WireFormat fmt, Comp comp, bool has_blob) |
| bool | parse_wire_header (const std::string &part, WireHeader &out) |
| Comp | resolve_compression (Compression policy, size_t size) |
| std::string | encode_payload (const nlohmann::json &j, WireFormat fmt) |
| bool | decode_to_json_text (const std::string &raw, uint8_t format, uint8_t comp, std::string &json_text_out) |
Variables | |
| constexpr uint64_t | FD_PER_AGENT = 2 |
| constexpr uint64_t | FD_BROKER_OVERHEAD = 64 |
| constexpr uint64_t | FD_LOW_WATERMARK = 1024 |
| constexpr uint64_t | FD_ABSOLUTE_CEILING = 1048576 |
| constexpr char | WIRE_MAGIC [4] = {'M', 'A', 'D', 'S'} |
| constexpr uint8_t | WIRE_HDR_VERSION = 1 |
| constexpr uint8_t | WIRE_FLAG_BLOB = 0x01 |
| constexpr size_t | WIRE_HEADER_SIZE |
|
strong |
| Enumerator | |
|---|---|
| None | |
| Snappy | |
Definition at line 46 of file wire_format.hpp.
|
inline |
How many agents a given soft limit leaves room for.
Definition at line 76 of file fd_limit.hpp.
References FD_BROKER_OVERHEAD, and FD_PER_AGENT.
Referenced by describe_fd_limits(), and plan_fd_limit().
|
inline |
Carries out plan. Only ever moves the soft limit: rlim_max is left untouched, since raising it needs CAP_SYS_RESOURCE and would simply fail for an unprivileged broker, while moving the soft limit anywhere at or below the hard one never needs privileges at all – in either direction.
Lowering does not close descriptors that are already open; it only makes further allocations fail. Since the broker applies this before binding anything, that distinction does not arise in practice.
Definition at line 318 of file fd_limit.hpp.
References Mads::detail::FdLimitPlan::action, Mads::detail::FdLimitOutcome::applied, Mads::detail::FdLimitOutcome::error, Mads::detail::FdLimitOutcome::limits, Mads::detail::FdLimitPlan::Lower, query_fd_limits(), Mads::detail::FdLimitPlan::Raise, Mads::detail::FdLimits::supported, and Mads::detail::FdLimitPlan::target.
|
inline |
Definition at line 86 of file plugin_cache.hpp.
Referenced by store_attachment().
|
inline |
Stable identifier for the clock this process reads. Computed once (function-local static, thread-safe init) and cached for the life of the process.
Definition at line 45 of file clock_domain.hpp.
References HOST_NAME_MAX.
|
inline |
Definition at line 115 of file wire_format.hpp.
References Snappy.
|
inline |
Renders e.g. "1024 soft / 1048576 hard, about 492 agents".
Definition at line 187 of file fd_limit.hpp.
References agent_capacity(), Mads::detail::FdLimits::hard, and Mads::detail::FdLimits::soft.
Referenced by plan_fd_limit().
|
inline |
Definition at line 74 of file plugin_cache.hpp.
References fnv1a64().
Referenced by store_attachment().
|
inline |
Definition at line 104 of file wire_format.hpp.
|
inline |
The hint appended to every message that reports a limit worth raising.
Definition at line 194 of file fd_limit.hpp.
Referenced by plan_fd_limit().
|
inline |
Definition at line 62 of file plugin_cache.hpp.
Referenced by digest_hex().
|
inline |
True when err is the errno of a process (or system) descriptor table that has filled up – the condition every explanatory message here exists for.
Definition at line 346 of file fd_limit.hpp.
|
inline |
Definition at line 56 of file wire_format.hpp.
References WIRE_FLAG_BLOB, WIRE_HDR_VERSION, WIRE_HEADER_SIZE, and WIRE_MAGIC.
|
inline |
Return the process-wide mongocxx driver instance.
mongocxx::instance must be constructed exactly once per process and must outlive every other driver object; constructing a second one while the first is alive throws mongocxx::logic_error{k_cannot_recreate_instance}. Holding one as a class member therefore makes it impossible for two driver-using MADS objects to coexist, so every translation unit that touches the driver shares the single function-local static created here.
The static is destroyed at process exit, after all clients built on top of it.
inline, so all callers linked into the same binary share one static. MadsCore is a single shared library, so that holds for MADS. Definition at line 36 of file mongo_instance.hpp.
|
inline |
Definition at line 73 of file wire_format.hpp.
References Mads::detail::WireHeader::compression, Mads::detail::WireHeader::format, Mads::detail::WireHeader::has_blob, Mads::detail::WireHeader::hdr_version, Mads::detail::WireHeader::schema, WIRE_FLAG_BLOB, WIRE_HEADER_SIZE, and WIRE_MAGIC.
|
inline |
Decides what to do. requested is the resolved max_open_files value: nullopt leaves the limit untouched, 0 means "as high as this process is
allowed to go", and a positive value is a specific soft limit.
Definition at line 202 of file fd_limit.hpp.
References Mads::detail::FdLimitPlan::action, agent_capacity(), Mads::detail::FdLimitPlan::clamped, describe_fd_limits(), FD_BROKER_OVERHEAD, fd_limit_hint(), FD_LOW_WATERMARK, Mads::detail::FdLimits::hard, Mads::detail::FdLimitPlan::Invalid, Mads::detail::FdLimitPlan::Lower, Mads::detail::FdLimitPlan::message, Mads::detail::FdLimitPlan::NotSupported, Mads::detail::FdLimitPlan::Raise, Mads::detail::FdLimits::soft, Mads::detail::FdLimits::supported, Mads::detail::FdLimitPlan::target, Mads::detail::FdLimitPlan::Unchanged, Mads::detail::FdLimitPlan::Unset, and Mads::detail::FdLimitPlan::warn.
|
inline |
Reads the limits currently in force, with hard clamped as described above.
Definition at line 132 of file fd_limit.hpp.
References FD_ABSOLUTE_CEILING, Mads::detail::FdLimits::hard, Mads::detail::fd_limit_impl::kernel_fd_ceiling(), Mads::detail::FdLimits::soft, and Mads::detail::FdLimits::supported.
Referenced by apply_fd_limit().
|
inline |
Definition at line 91 of file wire_format.hpp.
| std::optional< T > Mads::detail::resolve_setting | ( | toml::node_view< toml::node > | fleet_cfg, |
| toml::node_view< toml::node > | agent_cfg, | ||
| std::string_view | key | ||
| ) |
Definition at line 24 of file socket_options.hpp.
|
inline |
Persist a broker-served attachment under its content digest and return the path to load it from.
Safe to call concurrently from any number of processes and threads: the bytes at the returned path are never mutated in place, so a copy another process has already dlopen()'d stays exactly as that process mapped it.
| name | Settings section name; also the returned file's stem. |
| ext | Extension without the leading dot (e.g. "plugin"). |
| bytes | The attachment as received from the broker. |
| std::runtime_error | if the attachment cannot be persisted. |
Definition at line 134 of file plugin_cache.hpp.
References attachment_cache_root(), digest_hex(), and sweep_stale().
|
inline |
Definition at line 96 of file plugin_cache.hpp.
Referenced by store_attachment().
|
inlineconstexpr |
Last-resort ceiling when the OS reports an unbounded hard limit and no kernel cap could be read. Matches Linux's own default fs.nr_open.
Definition at line 73 of file fd_limit.hpp.
Referenced by query_fd_limits().
|
inlineconstexpr |
The broker's own descriptor footprint, independent of fleet size: three listening sockets, ~10 libzmq socket mailboxes, the context reaper's and each I/O thread's poller, stdio, and the settings-file watch.
Platform-dependent, because the mailboxes dominate it and their cost is not the same everywhere: libzmq's signaler uses eventfd() where it exists (Linux), costing one descriptor per mailbox, and falls back to a socketpair – two descriptors – everywhere else. Measured at idle: ~34 on Linux, 49 on macOS. Rounded up in both cases, so the capacity estimate errs toward understating how many agents will fit rather than overstating.
Definition at line 63 of file fd_limit.hpp.
Referenced by agent_capacity(), and plan_fd_limit().
|
inlineconstexpr |
Soft limit at or below which raising is worth suggesting – the default on essentially every Linux distribution, and the value systemd hands a unit that does not set LimitNOFILE=.
Definition at line 69 of file fd_limit.hpp.
Referenced by plan_fd_limit().
|
inlineconstexpr |
Descriptors a single connected agent costs the broker for as long as it stays connected: one for its publisher, one for its subscriber. (The settings request needs a third, but only while it is in flight.)
Definition at line 48 of file fd_limit.hpp.
Referenced by agent_capacity().
|
constexpr |
Definition at line 41 of file wire_format.hpp.
Referenced by make_wire_header(), and parse_wire_header().
|
constexpr |
Definition at line 40 of file wire_format.hpp.
Referenced by make_wire_header().
|
constexpr |
Definition at line 42 of file wire_format.hpp.
Referenced by make_wire_header(), and parse_wire_header().
|
constexpr |
Definition at line 39 of file wire_format.hpp.
Referenced by make_wire_header(), and parse_wire_header().