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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 回顾外滩踩踏事件,吸取的教训[通俗易懂]

    回顾外滩踩踏事件,吸取的教训[通俗易懂]外滩踩踏事故:悲剧为何发生?外滩踩踏事故:悲剧为何发生?截至当前,上海外滩踩踏事故已造成36人遇难、47人受伤。事故发生的原因初步显现,为外滩观景平台的人流对冲。很多人认为这种归因过于简单,更何况

    2022年7月1日
    194
  • getClass()和getClassLoader()区别 以及ClassLoader详解及用途(文件加载,类加载)

    getClass()和getClassLoader()区别 以及ClassLoader详解及用途(文件加载,类加载)获得ClassLoader的几种方法可以通过如下3种方法得到ClassLoader  this.getClass().getClassLoader(); // 使用当前类的ClassLoader  Thread.currentThread().getContextClassLoader(); // 使用当前线程的ClassLoader  ClassLoader.getSystemCla

    2022年5月4日
    77
  • ssd硬盘数据怎么恢复_硬盘数据转移到另一个硬盘

    ssd硬盘数据怎么恢复_硬盘数据转移到另一个硬盘英特尔(Intel)SSD数据恢复概览现在,英特尔SSD是目前市面上最受欢迎的SSD硬盘之一,这都归功于它的几个优点。例如:快速的读取和写入速度、计算性能的增强、高级的加密标准(AES)等等。尽管有这些优秀的硬盘特性,还是无法避免在一切情境下资料丢失的问题。为什么硬盘中的资料会丢失?可能有以下几种原因:包括意外删除、格式化、病毒攻击、电源激增、操作系统崩溃或者说在一些情况下导致SSD不可独、初始化或坏掉。当意外发生之时,能否成功从IntelSSD硬盘中恢复数据?是的,当然可以!在你将新数据写入

    2025年11月23日
    6
  • mybatis code helper pro 2.9 激活[最新免费获取]

    (mybatis code helper pro 2.9 激活)2021最新分享一个能用的的激活码出来,希望能帮到需要激活的朋友。目前这个是能用的,但是用的人多了之后也会失效,会不定时更新的,大家持续关注此网站~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月31日
    1.3K
  • windows搭建php环境_如何安装php环境

    windows搭建php环境_如何安装php环境使用apache+php+mysql的方式一、安装mysql1、下载mysql,下载地址:https://dev.mysql.com/downloads/installer/2、下载完成后解压我解压的路径是:D:\ProgramFiles\mysql-8.0.253、配置文件首先在解压的路径下查看是否含有my.ini的文件,如果没有则新建一个,内容如下:[mysqld]#设置3306端口port=3306#设置mysql的安装目录basedir=D:\ProgramFiles\

    2025年11月26日
    3
  • 模拟电路与数字电路基础知识点总结

    模拟电路与数字电路基础知识点总结最近模电真的是让人头疼,模电马上就要结课了,而我的只是水平还停留在第一章第一节,总结起来就是老师讲课听不懂,我又不想听,再加上老师又不想把分给我们,所以我慌了,就再csdn上查找了一下有没有大佬对模电只是点进行过总结;世界之大,总有大佬的:废话不多说,直接上链接,赶快去膜拜:模拟电路与数字电路基础知识点总结千万不要挂科啊~!!!!!!!!!1…

    2022年6月20日
    30

发表回复

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

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