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

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • linux iso镜像下载_linux镜像下载网站

    linux iso镜像下载_linux镜像下载网站iso是电脑上光盘镜像(CD Mirror)的存储格式之一因为其是根据ISO-9660有关CD-ROM文件系统标准存储的文件,所以通常在电脑中以后缀.iso命名,俗称iso镜像文件。它形式上只有一个文件,可以真实反映光盘的内容,可由刻录软件或者镜像文件制作工具创建。大陆叫镜像文件,台湾叫映像文件。镜像文件需要专门的虚拟光驱软件,进行读取,完全模拟了读取光盘文件的特性原理既然可以用直接方式向 光盘写入文件,为什么还要如此麻烦地制作一个映像文件呢?要知道制作映像文件同样是个耗费..

  • bind函数失败返回10049 的解决方案[通俗易懂]

    bind函数失败返回10049 的解决方案[通俗易懂]一般都是ip地址错误,不是局域网内的ip都能随便bind的,即使这个ip没人使用也不行。bind函数必须绑定本机ip地址,如果本机有多个ip地址,那么这些地址都可以bind,如果只有一个网卡和ip,那么就只能bind这个唯一的ip地址,或者127.0.0.1。或者直接用INADDR_ANY自动bind本机ip。…

  • Keycloak 6.0.0 正式发布,身份和访问管理系统

    Keycloak 6.0.0 正式发布,身份和访问管理系统Keycloak 6.0.0 正式发布,身份和访问管理系统

  • 抖音、吃鸡、王者荣耀:你的自律,是如何被顶级产品经理一步一步毁掉的

    抖音、吃鸡、王者荣耀:你的自律,是如何被顶级产品经理一步一步毁掉的文章概要01你的沉迷跟这个时代有关这是个特别容易沉迷的时代。抖音、煲剧、王者荣耀、吃鸡游戏……你的时间和注意力悄悄被它们偷走,却从不说再见。或许你也纳闷,自己的自制力怎么这么差了?但我想说,这事可能不完全怪你。《欲罢不能:刷屏时代如何摆脱行为上瘾》分享到:你的沉迷跟这个时代有关。作者亚当·奥尔特,是普林斯顿大学的心理学博士。他在这本书里以大量科学研究为基础,揭示了一个细思极恐的真相…

  • C# List用法 List 实列介绍

    C# List用法 List 实列介绍 usingSystem;usingSystem.Collections.Generic;namespaceList{classProgram{staticvoidMain(stri

  • python保存文件的几种方法

    python保存文件的几种方法

发表回复

您的电子邮箱地址不会被公开。

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