-
Notifications
You must be signed in to change notification settings - Fork 230
IpcDisruptor
Olivier Coanet edited this page Sep 7, 2025
·
1 revision
The IpcDisruptor is built on a value-type-based ring buffer stored in a shared memory-mapped file. This design allows the IpcDisruptor to support remote publication, i.e., event publication from other processes on the same machine.
Because the IpcDisruptor uses value type events, it also benefits from the same performance improvements as the ValueDisruptor.
In addition to the expected IpcDisruptor<T>
and IpcRingBuffer<T>
types, the IPC API exposes the following types:
-
IpcRingBufferMemory
: represents the shared memory of the IPC components. -
IpcPublisher<T>
: allows publishing events to anIpcRingBufferMemory
.
Disruptor setup:
// Creates an IpcDisruptor based on a shared memory created in a temporary directory.
// The shared memory directory is automatically deleted when the disruptor is disposed.
await using var disruptor = new IpcDisruptor<IpcEvent>(1024);
disruptor.HandleEventsWith(new Handler());
await disruptor.Start();
Console.WriteLine($"IpcDirectoryPath: {disruptor.IpcDirectoryPath}");
Publisher setup:
using var publisher = new IpcPublisher<IpcEvent>(ipcDirectoryPath);
using (var scope = publisher.PublishEvent())
{
scope.Event().Value = 101;
}
Disruptor setup:
using var memory = IpcRingBufferMemory.Create<IpcEvent>(ipcDirectoryPath, 1024);
await using var disruptor = new IpcDisruptor<IpcEvent>(memory);
disruptor.HandleEventsWith(new Handler());
await disruptor.Start();
Publisher setup:
using var publisherMemory = IpcRingBufferMemory.Open<IpcEvent>(ipcDirectoryPath);
using var publisher = new IpcPublisher<IpcEvent>(publisherMemory);
using (var scope = publisher.PublishEvent())
{
scope.Event().Value = 101;
}
- The IpcDisruptor has the same design as the regular disruptors, but the concurrent data structures are stored in a shared memory-mapped file (ring buffer, availability buffer, sequences).
- The IpcDisruptor can generate a limited number of sequences, and thus can only support a limited number of event handlers. The sequence pool capacity can be configured when creating
IpcRingBufferMemory
and the default value is 64. Note:maximumEventHandlerCount = sequencePoolCapacity - 1
, because one sequence is reserved for the ring buffer cursor.