Class ConsumerSpec

java.lang.Object
org.acemq.workloads.ConsumerSpec

public final class ConsumerSpec extends Object
How the load is consumed.

 .consumers(c -> c
         .concurrency(8)
         .prefetch(100)
         .handlerTime(Duration.ofMillis(2)))
 

handlerTime(Duration) is the part people leave out and then wonder why the results do not resemble production. A consumer that does nothing measures the broker; a consumer that sleeps two milliseconds measures the broker and what happens when the application is the slow part — which is the situation almost every real system is in.

  • Method Details

    • concurrency

      public ConsumerSpec concurrency(int concurrency)
      Parameters:
      concurrency - how many consumers to attach
      Returns:
      this spec
    • prefetch

      public ConsumerSpec prefetch(int prefetch)
      How many unacknowledged messages a consumer will hold.

      The most consequential number here, and the one most often left at a default that is wrong in both directions. Too low and the consumer waits on the network between messages; too high and one consumer takes the whole queue while its peers idle, and a restart redelivers all of it.

      Parameters:
      prefetch - the limit, or 0 for unlimited
      Returns:
      this spec
    • handlerTime

      public ConsumerSpec handlerTime(Duration handlerTime)
      Simulated work per message.

      Implemented as a sleep, which models a handler waiting on a database or an HTTP call — the common case. It does not model a handler that is CPU-bound, because a sleeping thread does not compete for a core the way a busy one does.

      Parameters:
      handlerTime - how long each message takes to process
      Returns:
      this spec
    • failureRate

      public ConsumerSpec failureRate(double fraction)
      A fraction of messages the handler rejects.

      For exercising retry and dead-lettering under load, which is where those paths behave least like they do in a unit test.

      Parameters:
      fraction - between 0 and 1
      Returns:
      this spec
    • none

      public ConsumerSpec none()
      Runs with no consumers at all.

      A publish-only workload. Useful for measuring ingest and for filling a queue before a separate drain test — and note that end-to-end latency cannot be measured without a consumer, so the report will say so rather than showing zeroes.

      Returns:
      this spec
    • concurrency

      public int concurrency()
    • prefetch

      public int prefetch()
    • handlerTime

      public Duration handlerTime()
    • failureRate

      public double failureRate()
    • isEnabled

      public boolean isEnabled()
    • toString

      public String toString()
      Overrides:
      toString in class Object