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


相关推荐

  • Linux下视频流媒体服务器搭建详解「建议收藏」

    Linux下视频流媒体服务器搭建详解「建议收藏」目标用于搭建内网流媒体服务器支持视频的点播。背景用于支持培训网站中视频点拨功能,在培训网站总体方案中需要加入流媒体服务器,用于存储和传输视频资源。相关概念流媒体流媒体(StreamingMedia)是一种新兴的网络传输技术,在互联网上实时顺序地传输和播放视/音频等多媒体内容的连续时基数据流。流媒体技术包括流媒体数据采集、视/音频编解码、存储、传输、播放等领域。流媒体系统组成包括编码工具、流媒体数…

    2022年10月20日
    3
  • android中遍历arrayList的四种方法[通俗易懂]

    android中遍历arrayList的四种方法[通俗易懂]packagecom.mylist.test;importjava.util.ArrayList;importjava.util.Iterator;importjava.util.List;publicclassArrayListDemo{   publicstaticvoidmain(Stringargs[]){       Listlist

    2022年7月22日
    5
  • elasticsearch 入门安装

    elasticsearch 入门安装

    2022年2月18日
    51
  • 光纤交换机常用命令

    光纤交换机常用命令使用电脑连接管理网口,默认IP地址为:192.168.0.1,掩码:255.255.255.0默认用户名:admin,默认密码password1.switchStatusShow查看交换机的总体健康状态switch:admin>switchstatusshowSwitchHealthReportSwitchName:SWF…

    2022年5月11日
    58
  • 关于软连接的创建_linux设置软连接

    关于软连接的创建_linux设置软连接关于软连接的创建ln的功能是为某一个文件在另外一个位置建立一个同步的链接这个命令最常用的参数是-s,具体用法是:ln-s源文件目标文件。当在不同的目录,用到相同的文件时,可以不需要在每一个需要的目录下都放一个必须相同的文件,只要在某个固定的目录,放上该文件,然后在其它的目录下用ln命令链接(link)它就可以,不必重复的占用磁盘空间。例如:ln-s/bin/hello.sh…

    2022年9月28日
    2
  • 舵机控制原理和结构图_舵机的相关原理与控制原理

    舵机控制原理和结构图_舵机的相关原理与控制原理原文:https://blog.zeruns.tech/index.php/archives/358/什么是PWM信号PWM,英文名PulseWidthModulation,是脉冲宽度调制缩写,它是通过对一系列脉冲的宽度进行调制,等效出所需要的波形(包含形状以及幅值),对模拟信号电平进行数字编码,也就是说通过调节占空比的变化来调节信号、能量等的变化,占空比就是指在一个周期内,信号处于高电平…

    2025年7月24日
    3

发表回复

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

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