Maximum number of Event classifiers for my defined Pub/Sub

scala
akka

(Onyancha Chrispinus) #1

I am working on an Akka service for my platform.

I would like to get your guidance on the question below.

What is the maximum number of Classifiers that can be set a go on my custom EventBus implementation.

override protected def mapSize: Int = 128

​If i have 10,000 classifiers, am i allowed to change the 128 to 10,000? If yes what is the implication. ​

class LookupBusImpl extends EventBus with LookupClassification {

  type Event = MsgEnvelope
  type Classifier = String
  type Subscriber = ActorRef

  // is used for extracting the classifier from the incoming events
  override protected def classify(event: Event): Classifier = event.topic

  // will be invoked for each event for all subscribers which registered themselves
  // for the event’s classifier
  override protected def publish(event: Event, subscriber: Subscriber): Unit = {
    subscriber ! event.payload
  }

  // must define a full order over the subscribers, expressed as expected from
  // `java.lang.Comparable.compare`
  override protected def compareSubscribers(a: Subscriber, b: Subscriber): Int =
    a.compareTo(b)

  // determines the initial size of the index data structure
  // used internally (i.e. the expected number of different classifiers)
  override protected def mapSize: Int = 128

}

(Johan Andrén) #2

The classifier must be a power of 2, so 10 000 would not be a valid value, 16 384 would be the closest 2 factor above 10 000.

The classification will loop through the subscribers for the extracted classification on every published event so that may be costly if you have a large amount of subscribers for the same classifier. If it is too costly depends on you application, so you should benchmark for the number and distribution of subscribers you expect.


(Onyancha Chrispinus) #3

Thanks for your feedback @johanandren. I am happy to learn about this and will do the necessary improvements to my solution.

Just something else that was not very clear, What would be the possible maximum number of classifiers I could set? My classifiers are created dynamically and so would like to know a maximum number that would not hinder performance.