Wjybxx.Disruptor
1.1.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Wjybxx.Disruptor --version 1.1.0
NuGet\Install-Package Wjybxx.Disruptor -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Wjybxx.Disruptor" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Wjybxx.Disruptor --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Wjybxx.Disruptor, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Wjybxx.Disruptor as a Cake Addin #addin nuget:?package=Wjybxx.Disruptor&version=1.1.0 // Install Wjybxx.Disruptor as a Cake Tool #tool nuget:?package=Wjybxx.Disruptor&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Disruptor模块
LMAX-Disruptor的C#精简实现,保留其核心设计,更好的抽象和扩展性。
先上架构图:
与LMAX的Disruptor差异
- RingBuffer仅是数据结构,没有额外的职责。
- Sequencer是协调的集成,而不是生产者屏障,生产者屏障有明确的抽象。
- 协调的基本单位是屏障
Barrier
,依赖的单位也是屏障,而不是序列Sequence
。 - 反转了Barrier和Consumer之间的Sequence依赖。
- 剥离了Blocker和WaitStrategy,消费者可以使用不同的等待策略,但使用同一个Blocker。
- 库只提供了核心的协调功能,并没有提供BatchEventProcessor这样的具体组件,完全由用户控制。
- 内置了一套无界缓冲区
MpUnboundedBuffer
。
ps: 很自信地讲,我的设计更容易理解。
C#实现与Java实现的不同
- C#的挂起最小单位是毫秒,而1毫秒已是非常长的时间,因此所有Sleep等待策略都没有让用户指定睡眠时间,而是固定1毫秒。
- C#的
Thread.SpinWait
方法提供了iterations
参数,因此所有的SpinWait策略都提供了该参数支持。 - C#的不直接支持C++11的 Acquire和Release内存语义,因此使用Volatile读写代替。
- C#不支持volatile修饰64位的long和double,因此一些long类型字段未声明为volatile,这与我的日常习惯不同 -- 可能多线程读写的字段,保持为volatile是个好习惯。
- 为支持结构体类型,
DataProvider
提供了获取元素引用的ProducerGetRef
和ConsumerGetRef
接口。
PS:C#其实可以采用FieldOffset来实现缓存行填充,但为了保持代码简单,暂未采用
注意事项:
- C#的挂起最小单位是毫秒,因此慎重使用可能导致线程挂起的api,可能导致较大的延迟。
- 框架的具体应用见并发库中的
DisruptorEventLoop
。
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Wjybxx.Disruptor:
Package | Downloads |
---|---|
Wjybxx.Commons.Concurrent
并发基础库;提供事件循环和基于事件循环的await语法 |
GitHub repositories
This package is not used by any popular GitHub repositories.