Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disruptor发生内存溢出问题讨论 #94

Closed
sosojustdo opened this issue Sep 4, 2018 · 4 comments
Closed

Disruptor发生内存溢出问题讨论 #94

sosojustdo opened this issue Sep 4, 2018 · 4 comments
Labels

Comments

@sosojustdo
Copy link

你好:
阅读了作者您的博客:https://crossoverjie.top/2018/08/29/java-senior/OOM-Disruptor/ 之后,自己也动手写了下单元测试,oom问题无疑,但是对于博客中有一段话存在不解:“我设置队列大小为 8 ,从 0~9 往里面写 10 条数据,当写到 8 的时候就会把之前 0 的位置覆盖掉,后面的以此类推(类似于 HashMap 的取模定位)。”;而我的单侧中,event数大于buffersize的时候,produce.publish方法回阻塞,我的单测地址:
sosojustdo/disruptor-learning@fb74612

@crossoverJie
Copy link
Owner

@sosojustdo

嗯,其实我想表达的意思是:

Disruptor 环形队列里的数据只有等到下一轮数据覆盖掉才会被回收。

阻塞的情况肯定是数据没有被消费导致生产者阻塞了,这是一个阻塞队列的基本功能。

@sosojustdo
Copy link
Author

@crossoverJie
阻塞队列要是满了,入队列不是会阻塞吗?“Disruptor 环形队列里的数据只有等到下一轮数据覆盖掉才会被回收。”这句话“下一轮数据覆盖掉” 意思是队列满了还能入队列,典型的场景:生产速度大于消费速度的时候会出现上面情况?,岂不是违背了阻塞队列初衷。disruptor队列刚使用,不太熟悉,望您指教,谢谢。。

@crossoverJie
Copy link
Owner

@sosojustdo

"下一轮数据覆盖掉"

忘了说这个前提了,前提是有消费之后才会覆盖。

比如我文章里面模拟的 8 个坑的队列。

主线程写入 10 条数据,消费线程去消费,肯定边消费边生产的。

如下图所示:

典型的场景:生产速度大于消费速度的时候会出现上面情况?

这样的场景肯定会导致生产者阻塞。

我在这里模拟消费比较慢的场景。

public void onEvent(LongEvent event, long sequence, boolean endOfBatch) throws InterruptedException {
LOGGER.info("消费 Event=[{}]",event.getValue()) ;
Thread.sleep(1000);

通过日志会发现生产者很快把 8 个消息写进入,到第 9 个的时候就阻塞了等到消费一条数据之后才会继续生产数据。

dump 线程也会发现 main 线程作为生产者确实是 waiting 状态。

@sosojustdo
Copy link
Author

@crossoverJie
明白了,多谢你的指点

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants