Elixir GenServer并行handle_call [英] Elixir GenServer parallel handle_call

查看:100
本文介绍了Elixir GenServer并行handle_call的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Phoenix框架上有一个应用程序.

There is an application on the Phoenix Framework.

需要GenServer,它将检查一些值.

There is a need for GenServer, which will check some values.

从控制器开始验证这些值(客户端发出请求,GenServer值检查,客户端收到响应).

Validation of these values is started from the controller (a request comes from the client, the GenServer value checks, the client receives a response).

一旦handle_call是同步的,那么当10个客户端一次呼叫10个调用handle_call时会发生什么?所有10个呼叫将被并行处理还是按队列顺序处理?

Once handle_call is synchronous, then what happens when 10 clients call 10 calls handle_call at a time? All 10 calls will be processed in parallel or in the order of the queue?

推荐答案

GenServer仅处理单个呼叫,其他消息将在邮箱中排队.如果需要同步进程,则可以允许这样做,但是您必须考虑邮箱,邮箱可能会在负载较重时很快堆积起来,并可能在没有任何警告的情况下杀死VM.

GenServer will process only single call other messages will be queued in mailbox. You can allow this if there is need for synchronous process but you have to think about mailbox, it could pile up soon on heavier load and kill VM probably without any warning.

您是否考虑改用Task?

Did you consider using Task instead?

这篇关于Elixir GenServer并行handle_call的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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