crumpling_relabelling

crumpling_relabellingTheRingBufferisadatastructurewherethedataisstoredinaring-likestructure.Youcanthinkofitasacirculararraywithacertaincapacity.Inthiscirculararray,theoldestitemgetsoverwrittenincaseanewitemiswrittenwhenthemaximumc

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

The RingBuffer is a data structure where the data is stored in a ring-like structure. You can think of it as a circular array with a certain capacity. In this circular array, the oldest item gets overwritten in case a new item is written when the maximum capacity is reached. For now, the RingBuffer is not a partitioned data structure; its data is stored in a single partition and the replicas are stored in another partition.

Each element in a RingBuffer can be accessed using a sequence ID. This ID is between the head and tail (inclusive) of the RingBuffer. Head is the side where items are discarded and tail is the side where items are added to.

The RingBuffer can sometimes be a better alternative than an IQueue. Unlike IQueue, the RingBuffer does not remove the items, it only reads the items using a certain position. There are many advantages using this approach:

  • The same item can be read multiple times by the same thread; useful for realizing read at least once or read at most once semantics.
  • The same item can be read by multiple threads. Normally you could use a IQueue per thread for the same semantic, but this is way less efficient.
  • Reads are extremely cheap since there is no change in the RingBuffer, there is no change and therefor no replication required.
  • reads can be batched to speed up performance. Using read (and write) batching can dramatically improve performance of the RingBuffer.

The following are the methods included in the RingBuffer interface.

public interface Ringbuffer<E> extends DistributedObject {
  long capacity();
  long size();
  long tailSequence();
  long headSequence();
  long remainingCapacity();
  long add(E item);
  ICompletableFuture<Long> addAsync(E item, OverflowPolicy overflowPolicy);
  E readOne(long sequence) throws InterruptedException;
  ICompletableFuture<Long> addAllAsync(Collection<? extends E> collection, 
                        OverflowPolicy overflowPolicy);
  ICompletableFuture<ReadResultSet<E>> readManyAsync(long startSequence, 
                         int minCount, int maxCount, 
                         IFunction<E, Boolean> filter);

The RingBuffer can be configured with a time to live in seconds. Using this setting, you can control how long the items remain in the RingBuffer before getting deleted. By default the time to live is set to 0, meaning that unless the item is overwritten, it will remain in the RingBuffer indefinitely. If a time to live is set and an item is added, then depending on the OverwritePolicy, either the oldest item is overwritten, or the call is rejected.

The RingBuffer can also be configured with an InMemoryFormat which controls the format of stored items. By default BINARY is used; meaning that the object is stored in a serialized form. But also the OBJECT InMemoryFormat can be selected. This is useful when filtering is applied or when the OBJECT InMemoryFormat can lead to a smaller memory footprint than a BINARY.

The RingBuffer supports filtered reads. For example, when one thread only wants to see certain messages, one can filter the items after they are received from the RingBuffer. The problem is that this approach can be very inefficient since a lot of useless data needs to be sent over the line. When a filter is used, then the filtering happens at the source, which makes it a lot more efficient.

The RingBuffer provides asynchronous methods for the more powerful methods like batched reading with filtering or batch writing. To make these methods synchronous, just call get() on the returned future.

For more details about RingBuffer configuration check the RingbufferConfig class in H.

参考:

http://ifeve.com/dissecting-disruptor-whats-so-special/

https://docs.hazelcast.org/docs/3.5/manual/html/ringbuffer.html#ringbuffer

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/195257.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 智慧小区智慧物业管理系统一体化解决方案怎么写_小区物业管理系统界面

    智慧小区智慧物业管理系统一体化解决方案怎么写_小区物业管理系统界面传统物业在管理上不仅成本高,服务质量也很难有所保障。现在很多小区都安装了智能物业管理系统,它将信息手段与现代物业管理工作相结合,帮助物业管理团队及时响应客户需求,降低运营成本,提升服务品质。智慧物业是指充分利用物联网、云计算、移动互联网等新一代信息技术的集成应用,将物业各个单位紧密连接起来,实现数据的融合,建立起高效的联动机制。为业主提供一个安全、便利的智慧化生活环境。会比传统物业,带来更舒适的体验感与满意度。随着物联网不断完善,智能技术几乎渗透到各行各业的众多领域。智能运用的迅速发展将颠覆我们的生

    2022年10月18日
    1
  • Werkzeug_vuze怎么用

    Werkzeug_vuze怎么用原文链接:http://werkzeug.pocoo.org/docs/tutorial/欢迎来到Werkzeug教程,这里我们将会创建一个仿制TinyURL的应用,将URLs存储到一个redis实例。为了这个应用,我们将会使用的库包括,用于模板的Jinja2、用于数据库层的redis和用于WSGI层的Werkzeug。你可以使用pip安装需要的库:[plai

    2022年10月7日
    2
  • jni 头文件_java.io.file

    jni 头文件_java.io.file1,cmd切换到应用工程目录下如示例中的D:\zxy\IDCardQualityLib2,执行javah命令,红色部分为sdk平台android.jar路径,蓝色部分为生成的jni类名 D:\zxy\IDCardQualityLib>javah-classpath bin/classes;d:\tool\adt-bundle-windows-x86-20131030\adt-b

    2025年11月19日
    6
  • python编程100例_python进阶路线图

    python编程100例_python进阶路线图异常模块下面介绍python常用的异常模块AttributeError异常AttributeError试图访问一个类中不存在的成员(包括:成员变量、属性和成员方法)而引发的异常Attribut

    2022年7月28日
    3
  • 使用XSLT转换XML

    使用XSLT转换XMLSLT1.0是W3C标准,主要用于对XML文档的转换,包括将XML转换成HMTL,TEXT或者另外格式的XML文件.XSLT1.0可以与XPATH1.0标准一起使用,XPATH会告诉你要转换的节点而

    2022年7月2日
    31
  • 动画插件–AnimateCSS

    动画插件–AnimateCSS1.什么是Animate.css?其实swiper-animate就是参考Animate.css演变出来的一个插件, Animate.css和swiper-animate一样都是用于快速添加动画的, 所以会用swiper-animate就会用Animate.css2.Animate.css的使用:引入animate.css的文件 给需要执行动画的元素添加类名3.示例animated这个类名是animated.css的基类,但凡需要通过animated.css来添加动画,都需

    2022年7月27日
    16

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号