Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Resource capacities

A resource can expose measured capacities. occupancy describes a quantity held over the usage span, such as bytes of memory held while a task runs.

YAML model

quent: alpha
model: resource_capacity

entities:
  Memory:
    resource:
      bytes:
        kind: occupancy
    events:
      created: {}

fsms:
  Task:
    states:
      running:
        initial: true
        attributes:
          memory: { uses: Memory }
        to: [completed]
      completed: {}

Declaring the bytes capacity generates a MemoryUsage record with a bytes field.

Instrumentation API

The task’s reference to Memory carries the quantity it claims.

use instrumentation::{Context, Memory, MemoryUsage, Noop, ResourceCapacity, Task};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let context = Context::<ResourceCapacity>::try_new(Noop)?;

    let mut memory = context.observer::<Memory>().handle();
    memory.created()?;

    let _task = context
        .observer::<Task>()
        .handle()
        .running(memory.as_entity_ref_with(MemoryUsage { bytes: 512_000_000 }))
        .completed();

    Ok(())
}
#include "quent-tutorial-resource-capacity-cpp-bridge/gen/quent.hpp"

int main() {
  auto context = quent::Context::none();
  auto memory = context.memory_observer()->handle();
  memory.created();

  auto running = context.task_observer()->handle().running(
      quent::task::Running{
          .memory = quent::refs::MemoryUsageRef{
              .target = memory.id(),
              .data = quent::records::MemoryUsage{
                  .bytes = 512'000'000,
              },
          },
      });
  auto completed = std::move(running).completed();
  return 0;
}
import quent_tutorial_resource_capacity as quent


def main() -> None:
    with quent.Context() as context:
        memory = context.memory_observer().handle()
        memory.created()

        task = context.task_observer().handle()
        running = task.running(
            memory={
                "target": memory,
                "data": {"bytes": 512_000_000},
            }
        )
        completed = running.completed()


if __name__ == "__main__":
    main()
Key point

A capacity resource records the quantity of a resource used by an entity.

Check yourself

What does an occupancy capacity measure?

Where is the task's claimed byte quantity declared?

Full code