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

[C#] FasterLog - tailing iterator from different process #332

Closed
AlgorithmsAreCool opened this issue Sep 16, 2020 · 8 comments · Fixed by #333
Closed

[C#] FasterLog - tailing iterator from different process #332

AlgorithmsAreCool opened this issue Sep 16, 2020 · 8 comments · Fixed by #333
Labels
enhancement New feature or request

Comments

@AlgorithmsAreCool
Copy link

Can FasterLog be used by multiple processes in any configuration?

My primary use case would be a single Writer Process and a single Reader Process.

I'm ok with the reader being truly read-only and not being able to truncate.

@badrishc
Copy link
Contributor

Sure, that should be doable, you just need to recover from the second process and perform the iteration there. To refresh the latest updates, you would need to "recover" again to the latest commit.

@AlgorithmsAreCool
Copy link
Author

That is ideal! I needed to be able to progressively read from the log and was hoping for something like this.

Just to be clear, I'm assuming that truncating or writing from the 2nd process is not supported, correct?

@badrishc
Copy link
Contributor

badrishc commented Sep 16, 2020

To be clear, the basic underlying capability is there but is not exposed or supported out of the box right now. I tried to play around and it works but will need some effort to convert into a supported feature.

Work in branch: fasterlog-separate-scan
See working sample here: https://github.com/microsoft/FASTER/blob/fasterlog-separate-scan/cs/samples/FasterLogPubSub/Program.cs

@badrishc
Copy link
Contributor

I'm assuming that truncating or writing from the 2nd process is not supported, correct?

That is correct. The reader gets a read-only view of the log.

@badrishc badrishc added the enhancement New feature or request label Sep 16, 2020
@badrishc
Copy link
Contributor

Marking this as feature request/enhancement based on this work.

@badrishc badrishc changed the title [Question] [C#] Is FasterLog and multiple processes [C#] FasterLog - tailing iterator from different process Sep 16, 2020
@badrishc
Copy link
Contributor

It's now in relatively stable state - but still in branch. Feel free to play with the sample to see if that is what you had in mind. Log truncation right now needs to be handled by the primary owner (writer), as it is the point of truth for the log.

The way we expose the reading capability in the second process is summarized in the code snippet below:

static async Task SeparateConsumerAsync(CancellationToken cancellationToken)
{
    var device = Devices.CreateLogDevice(path + "mylog");
    var log = new FasterLog(new FasterLogSettings { LogDevice = device, ReadOnlyMode = true, PageSizeBits = 9, SegmentSizeBits = 9 });
    var _ = RecoverAsync(log, cancellationToken);

    using var iter = log.Scan(log.BeginAddress, long.MaxValue);

    await foreach (var (result, length, currentAddress, nextAddress) in iter.GetAsyncEnumerable(cancellationToken))
    {
        Console.WriteLine($"Consuming {Encoding.UTF8.GetString(result)}");
        iter.CompleteUntil(nextAddress);
    }
}

static async Task RecoverAsync(FasterLog log, CancellationToken cancellationToken)
{
    while (!cancellationToken.IsCancellationRequested)
    {
        await Task.Delay(TimeSpan.FromMilliseconds(restorePeriodMs), cancellationToken);

        Console.WriteLine("Restoring ...");

        log.RecoverReadOnly();
    }
}

@AlgorithmsAreCool
Copy link
Author

Goodness you are fast 🤯

I'm looking forward to seeing saturating my disk IO testing this out!

@badrishc
Copy link
Contributor

The linked sample will probably have overheads due to string encoding and decoding. Using byte arrays or spans as in this sample is best for perf/benchmarking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants