FASTER
FASTER copied to clipboard
Publishing from different thread
In the PubSub example (https://github.com/microsoft/FASTER/blob/main/cs/samples/FasterLogPubSub/Program.cs) it has a consumer operating on a different thread, but is it possible to have the producer be on a different thread?
My use case is I have a consumer that I want to be able to truncate all the messages when it has consumed them. I want other running threads to be able to enqueue on the log.
The examples usually have a shared instance of the FasterLog, but that isn't possible for me as I have multiple running background processes that I would like to be able to enqueue onto the FasterLog.
private readonly FasterKV<byte[], byte[]> _store;
private readonly LogSettings _logSettings;
private readonly AsyncPool<
ClientSession<
byte[],
byte[],
byte[],
byte[],
Empty,
SimpleFunctions<byte[], byte[]>>> _sessionPool;
//....
sessionPool = new(
_logSettings.LogDevice.ThrottleLimit,
() => _store.For(new SimpleFunctions<byte[], byte[]>())
.NewSession<SimpleFunctions<byte[], byte[]>>());
//....
// in method
if (_sessionPool.TryGet(out var session) == false)
session = _sessionPool.Get();
var status = session.Upsert(key, value);
if (status.IsPending)
session.CompletePending(true, true);
_sessionPool.Return(session);