erlang - 如何限制消息队列或模拟? [英] erlang - how to limit message queue or emulate it?

查看:148
本文介绍了erlang - 如何限制消息队列或模拟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在做流程!消息,但是随着我googled一点,消息队列大小只限于内存。我有一棵进程树,其中叶子生成消息,并提供给根目录,我需要限制队列或切换到另一种做同样的方法。

Right now I am doing Process ! Message, but as i googled a bit, a message queue size is only limited to memory. I have a tree of processes where leaves generate messages and feed up to the root and i need to limit queue or switch to some another method of doing the same.

它,有时进程从一个叶子有时从两个叶子获取消息。在第二种情况下,我需要不同的有限队列,用于檐叶。

more of it, sometimes Process gets messages from one leaf and sometimes from two leaves. In the second case I need different finite queues for eave leaf.

推荐答案

没有内置机制来限制用于进程的消息队列。

There are no built-in mechanisms to limit the size of the message queue for a process.

erlang中此问题的常见解决方案是在生产者和消费者之间引入流控制协议。在发送下一条消息之前,这可以像发送者等待继续回复一样简单。你可以发明更复杂的流控制协议(windowing,...),但是经常发送/等待回复会做。 gen_server:call / 2 协议是一个很好的请求 - 响应协议,可以通过查看 gen_server gen:call - 它处理了很多可能的边缘案例。

The usual solution to this problem in erlang is to introduce a flow control protocol between the producer and the consumer. This can be as simple as the sender waiting for a continue reply before sending the next message. You can invent more complicated flow control protocols (windowing, ...), but often send/wait-reply will do. The gen_server:call/2 protocol is a good request-response protocol and can be re-used by looking at the code for gen_server and gen:call - it takes care of a lot of the edge cases that are possible.

另一种方法是通过系统拉取消息,而不是推送消息 - 在这种情况下,接收方在准备好消息时询问发送方的消息。虽然如果您有外部生产者,您无法充分限制或缓冲,那么您可能没有此选项。

Another approach is to pull messages through the system instead of pushing them - in this case the receiver asks the sender for a message when it's ready. Though if you have external producers that you can't rate-limit or buffer sufficiently, then you may not have this option.

这篇关于erlang - 如何限制消息队列或模拟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆