Class Payload

java.lang.Object
org.acemq.workloads.Payload

public final class Payload extends Object
The bytes a workload publishes, and the header this library needs inside them.

Every message carries a 16-byte prefix: the intended send time in nanoseconds, and a sequence number. Both are read back by the consumer.

Why the intended time and not the actual one

This is the difference between a latency number that is true and one that flatters the broker.

Suppose the schedule says publish at t=0, 1ms, 2ms, 3ms, and the broker stalls for 100ms after the first. A generator that timestamps at the moment of the actual send records four messages that each took a millisecond or two: the stall is invisible, because the generator was stalled with it and never offered the load it was supposed to. That is coordinated omission, and it makes latency look better the worse the broker behaves.

Timestamping the moment the message was due records 100ms, 99ms, 98ms, 97ms — which is what a client waiting on that schedule actually experienced.

  • Field Details

    • HEADER_BYTES

      public static final int HEADER_BYTES
      Two longs: the intended send time and the sequence number.
      See Also:
  • Method Details

    • ofBytes

      public static Payload ofBytes(int size)
      Parameters:
      size - total message size in bytes, including the 16-byte header
      Returns:
      a payload of zero-filled bytes after the header
    • ofRandomBytes

      public static Payload ofRandomBytes(int size)
      Random bytes after the header.

      Worth using when anything downstream compresses or deduplicates. A run of zeroes compresses to nothing, and a broker or network that compresses will report a throughput that no real payload will reproduce.

      Parameters:
      size - total message size in bytes
      Returns:
      a payload of random bytes after the header
    • size

      public int size()
      Returns:
      the message size in bytes
    • isRandom

      public boolean isRandom()
      Returns:
      whether the body after the header is random rather than zeroes
    • build

      public byte[] build(long intendedSendNanos, long sequence)
      Builds one message body.
      Parameters:
      intendedSendNanos - when this message was due, from System.nanoTime()
      sequence - the message's sequence number within its publisher
      Returns:
      the body
    • intendedSendNanos

      public static long intendedSendNanos(byte[] body)
      Parameters:
      body - a message built by build(long, long)
      Returns:
      the time the message was due, in System.nanoTime() terms
    • sequence

      public static long sequence(byte[] body)
      Parameters:
      body - a message built by build(long, long)
      Returns:
      its sequence number
    • isWorkloadMessage

      public static boolean isWorkloadMessage(byte[] body)
      Parameters:
      body - a received body
      Returns:
      whether it is long enough to have been produced by this library. A queue with messages from somewhere else in it would otherwise produce nonsense latencies rather than an obvious failure
    • toString

      public String toString()
      Overrides:
      toString in class Object