Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid overflow of index #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object ImmutableRoundRobin {

private def activeRoutingBehavior[T](index: Long, workers: Vector[ActorRef[T]]): Behavior[T] =
Actor.immutable[T] { (ctx, msg) =>
workers((index % workers.size).toInt) ! msg
workers(abs(index % workers.size).toInt) ! msg
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a Long so you would have to run for very long before you wrap around (292471 years if the throughput is 1M msg/s)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's all about correctness. And who knows, in the past numeric ranges have been underestimated several times ;-)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright, then update to the more correct https://github.com/akka/akka/blob/master/akka-actor/src/main/scala/akka/routing/RoundRobin.scala#L30
otherwise it will not be strict round robin when wrapping around

also update other code: MutableRoundRobin.scala, ImmutableRoundRobin.java, MutableRoundRobin.java

Thanks

activeRoutingBehavior(index + 1, workers)
}
}
Expand Down