GENSTAGE和民意调查是推荐的模式吗?
我正在开发我在Elixir中的第一个媒介/大型应用程序,并试图熟悉Elixir系统设计和体系结构中的常见模式。
目前,我正在尝试实现一个输入队列(目前使用Erlang:队列实施),揭露并通过API,我想让该队列中的消费者执行一些处理并存储数据。
我已经使用代理商创建了队列,并实施了一个genstage,该阶层向队列查询元素,并为执行我需要的所有处理而进行了Genstage消费者。总而言之,类似这个
队列代理--------> Genstage生产商------------> Genstage消费者------>数据库
我的问题如下:
- 这种模式对长生不老药有效吗?
- GenStage生产商在队列上执行的民意调查是否有效,每次都要求消费者要求使用新元素吗?
- 在这种模式中是否有任何性能含义,特别是队列代理中可能存在任何阻塞含义吗?
I'm developing my first medium/big application in elixir and I'm trying to get familiar with the common patterns in elixir system design and architectures.
At this moment I'm trying to implement an input queue (currently implemented using the erlang :queue), exposed through and API and I want to have consumers from that queue performing some processing and storing the data.
I have created the queue using an Agent and I have implemented a genStage that queries the queue for elements and a genstage consumer for performing all the processing that I need. In summary something like this
Queue Agent -------> GenStage producer ---------> GenStage consumer -----> database
My questions are the following:
- Is this pattern valid for Elixir?
- Is a valid pattern the polling that the GenStage producer is performing on the Queue, asking everytime that consumers requests for new elements?
- Are there any performance implication in this pattern, specially are there any possible blocking implications in the Queue Agent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一些评论和阅读文档后,我意识到
genstage
基于Genserver
,我有可能从genStage
之外管理内部状态。之后,我重新分配了代码,现在我有
:queue
作为genstage
状态的一部分,因此我不需要在genStage之外进行轮询
,我还可以使用handle_cast
方法将元素添加到队列中。现在,我将队列用作
genstage
生产者,并且能够将我的数据库服务连接为消费者After some comments and reading documentation I realised that
GenStage
is based onGenServer
and I have the possibility to manage the internal state from outside theGenStage
.After this I refactored the code and now I have the
:queue
as part of theGenStage
state, so I don't need to polling any queue outside theGenStage
and I also have the possibility to add elements into the queue using thehandle_cast
method.Now I have the Queue working as a
GenStage
producer and I have been able to connect my database service as a consumer