Skip to content

BoundedSourceQueue API#29770

Merged
johanandren merged 2 commits into
akka:masterfrom
seglo:seglo/faster-drop-new-queue
Nov 6, 2020
Merged

BoundedSourceQueue API#29770
johanandren merged 2 commits into
akka:masterfrom
seglo:seglo/faster-drop-new-queue

Conversation

@seglo

@seglo seglo commented Oct 21, 2020

Copy link
Copy Markdown
Contributor

Based on @jrudolph's FastDroppingQueue implementation in #29574

A new queue implementation that drops new elements immediately when the buffer is full. Does not use async callbacks like Source.queue with OverflowStrategy.dropNew, which can still result in OOM errors (#25798).

Other "drop" scenarios (dropTail, dropHead) may be supported by this implementation if their use can be justified.

@seglo seglo force-pushed the seglo/faster-drop-new-queue branch from 4cac2d6 to 0cfda82 Compare October 21, 2020 21:48
@akka-ci akka-ci added the validating PR is currently being validated by Jenkins label Oct 21, 2020
@seglo seglo force-pushed the seglo/faster-drop-new-queue branch from 0cfda82 to e746bc5 Compare October 21, 2020 21:50
@akka-ci akka-ci added needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed validating PR is currently being validated by Jenkins labels Oct 21, 2020
@akka-ci

akka-ci commented Oct 21, 2020

Copy link
Copy Markdown

Test FAILed.

1 similar comment
@akka-ci

akka-ci commented Oct 21, 2020

Copy link
Copy Markdown

Test FAILed.

Comment thread akka-stream/src/main/scala/akka/stream/scaladsl/Source.scala Outdated
@seglo seglo changed the title DroppingQueueSource API BoundedQueueSource API Oct 22, 2020
@akka-ci akka-ci added validating PR is currently being validated by Jenkins needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) validating PR is currently being validated by Jenkins labels Oct 22, 2020
@akka-ci

akka-ci commented Oct 22, 2020

Copy link
Copy Markdown

Test FAILed.

@seglo seglo force-pushed the seglo/faster-drop-new-queue branch from 3a48a4a to 66da0be Compare October 22, 2020 22:24
@akka-ci akka-ci added validating PR is currently being validated by Jenkins needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) validating PR is currently being validated by Jenkins labels Oct 22, 2020
@akka-ci

akka-ci commented Oct 22, 2020

Copy link
Copy Markdown

Test FAILed.

@seglo seglo force-pushed the seglo/faster-drop-new-queue branch from 66da0be to 44aead2 Compare October 23, 2020 01:50
@akka-ci akka-ci added validating PR is currently being validated by Jenkins needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) validating PR is currently being validated by Jenkins labels Oct 23, 2020
@akka-ci

akka-ci commented Oct 23, 2020

Copy link
Copy Markdown

Test FAILed.

@raboof raboof left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking good overall!

Comment thread akka-docs/src/main/paradox/stream/operators/Source/queue.md Outdated
Comment thread akka-stream-tests/src/test/scala/akka/stream/scaladsl/QueueSourceSpec.scala Outdated
Comment thread akka-docs/src/main/paradox/stream/operators/Source/queue.md Outdated
Comment thread akka-docs/src/test/java/jdocs/stream/IntegrationDocTest.java Outdated
Comment thread akka-docs/src/test/scala/docs/stream/IntegrationDocSpec.scala Outdated
Comment thread akka-docs/src/test/scala/docs/stream/IntegrationDocSpec.scala Outdated
Comment thread akka-docs/src/main/paradox/stream/operators/Source/queue.md Outdated
new Source(
scaladsl.Source.queue[T](bufferSize, overflowStrategy, maxConcurrentOffers).mapMaterializedValue(_.asJava))
overflowStrategy match {
case _: OverflowStrategies.DropNew => queue[T](bufferSize).mapMaterializedValue(_.asJavaSourceQueue())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are we sure that we want to change the queue implementation for DropNew? It's probably much better, but the change in behavior could impact users. I think we should consider deprecating this version of Source.queue instead and promote the new method instead. The deprecation could come in a separate PR (possibly later release) since we probably want to provide a good alternative replacement for at least Backpressure strategy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll revert this change.

In the future I suggest we deprecate these two overloads altogether (with a backpressure and "fail" strategy alternative). We can't deprecate OverflowStrategies.DropNew because it's used in Source.actorRef as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

and we might not need a fail strategy because that can be a decision for the caller (and implemented together with a KillSwitch)

@akka-ci akka-ci added the validating PR is currently being validated by Jenkins label Oct 28, 2020
@akka-ci akka-ci removed the validating PR is currently being validated by Jenkins label Nov 2, 2020
@akka-ci

akka-ci commented Nov 2, 2020

Copy link
Copy Markdown

Test PASSed.

@johanandren johanandren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking good, some small things noted.

Comment thread akka-docs/src/main/paradox/stream/operators/Source/queue.md Outdated
Comment thread akka-docs/src/test/scala/docs/stream/IntegrationDocSpec.scala Outdated
Comment thread akka-stream/src/main/scala/akka/stream/BoundedQueueSource.scala Outdated
Comment thread akka-stream/src/main/scala/akka/stream/QueueOfferResult.scala
Comment thread akka-stream/src/main/scala/akka/stream/impl/BoundedQueueSource.scala Outdated

@jrudolph jrudolph left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for doing this work, @seglo! I mostly looked at the documentation. I guess my biggest non-cosmetic suggestion is to rename BoundedQueueSource to BoundedSourceQueue...

Comment thread akka-docs/src/main/paradox/stream/operators/index.md Outdated
# Source.queue

Materialize a `SourceQueue` onto which elements can be pushed for emitting from the source.
Materialize a `SourceQueue` or `BoundedSourceQueue` onto which elements can be pushed synchronously or asynchronously for emitting from the source.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here's a suggestion of giving an overview about the options right away (I found the distinction between synchronous and asynchronous not really descriptive as a user coming to this page):

Suggested change
Materialize a `SourceQueue` or `BoundedSourceQueue` onto which elements can be pushed synchronously or asynchronously for emitting from the source.
Materialize a `BoundedSourceQueue` or `SourceQueue` onto which elements can be pushed for emitting from the source.
The `BoundedSourceQueue` is an optimized variant of the `SourceQueue` with `OverflowStrategy.dropNew`. The `BoundedSourceQueue` will give immediate, synchronous feedback whether an element was accepted or not and is therefore recommended for situations where overload and dropping elements is expected and needs to be handled quickly.
In contrast, the `SourceQueue` offers more variety of `OverflowStrategies` but feedback is only asynchronously provided through a @scala[`Future`]@java[`CompletionStage`] value. In cases where elements need to be discarded quickly at times of overload to avoid out-of-memory situations, delivering feedback asynchronously can itself become a problem. This happens if elements come in faster than the feedback can be delivered in which case the feedback mechanism itself is part of the reason that an out-of-memory situation arises.
In summary, prefer `BoundedSourceQueue` over `SourceQueue` with `OverflowStrategy.dropNew` especially in high-load scenarios. Use `SourceQueue` if you need one of the other `OverflowStrategies`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I initially had more content above the fold like you suggested, but a docs post-processing step didn't like it. I'll take another look to see if I can make that work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It looks like a rule was explicitly created to keep the description one line (to keep it short).

https://github.com/akka/akka/blob/master/project/StreamOperatorsIndexGenerator.scala#L244-L248

I like your description though, so I'll try to make it work with the rule intact.

Comment thread akka-docs/src/main/paradox/stream/operators/Source/queue.md Outdated
Comment thread akka-docs/src/main/paradox/stream/operators/Source/queue.md Outdated
/**
* A queue of the given size that gives immediate feedback whether an element could be enqueued or not.
*/
trait BoundedQueueSource[T] {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not BoundedSourceQueue? After all, it's not a source but a queue and that would also be consistent with the existing naming? (I just realized that I confused those also above in my docs suggestions).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Btw. I think it would be fine if a BoundedQueueSource(Stage) would provide a BoundedSourceQueue. After all these are two opposite ends of looking at the component.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I renamed BoundedQueueSource to BoundedSourceQueue. I changed the stage too just to make it consistent.

Comment thread akka-stream/src/main/scala/akka/stream/javadsl/Source.scala Outdated
Comment thread akka-stream/src/main/scala/akka/stream/javadsl/Source.scala
Comment thread akka-stream/src/main/scala/akka/stream/javadsl/Source.scala Outdated
Comment thread akka-stream/src/main/scala/akka/stream/javadsl/Source.scala Outdated
@jrudolph

jrudolph commented Nov 5, 2020

Copy link
Copy Markdown
Contributor

LMK if this is acceptable @patriknw, @jrudolph.

Of course, thanks a lot for bringing that over the finish line.

@seglo

seglo commented Nov 5, 2020

Copy link
Copy Markdown
Contributor Author

I guess my biggest non-cosmetic suggestion is to rename BoundedQueueSource to BoundedSourceQueue

I originally used that convention, but I changed it to what it is now for some reason. I'll make it BoundedSourceQueue.

👍

@seglo seglo force-pushed the seglo/faster-drop-new-queue branch from 52d28f1 to e2d1484 Compare November 5, 2020 18:51
@seglo seglo changed the title BoundedQueueSource API BoundedSourceQueue API Nov 5, 2020
@akka-ci akka-ci added validating PR is currently being validated by Jenkins and removed tested PR that was successfully built and tested by Jenkins labels Nov 5, 2020
@seglo

seglo commented Nov 5, 2020

Copy link
Copy Markdown
Contributor Author

@johanandren @jrudolph Thanks for the thorough review. I accommodated almost all of your feedback. I'll be away next week, but feel free to push commits if necessary to have this completed this sprint.

@akka-ci akka-ci added needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed validating PR is currently being validated by Jenkins labels Nov 5, 2020
@akka-ci

akka-ci commented Nov 5, 2020

Copy link
Copy Markdown

Test FAILed.

@seglo seglo force-pushed the seglo/faster-drop-new-queue branch from e2d1484 to 779161d Compare November 5, 2020 19:06
@akka-ci akka-ci added validating PR is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) validating PR is currently being validated by Jenkins labels Nov 5, 2020
@akka-ci

akka-ci commented Nov 5, 2020

Copy link
Copy Markdown

Test PASSed.

@johanandren

Copy link
Copy Markdown
Contributor

Given that you are away next week, and @jrudolph is away today, let's merge this and follow up with fixes if J has any more feedback when back next week.

@johanandren johanandren merged commit 2b8d0b2 into akka:master Nov 6, 2020
@johanandren johanandren added this to the 2.6.11 milestone Nov 6, 2020
@seglo

seglo commented Nov 6, 2020

Copy link
Copy Markdown
Contributor Author

Sounds good. Thanks @johanandren 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tested PR that was successfully built and tested by Jenkins

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants