_Alignas(64) uint8_t kru[];
};
struct defer *defer = NULL;
+bool defer_initialized = false;
struct mmapped defer_mmapped = {0};
defer_sample_state_t defer_sample_state = {
/// Initialize shared memory, queues. To be called from Lua.
int defer_init(const char *mmap_file, int cpus)
{
+ defer_initialized = true;
+ if (mmap_file == NULL) {
+ // defer explicitly disabled
+ return 0;
+ }
+
int ret = 0;
if (cpus < 1) {
ret = EINVAL;
#include "lib/kru.h"
/// Initialize defer, incl. shared memory with KRU, excl. idle.
-/// To be called from Lua; defer is disabled by default otherwise.
KR_EXPORT
int defer_init(const char *mmap_file, int cpus);
extern defer_sample_state_t defer_sample_state;
extern struct defer *defer; /// skip sampling/deferring if NULL
+extern bool defer_initialized; /// defer_init was called, possibly keeping defer disabled
// TODO: reconsider `static inline` cases below
lua_settop(the_engine->L, 0);
}
+ if (!defer_initialized) {
+ kr_log_warning(SYSTEM, "Prioritization not initialized from Lua, using hardcoded default.");
+ ret = defer_init("defer", 1);
+ if (ret) {
+ ret = EXIT_FAILURE;
+ goto cleanup;
+ }
+ }
+
if (defer_init_idle(loop) != 0) {
ret = EXIT_FAILURE;
goto cleanup;
},
"default": null
},
+ "defer": {
+ "description": "Configuration of request prioritization (defer).",
+ "type": "object",
+ "properties": {
+ "enabled": {
+ "type": "boolean",
+ "description": "Use request prioritization.",
+ "default": true
+ }
+ },
+ "default": {
+ "enabled": true
+ }
+ },
"lua": {
"description": "Custom Lua configuration.",
"type": "object",
from knot_resolver.datamodel.network_schema import NetworkSchema
from knot_resolver.datamodel.options_schema import OptionsSchema
from knot_resolver.datamodel.rate_limiting_schema import RateLimitingSchema
+from knot_resolver.datamodel.defer_schema import DeferSchema
from knot_resolver.datamodel.templates import POLICY_CONFIG_TEMPLATE, WORKER_CONFIG_TEMPLATE
from knot_resolver.datamodel.types import EscapedStr, IntPositive, WritableDir
from knot_resolver.datamodel.view_schema import ViewSchema
monitoring: Metrics exposisition configuration (Prometheus, Graphite)
lua: Custom Lua configuration.
rate_limiting: Configuration of rate limiting.
+ defer: Configuration of request prioritization (defer).
"""
version: int = 1
logging: LoggingSchema = LoggingSchema()
monitoring: MonitoringSchema = MonitoringSchema()
rate_limiting: Optional[RateLimitingSchema] = None
+ defer: DeferSchema = DeferSchema()
lua: LuaSchema = LuaSchema()
_LAYER = Raw
logging: LoggingSchema
monitoring: MonitoringSchema
rate_limiting: Optional[RateLimitingSchema]
+ defer: DeferSchema
lua: LuaSchema
def _hostname(self, obj: Raw) -> Any:
--- /dev/null
+from knot_resolver.utils.modeling import ConfigSchema
+
+
+class DeferSchema(ConfigSchema):
+ """
+ Configuration of request prioritization (defer).
+
+ ---
+ enabled: Use request prioritization.
+ """
+
+ enabled: bool = True
--- /dev/null
+{% from 'macros/common_macros.lua.j2' import boolean %}
+
+{% if cfg.defer.enabled and not disable_defer -%}
+assert(C.defer_init(
+ '{{ cfg.rundir }}/defer',
+ {{ cfg.workers }}) == 0)
+{% else %}
+assert(C.defer_init(nil, 0) == 0)
+{%- endif %}
-- FORWARD section ----------------------------------
{% include "forward.lua.j2" %}
+-- DEFER section ------------------------------------
+{% set disable_defer = true %}
+{% include "defer.lua.j2" %}
+
+
{% endif %}
quit()
-- RATE-LIMITING section ------------------------------------
{% include "rate_limiting.lua.j2" %}
+-- DEFER section ------------------------------------
+{% include "defer.lua.j2" %}
+
{% endif %}
-- LUA section --------------------------------------
async def validate_config(self, _old: KresConfig, new: KresConfig) -> Result[NoneType, str]:
async with self._manager_lock:
if _old.rate_limiting != new.rate_limiting:
- logger.debug("Unlinking shared RRL memory")
+ logger.debug("Unlinking shared ratelimiting memory")
try:
os.unlink(str(_old.rundir) + "/ratelimiting")
except FileNotFoundError:
pass
+ if _old.workers != new.workers or _old.defer != new.defer:
+ logger.debug("Unlinking shared defer memory")
+ try:
+ os.unlink(str(_old.rundir) + "/defer")
+ except FileNotFoundError:
+ pass
logger.debug("Testing the new config with a canary process")
try:
# technically, this has side effects of leaving a new process runnning