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

MQTT streaming: Retire ask in favour of promise #1304

Merged
merged 1 commit into from
Nov 5, 2018
Merged

Conversation

huntc
Copy link
Contributor

@huntc huntc commented Nov 4, 2018

The ask pattern is overkill for situations where there is a strong coupling between one actor and another, as is the case between an MQTT session and its many command and event flows. For instance, if an MQTT session actor is lost for any reason, then its associated flows will also be failed. In this scenario, where a flow notifies the session of, say, an event having been received, it is effectively “calling” the session actor as per a function call, but using a message. The request is effectively synchronous in nature (although there is no blocking of course). The session actor must promise to yield a result, no matter what. Not yielding a result is a bug.

As such, we can use promises instead of the ask pattern for tightly coupled callers calling on actors. This then yields the advantage that request/reply timeouts do not have to be considered. Indeed, a strong motivation for the retirement of ask here is that it is difficult to determine a default timeout value. The performance of the MQTT session on a single core processor with memory constraints is quite different to that of a quad core with enormous amounts of memory. Timeouts perhaps make more sense when considering networks, where request/reply is required instead of a synchronous one.

Thanks to @longshorej for motivating this change and his thoughts on when to use the synchronous call pattern in place of ask.

The ask pattern is overkill for situations where there is a strong coupling between one actor and another, as is the case between an MQTT session and its many command and event flows. For instance, if an MQTT session actor is lost for any reason, then its flows will also be failed. In this scenario, where a flow notifies the session of, say, an event having been received, it is effectively “calling” the session actor as per a function call, but using a message. The request is effectively synchronous in nature (although there is no blocking of course). The session actor must promise to yield a result, no matter what. Not yielding a result is a bug.

As such, we can use promises instead of the ask pattern for tightly coupled callers calling on actors. This then yields the advantage that request/reply timeouts do not have to be considered. Indeed, a strong motivation for the retirement of ask here is that it is difficult to determine a default timeout value. The performance of the MQTT session on a single core processor with memory constraints is quite different to that of a quad core with enormous amounts of memory. Timeouts perhaps make more sense when considering networks, where request/reply is required instead of a synchronous call.

Thanks to Jason Longshore for motivating this change and his thoughts on when to use the synchronous call pattern in place of ask.
@@ -253,7 +253,8 @@ import scala.util.{Failure, Success}
Subscriber(subscribeData, remote, data.subscriberPacketRouter, data.settings),
subscriberName
)
case _: Some[_] => // Ignored for existing subscriptions
case _: Some[_] =>
remote.failure(new IllegalStateException("Duplicate subscribe: " + subscribe))
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Member

@ennru ennru left a comment

Choose a reason for hiding this comment

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

LGTM.

@ennru ennru changed the title Retire ask in favour of promise MQTT streaming: Retire ask in favour of promise Nov 5, 2018
@ennru ennru merged commit cd37c4c into akka:master Nov 5, 2018
@ennru ennru added this to the 1.0-M2 milestone Nov 5, 2018
@huntc huntc deleted the promises branch November 5, 2018 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants