go-disruptor高性能的消息框架
这是Go编程语言里 LMAX Disruptor的接口。 它保留了Disruptor的本质和原理,并利用了很多相同的抽象概念和理论,但不会保持同样的API。
简述:
在我的 MacBook Pro (Intel Core i7-4960HQ CPU @ 2.60GHz) 中,我使用了 Go 1.4.2, 此版本使我能在一秒内发送9亿多份邮件(是的,你没有听错), 从一个goroutine到另一个goroutine. 讯息在两台CPU间的传递很简单。 请注意,您的里程可能会有所不同,通过控制CPU并清除其缓存,不同的操作系统可以添加特定的“jitter”到App中。Linux和Windows系统有给定的进程分配给特定的CPU内核它通过将所有的CPU缓存热显著降低“jitter”的能力。 顺便,当Disruptor代码被编译并在Nexus 5上运行,它可以每秒可推送约15-20万条信息。
一旦被初始化,在运行时,Disruptor杰出设计的考虑因素之一,就是以一个恒定的速率来处理消息。为此,它使用两个主要技术:
1. 它避免了在所有costs上使用锁,costs通常会引起CPU内核间的排斥,影响可测量性。
2. 它允许应用程序预先在一个环形缓冲区分配连续的空间,不产生垃圾。
通过避免垃圾,垃圾清理站和应用程序暂停的功能可以免去。
示例代码:
Wireup
runtime.GOMAXPROCS(2) // make sure we have enough cores available to execute const RingBufferCapacity = 1024 // must be a power of 2 const RingBufferMask = RingBufferCapacity - 1 // this instance will be shared among producers and consumers of this application var ringBuffer = [RingBufferCapacity]MyStruct{} myDisruptor := disruptor. Configure(RingBufferCapacity). WithConsumerGroup(MyConsumer{}). // we can have a set of concurrent consumers run first // WithConsumerGroup(MyConsumer{}). // and then run this/these consumers after the first set of consumers BuildShared() // Build() = single producer vs BuildShared() = multiple producers myDisruptor.Start() defer myDisruptor.Stop() // clean shutdown which stops all idling consumers after all published items have been consumed // application code here, e.g. listen to HTTP, read from a network socket, etc.
生产者
Producer writer := myDisruptor.Writer() // for each item received from a network socket, e.g. UDP packets, HTTP request, etc. etc. sequence := writer.Reserve(1) // reserve 1 slot on the ring buffer and give me the upper-most sequence of the reservation // this could be written like this: ringBuffer[sequence%RingBufferCapacity] but the Mask and & operator is faster. ringBuffer[sequence&RingBufferMask].MyImportStructData = ... // data from network stream writer.Commit(sequence, sequence) // the item is ready to be consumed
消费者
type MyConsumer struct{} func (m MyConsumer) Consume(lowerSequence, upperSequence int64) { for sequence := lowerSequence; sequence <= upperSequence; sequence++ { message := ringBuffer[sequence&RingBufferMask] // see performance note on producer sample above // handle the incoming message with your application code } }
评论
smqtt高性能的 MQTT 消息代理
SMQTT基于Netty开发,底层采用Reactor3反应堆模型,支持单机、集群和容器化部署,具备低延迟、高吞吐量,支持百万TCP连接,同时支持多种协议交互、规则引擎,是一款非常优秀的消息中间件!sm
smqtt高性能的 MQTT 消息代理
0
MadzMQ高性能消息队列
MadzMQ是基于libzmq+czmq实现的高性能,高可用的消息队列。架构设计*--------------------*| madclient |+---------------
MadzMQ高性能消息队列
0
delaymq高性能的任意延时消息队列
RocketMQ开源版本任意时间延时队列实现定时消息:Producer将消息发送到消息队列RocketMQ版服务端,但并不期望立马投递这条消息,而是推迟到在当前时间点之后的某一个时间投递到Consum
delaymq高性能的任意延时消息队列
0
gevent高性能的 Python 并发框架
Gevent是一个基于greenlet的Python的并发框架,以微线程greenlet为核心,使用了epoll事件监听机制以及诸多其他优化而变得高效。于greenlet、eventlet相比,性能略
gevent高性能的 Python 并发框架
0