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


相关推荐

  • Intellij IDEA 实用插件

    Intellij IDEA 实用插件1.前言从2020年JVM生态报告解读可以看出IntellijIDEA目前已经稳坐JavaIDE头把交椅。而且统计得出付费用户已经超过了八成(国外统计)。IDEA的优良设计保证了我的生产力,也是我情愿为之付费的软件之一。今天把我自己经常用的一些插件拿出来分享一波。同时欢迎加入[微信圈子]SpringForAll社区交流编程经验。2.IDEA插件分享之前我们来看看其插件体系。IntellijIDEA大部分功能是通过插件集成进来的。默认情况下已经集成了很多插件。你可以…

    2025年5月23日
    2
  • 织梦CMS搭建网站必做的服务器相关安全设置

    织梦CMS搭建网站必做的服务器相关安全设置

    2021年10月8日
    36
  • 最炫民族风原创_manjaro deepin

    最炫民族风原创_manjaro deepin最近有一首最具有民族风的歌曲很流行,它就是《最炫民族风》。中华民族的儿女都有这种情节,对于民族风的事物都非常感兴趣。与之相关,有一款最具民族风的Linux桌面操作系统也正在引起大家的关注。2012年7月17日,国人最喜爱的一款Linux发行版——DeepinLinux12.06正式发布了。LinuxDeepin也就是我们所说的深度Linux,这是一款基于Ubuntu11.04的发行

    2022年9月15日
    0
  • CSS中常见的BUG调试

    CSS中常见的BUG调试

    2022年1月23日
    35
  • DVD区码划分(一区 二区 三区 四区 五区 六区 全码区)

    DVD区码划分(一区 二区 三区 四区 五区 六区 全码区)美国电影协会为制定区域码划分了六个地区,这六区的域码分别是第一区 Region1 美国、加拿大、东太平洋岛屿,第二区 Region2 日本、西欧、北欧、埃及、南非、中东,第三区 Region3 台湾、

    2022年7月4日
    1.4K
  • pycharm提示代码功能问题「建议收藏」

    pycharm提示代码功能问题「建议收藏」在使用pycharm写python代码时,对于tensorflow模块,不能显示代码提示内容。在project中设置解释器地址后, 要等待下面列出的package包全部扫描完,显示完当前版本和最新版本完,再点OK按钮。在代码区输入相关类的点后,要稍微等一会,才会出现代码提示的信息。…

    2022年8月29日
    1

发表回复

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

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