crumpling_relabelling

crumpling_relabellingTheRingBufferisadatastructurewherethedataisstoredinaring-likestructure.Youcanthinkofitasacirculararraywithacertaincapacity.Inthiscirculararray,theoldestitemgetsoverwrittenincaseanewitemiswrittenwhenthemaximumc


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

相关推荐

  • MySQL数据库建表语句

    MySQL数据库建表语句**建立一个叫student的表**CREATETABLE`student`(**id为int类型设置不能为空值**`id`INTNOTNULLauto_incrementprimarykeyCOMMENT’学生id’,`name`VARCHAR(16)NOTNULLCOMMENT’学生姓名’,`sex`CHAR(1)DEFAULT’男’COMMENT’性别’…

    2022年9月8日
  • CCS6.2超详细使用方法

    CCS6.2超详细使用方法本文介绍了如何安装CCS6.2、一步一步的建立工程、以及建立工程以后编译、调试、如何方便快捷有效率的使用CCS6.2。

    2022年4月7日
  • mysql和sqlyog安装_MySQL与sqlyog安装教程图文详解[通俗易懂]

    mysql和sqlyog安装_MySQL与sqlyog安装教程图文详解[通俗易懂]1.MySQL1.1MySQL安装mysql-5.5.27-winx64下载(1)欢迎安装(2)协议接受(3)安装模式选择Typical:表示一般常用的组件都会被安装,默认情况下安装到C:ProgramFilesMySQLMySQLServer5.5下。Complete:表示会安装所有的组件。此套件会占用比较大的磁盘空间。Custom:表示用户可以选择要安装的组件,可以更改默认按照的路径…

    2022年5月8日
  • Android中的像素密度,屏幕密度,屏幕大小,分辨率,ldpi,mdpi,xhdpi,xxhdpi

    Android中的像素密度,屏幕密度,屏幕大小,分辨率,ldpi,mdpi,xhdpi,xxhdpiAndroid开发为适配不同屏幕需要在资源文件中添加多套图片或者多套布局文件,这篇文章讲解多套图片。ldpi,mdpi,xhdpi,xxhdpi,xxxhdpi分别代表什么?如何使用。1屏幕大小智能手机普及,屏幕也随之越来越大,从经典的iPhone4的3.5英寸到iphoneXR6英寸多,Android手机也逐渐进入了6.x英寸行列。屏幕大小定义:手机对角线的物理尺寸,以英寸(in…

    2022年6月8日
  • 矩阵范数不等式_范数三角不等式取等号

    矩阵范数不等式_范数三角不等式取等号矩阵范数不等式∣∣A∣∣2≤∣∣A∣∣1∣∣A∣∣∞||A||_2\le||A||_1||A||_{\infty}∣∣A∣∣2​≤∣∣A∣∣1​∣∣A∣∣∞​证明引理1严格对角占优的矩阵行列式为正n维实矩阵A,满足aii>∑1≤j≤n,j≠i∣aij∣a_{ii}\gt\sum_{1\lej\len,j\nei}|a_{ij}|aii​>1≤j≤n,j​=i∑​∣aij​∣则称A为严格对角占优的矩阵,而∣A∣>0|A|>0∣A∣>0引理1的证

    2022年9月19日
  • Python中两种UnboundLocalError: local variable ‘xxx’ referenced before assignment情况的解决方法

    Python中两种UnboundLocalError: local variable ‘xxx’ referenced before assignment情况的解决方法  1)在子程序中对全局变量的操作,比如val=9deftest(flag):   ifflag:     val=1   else:     print’Error’   returnval test(0)错误提示:UnboundLocalError:localvariable’val’referencedbefo…

    2022年6月17日

发表回复

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

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