StormByte-Buffer 4.0.0
C++26 buffer module of the StormByte suite
Loading...
Searching...
No Matches
parameters.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Buffer.
5 *
6 * StormByte-Buffer original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte-Buffer source in this
20 * repository. They do not cover other StormByte modules or any third-party
21 * material shipped with this repository (including everything under
22 * thirdparty/, and in particular the bundled StormByte-Logger tree and
23 * the rest of the StormByte suite it vendors), which remains under its own
24 * license.
25 *
26 * Neither license grants any patent rights. Any patent licenses required
27 * to use this software or third-party components must be obtained separately
28 * from the patent holders.
29 *
30 * StormByte-Buffer is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU Lesser General Public License for more details.
34 *
35 * You should have received a copy of the GNU Lesser General Public License
36 * version 3 along with StormByte-Buffer. If not, see
37 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
38 *
39 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
40 */
41
42#pragma once
43
44#include <StormByte/type_traits/safe.hxx>
45
46#include <StormByte/byte_size.hxx>
47#include <StormByte/platform.h>
48#include <StormByte/safe/optional.hxx>
49#include <StormByte/type_traits.hxx>
50
51#include <chrono>
52#include <cstddef>
53#include <cstdint>
54#include <utility>
55
60namespace StormByte {
65 namespace Buffer {
74 namespace IO {
78 class ReadChunk {
79 public:
84 explicit ReadChunk(StormByte::ByteSize value) noexcept: m_value(value) {}
85
90 ReadChunk(const ReadChunk& other) noexcept = default;
91
96 ReadChunk(ReadChunk&& other) noexcept = default;
97
101 ~ReadChunk() noexcept = default;
102
108 ReadChunk& operator=(const ReadChunk& other) noexcept = default;
109
115 ReadChunk& operator=(ReadChunk&& other) noexcept = default;
116
121 StormByte::ByteSize Value() const noexcept { return m_value; }
122
123 private:
124 StormByte::ByteSize m_value;
125 };
126
131 public:
136 explicit WriteTransfer(StormByte::ByteSize value) noexcept: m_value(value) {}
137
142 WriteTransfer(const WriteTransfer& other) noexcept = default;
143
148 WriteTransfer(WriteTransfer&& other) noexcept = default;
149
153 ~WriteTransfer() noexcept = default;
154
160 WriteTransfer& operator=(const WriteTransfer& other) noexcept = default;
161
167 WriteTransfer& operator=(WriteTransfer&& other) noexcept = default;
168
173 StormByte::ByteSize Value() const noexcept { return m_value; }
174
175 private:
176 StormByte::ByteSize m_value;
177 };
178
183 public:
188 explicit WriteThreshold(StormByte::ByteSize value) noexcept: m_value(value) {}
189
194 WriteThreshold(const WriteThreshold& other) noexcept = default;
195
200 WriteThreshold(WriteThreshold&& other) noexcept = default;
201
205 ~WriteThreshold() noexcept = default;
206
212 WriteThreshold& operator=(const WriteThreshold& other) noexcept = default;
213
219 WriteThreshold& operator=(WriteThreshold&& other) noexcept = default;
220
225 StormByte::ByteSize Value() const noexcept { return m_value; }
226
227 private:
228 StormByte::ByteSize m_value;
229 };
230
240
252
271
276 class ReadAhead {
277 public:
282 explicit ReadAhead(const StormByte::ByteSize value) noexcept:
283 m_value(value) {}
284
289 StormByte::ByteSize Value() const noexcept {
290 return m_value;
291 }
292
293 private:
297 StormByte::ByteSize m_value;
298 };
299
304 class MaxMemory {
305 public:
310 explicit MaxMemory(const StormByte::ByteSize value) noexcept:
311 m_value(value) {}
312
317 StormByte::ByteSize Value() const noexcept {
318 return m_value;
319 }
320
321 private:
325 StormByte::ByteSize m_value;
326 };
327
332 class MaxWait {
333 public:
338 explicit MaxWait(const std::chrono::milliseconds value) noexcept:
339 m_value(value) {}
340
345 std::chrono::milliseconds Value() const noexcept {
346 return m_value;
347 }
348
349 private:
353 std::chrono::milliseconds m_value;
354 };
355
361 public:
366 explicit WriteChunk(const StormByte::ByteSize value) noexcept:
367 m_value(value) {}
368
373 StormByte::ByteSize Value() const noexcept {
374 return m_value;
375 }
376
377 private:
381 StormByte::ByteSize m_value;
382 };
383
389 public:
394 explicit BackPressure(const std::size_t value) noexcept:
395 m_value(value) {}
396
401 std::size_t Value() const noexcept {
402 return m_value;
403 }
404
405 private:
409 std::size_t m_value;
410 };
411
421 public:
425 ReaderParameters() = default;
426
432 template<typename... Knobs>
433 ReaderParameters(Knobs... knobs) {
434 (Apply(std::move(knobs)), ...);
435 }
436
441 ReaderParameters(const ReaderParameters& other) = default;
442
447 ReaderParameters(ReaderParameters&& other) noexcept = default;
448
452 ~ReaderParameters() noexcept = default;
453
459 ReaderParameters& operator=(const ReaderParameters& other) = default;
460
466 ReaderParameters& operator=(ReaderParameters&& other) noexcept = default;
467
472 const StormByte::Safe::Optional<StormByte::ByteSize>& ReadChunk() const noexcept {
473 return m_read_chunk;
474 }
475
481 return m_read_ahead;
482 }
483
489 return m_max_memory;
490 }
491
497 return m_max_wait;
498 }
499
500 private:
505 void Apply(class ReadChunk knob) {
506 m_read_chunk = knob.Value();
507 }
508
513 void Apply(class ReadAhead knob) {
514 m_read_ahead = knob.Value();
515 }
516
521 void Apply(class MaxMemory knob) {
522 m_max_memory = knob.Value();
523 }
524
529 void Apply(class MaxWait knob) {
530 m_max_wait = knob.Value().count();
531 }
532
537 template<typename Knob>
538 void Apply(Knob&&) = delete;
539
540 StormByte::Safe::Optional<StormByte::ByteSize> m_read_chunk;
544 StormByte::Safe::Optional<StormByte::ByteSize> m_read_ahead;
548 StormByte::Safe::Optional<StormByte::ByteSize> m_max_memory;
552 StormByte::Safe::Optional<std::chrono::milliseconds::rep> m_max_wait;
553 };
554
564 public:
568 WriterParameters() = default;
569
575 template<typename... Knobs>
576 WriterParameters(Knobs... knobs) {
577 (Apply(std::move(knobs)), ...);
578 }
579
584 WriterParameters(const WriterParameters& other) = default;
585
590 WriterParameters(WriterParameters&& other) noexcept = default;
591
595 ~WriterParameters() noexcept = default;
596
602 WriterParameters& operator=(const WriterParameters& other) = default;
603
609 WriterParameters& operator=(WriterParameters&& other) noexcept = default;
610
615 const StormByte::Safe::Optional<StormByte::ByteSize>& WriteTransfer() const noexcept {
616 return m_write_transfer;
617 }
618
624 return m_write_threshold;
625 }
626
632 return m_write_chunk;
633 }
634
640 return m_back_pressure;
641 }
642
648 return m_max_memory;
649 }
650
656 return m_max_wait;
657 }
658
659 private:
664 void Apply(class WriteTransfer knob) {
665 m_write_transfer = knob.Value();
666 }
667
672 void Apply(class WriteThreshold knob) {
673 m_write_threshold = knob.Value();
674 }
675
680 void Apply(class WriteChunk knob) {
681 m_write_chunk = knob.Value();
682 }
683
688 void Apply(class BackPressure knob) {
689 m_back_pressure = knob.Value();
690 }
691
696 void Apply(class MaxMemory knob) {
697 m_max_memory = knob.Value();
698 }
699
704 void Apply(class MaxWait knob) {
705 m_max_wait = knob.Value().count();
706 }
707
712 template<typename Knob>
713 void Apply(Knob&&) = delete;
714
715 StormByte::Safe::Optional<StormByte::ByteSize> m_write_transfer;
716 StormByte::Safe::Optional<StormByte::ByteSize> m_write_threshold;
720 StormByte::Safe::Optional<StormByte::ByteSize> m_write_chunk;
724 StormByte::Safe::Optional<std::size_t> m_back_pressure;
728 StormByte::Safe::Optional<StormByte::ByteSize> m_max_memory;
732 StormByte::Safe::Optional<std::chrono::milliseconds::rep> m_max_wait;
733 };
734 }
735 }
736}
737
749
Writer ring cap in WriteChunk units.
Definition parameters.hxx:388
BackPressure(const std::size_t value) noexcept
Store the cap in chunks.
Definition parameters.hxx:394
std::size_t Value() const noexcept
Cap in chunks.
Definition parameters.hxx:401
Cache / dirty-page budget knob.
Definition parameters.hxx:304
MaxMemory(const StormByte::ByteSize value) noexcept
Store the memory budget.
Definition parameters.hxx:310
StormByte::ByteSize Value() const noexcept
Memory budget.
Definition parameters.hxx:317
Origin wait cap.
Definition parameters.hxx:332
std::chrono::milliseconds Value() const noexcept
Wait cap.
Definition parameters.hxx:345
MaxWait(const std::chrono::milliseconds value) noexcept
Store the wait cap.
Definition parameters.hxx:338
Prefetch length knob.
Definition parameters.hxx:276
StormByte::ByteSize Value() const noexcept
Prefetch length.
Definition parameters.hxx:289
ReadAhead(const StormByte::ByteSize value) noexcept
Store the prefetch length.
Definition parameters.hxx:282
Maximum OriginPull request.
Definition parameters.hxx:78
StormByte::ByteSize Value() const noexcept
Requested transfer maximum.
Definition parameters.hxx:121
ReadChunk(StormByte::ByteSize value) noexcept
Store the requested transfer limit.
Definition parameters.hxx:84
ReadChunk(const ReadChunk &other) noexcept=default
Copy the limit.
~ReadChunk() noexcept=default
Destroy the non-owning limit.
ReadChunk(ReadChunk &&other) noexcept=default
Move the limit.
Optional reader knobs.
Definition parameters.hxx:420
const StormByte::Safe::Optional< std::chrono::milliseconds::rep > & MaxWait() const noexcept
Signed millisecond count when the caller set the wait cap.
Definition parameters.hxx:496
ReaderParameters(Knobs... knobs)
Engage the listed knobs.
Definition parameters.hxx:433
ReaderParameters(ReaderParameters &&other) noexcept=default
Transfer Safe-owned optional knobs.
~ReaderParameters() noexcept=default
Release optional knobs through provider callbacks.
ReaderParameters(const ReaderParameters &other)=default
Copy Safe-owned optional knobs; may allocate and throw.
const StormByte::Safe::Optional< StormByte::ByteSize > & ReadAhead() const noexcept
Prefetch length when the caller set it.
Definition parameters.hxx:480
const StormByte::Safe::Optional< StormByte::ByteSize > & MaxMemory() const noexcept
Cache cap when the caller set it.
Definition parameters.hxx:488
const StormByte::Safe::Optional< StormByte::ByteSize > & ReadChunk() const noexcept
Origin request maximum when the caller supplied it.
Definition parameters.hxx:472
Ring unit and drain trigger.
Definition parameters.hxx:360
StormByte::ByteSize Value() const noexcept
Chunk size.
Definition parameters.hxx:373
WriteChunk(const StormByte::ByteSize value) noexcept
Store the chunk size.
Definition parameters.hxx:366
Page drain high watermark.
Definition parameters.hxx:182
StormByte::ByteSize Value() const noexcept
Requested high watermark.
Definition parameters.hxx:225
WriteThreshold(WriteThreshold &&other) noexcept=default
Move the watermark.
WriteThreshold(const WriteThreshold &other) noexcept=default
Copy the watermark.
WriteThreshold(StormByte::ByteSize value) noexcept
Store the drain high watermark.
Definition parameters.hxx:188
~WriteThreshold() noexcept=default
Destroy the non-owning watermark.
Maximum OriginPush request in every mode.
Definition parameters.hxx:130
StormByte::ByteSize Value() const noexcept
Requested transfer maximum.
Definition parameters.hxx:173
~WriteTransfer() noexcept=default
Destroy the non-owning limit.
WriteTransfer(WriteTransfer &&other) noexcept=default
Move the limit.
WriteTransfer(const WriteTransfer &other) noexcept=default
Copy the limit.
WriteTransfer(StormByte::ByteSize value) noexcept
Store the transfer maximum.
Definition parameters.hxx:136
Optional writer knobs.
Definition parameters.hxx:563
const StormByte::Safe::Optional< StormByte::ByteSize > & MaxMemory() const noexcept
Dirty-page budget when the caller set it.
Definition parameters.hxx:647
WriterParameters(const WriterParameters &other)=default
Copy Safe-owned optional knobs; may allocate and throw.
const StormByte::Safe::Optional< StormByte::ByteSize > & WriteChunk() const noexcept
Chunk size when the caller set it.
Definition parameters.hxx:631
WriterParameters(Knobs... knobs)
Engage the listed knobs.
Definition parameters.hxx:576
WriterParameters(WriterParameters &&other) noexcept=default
Transfer Safe-owned optional knobs.
~WriterParameters() noexcept=default
Release optional knobs through provider callbacks.
const StormByte::Safe::Optional< StormByte::ByteSize > & WriteTransfer() const noexcept
Universal push maximum when the caller supplied it.
Definition parameters.hxx:615
const StormByte::Safe::Optional< std::size_t > & BackPressure() const noexcept
Backpressure when the caller set it.
Definition parameters.hxx:639
const StormByte::Safe::Optional< StormByte::ByteSize > & WriteThreshold() const noexcept
Page-drain watermark when the caller supplied it.
Definition parameters.hxx:623
const StormByte::Safe::Optional< std::chrono::milliseconds::rep > & MaxWait() const noexcept
Signed millisecond count when the caller set the wait cap.
Definition parameters.hxx:655
STORMBYTE_DECLARE_MAYBE_SAFE(class StormByte::System::Device::Access)
Buffered binary sources and sinks.
Buffer module of the StormByte suite.
Root namespace of the StormByte C++ suite.
Complete non-owning reader policy; scalar time crosses the DLL.
Definition parameters.hxx:234
StormByte::ByteSize ReadAhead
Prefetch target; zero disables.
Definition parameters.hxx:236
StormByte::ByteSize ReadChunk
Origin request maximum; zero selects 64 KiB.
Definition parameters.hxx:235
std::int64_t MaxWaitMilliseconds
Wait cap; zero is unlimited.
Definition parameters.hxx:238
StormByte::ByteSize MaxMemory
Page payload budget.
Definition parameters.hxx:237
Non-I/O snapshot.
Definition parameters.hxx:256
StormByte::ByteSize Bytes
Lifetime origin bytes.
Definition parameters.hxx:258
StormByte::ByteSize MaxRequest
Lifetime maximum request.
Definition parameters.hxx:260
StormByte::ByteSize LastRequest
Last hook request size.
Definition parameters.hxx:259
StormByte::ByteSize TransferLimit
Effective maximum; zero means unlimited.
Definition parameters.hxx:261
StormByte::ByteSize InFlight
Bytes requested in a current hook.
Definition parameters.hxx:267
StormByte::ByteSize Retained
Nonseekable reader replay outside pages.
Definition parameters.hxx:268
StormByte::ByteSize Pending
Queued/in-materialization payload.
Definition parameters.hxx:266
StormByte::ByteSize QueueCapacity
Logical ring admission capacity.
Definition parameters.hxx:264
StormByte::ByteSize RingCapacity
Actual ring allocation.
Definition parameters.hxx:263
StormByte::ByteSize Reconfiguration
Temporary replacement ring reservation.
Definition parameters.hxx:269
StormByte::ByteSize Threshold
Effective page drain watermark.
Definition parameters.hxx:265
std::size_t Calls
Lifetime real hook calls.
Definition parameters.hxx:257
StormByte::ByteSize PageCapacity
Page payload budget.
Definition parameters.hxx:262
Complete non-owning writer policy; Configure applies all fields together.
Definition parameters.hxx:244
std::int64_t MaxWaitMilliseconds
Wait cap; zero is unlimited.
Definition parameters.hxx:247
StormByte::ByteSize WriteChunk
Ring unit and drain trigger.
Definition parameters.hxx:245
std::size_t BackPressure
Ring capacity in chunk units.
Definition parameters.hxx:246
StormByte::ByteSize WriteThreshold
Drain high watermark; zero is pressure only.
Definition parameters.hxx:250
StormByte::ByteSize MaxMemory
Dirty page payload budget.
Definition parameters.hxx:248
StormByte::ByteSize WriteTransfer
Universal push maximum; zero is unlimited.
Definition parameters.hxx:249