---
version: 1

description: >
  Example load-generating service for resource sizing. On every incoming
  message it runs a CPU-intensive transform (generate a numeric series, sort
  it, and compute statistics), then aggregates the results into bursts. Drive
  the input topic with an MQTT publisher to produce steady CPU load on the
  Protocol Mapper. Raise the series length to increase the load per message.

metadata:
  name: Resource Sizing Load Example

resources:
  # Heavy per-message transform: builds a series of 5000 numbers, sorts it,
  # and derives statistics. Sorting dominates the CPU cost. Raise the series
  # length (the 5000 values) to push more CPU work onto the Protocol Mapper.
  transformMapping:
    type: Cybus::Mapping
    properties:
      mappings:
        - subscribe:
            topic: !sub '${Cybus::MqttRoot}/raw'
          publish:
            topic: !sub '${Cybus::MqttRoot}/processed'
          rules:
            - transform:
                expression: |
                  ($v := $number(value);
                  {
                    "value": $v,
                    "sortedTop5": $reverse($sort([1..5000].($ * $v)))[[0..4]]
                  })

  # Aggregates the processed stream into bursts, exercising buffering and
  # serialization in the Protocol Mapper.
  burstMapping:
    type: Cybus::Mapping
    properties:
      mappings:
        - subscribe:
            topic: !sub '${Cybus::MqttRoot}/processed'
          publish:
            topic: !sub '${Cybus::MqttRoot}/batched'
          rules:
            - burst:
                interval: 1000
                maxSize: 100
