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

Akka.Streams: FileIO sinks don't flush until completed #4851

Closed
Aaronontheweb opened this issue Mar 15, 2021 · 0 comments · Fixed by #4859
Closed

Akka.Streams: FileIO sinks don't flush until completed #4851

Aaronontheweb opened this issue Mar 15, 2021 · 0 comments · Fixed by #4859

Comments

@Aaronontheweb
Copy link
Member

Version: 1.4.17

The Akka.Streams FileIO sink stages have a design flaw:

.With<OnNext>(next =>
{
try
{
var byteString = (ByteString) next.Element;
var bytes = byteString.ToArray();
_chan.Write(bytes, 0, bytes.Length);
_bytesWritten += bytes.Length;
}

Unlike the OutputStreamSubscriber, the FileSubscriber actor can't periodically flush data onto disk during the course of writing streaming output to a file - thus 100% of file content is retained in memory. This can be disastrous for applications writing any non-trivially large file.

We should, instead, use the OutputStreamSubscriber implementation and allow it to automatically flush periodically:

Actor.Props.Create(() => new OutputStreamSubscriber(os, completionPromise, bufferSize, autoFlush))

We could also expose a command that could be injected from the outside to force flushing in accordance with specific domain rules specific to the user's application, but that might be a subject to a separate issue from this one.

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

Successfully merging a pull request may close this issue.

1 participant