English 中文(简体)
当一个gen_server方法同时被两个客户同时调用时会怎么样?
原标题:What happens when a gen_server method gets called simultaneously by two clients?

我有一个 gen_ server 模块, 当客户程序发送数据时将数据记录到文件 。 当两个客户程序同时发送数据到此模块时会怎样? 文件操作会相互冲突吗? < a href=" http://www.erlang.org/doc/man/gen_ server.html# Module% 3ahandle_info-2" rel = “ noreferrer''>erlang documents 的文档在这里很难说清楚。

最佳回答

Erlang 每个进程都保留一个信件队列。 此进程将逐个获取信件并处理信件 。

例如,如果两个客户同时调用 gen_server ,这些调用将成为 gen_server 程序队列中的信息,而 gen_server 将逐个处理这些信息。因此不必担心冲突。

但是,如果一个进程必须处理来自其他进程太多的信息,你就需要考虑该进程的能力,优化设计,否则就会成为一个瓶颈。

问题回答

gen_server 运行在与客户端进程分开的进程中,因此当您对它做 call call / cast cast 时,您实际上是向服务器进程发送信件。

所有信件都放在一个进程信件的队列中, 并且程序会逐个处理它们的信件。 如果信件在一个进程繁忙时到达, 那么它会被放在信件的队列中 。 所以同时到达的日志信件不会互相干扰, 因为会按顺序处理 。

这不是 gen_server 本身的属性,而是ERLang所有进程的一般属性,因此在gen_server文档中没有提到这一点。

gen_server 仅按请求的顺序处理请求,而不论请求是由一个或多个程序处理的。

在写作记录时,没有理由担心种族条件。

幸运的是,检察官办公室的资料来源可以随时在





相关问题
How big can Erlang DETS be and what to do if its too small?

All I need is a large persistent lookup table in Erlang and dets seems like just the thing though I need a definative answer to: just how big the total size of the binaries in the table can be. how ...

passing events from erlang to Clojure

I m looking for a way to pass events back and forth between Clojure and erlang. has someone done this before? how should I encode the (immutable) messages in a flaxable general way? Should IPC be ...

How to send a push notification using Erlang?

I m trying to send a push notification to APNs using Erlang. This is the code I came up with so far: -module(apnstest2). -export([connect/0]). connect() -> application:start(ssl), ssl:...

How do I build a DNS Query record in Erlang?

I am building a native Bonjour / Zeroconf library and need to build DNS query records to broadcast off to the other machines. I have tried looking thru the Erlang source code but as I am relatively ...

AccessViolation when calling unmanaged dll

When calling an unmanaged Dll from a c# application I get an AccessViolationException. The strange thing is that the exported function has no arguments, so the problem is not in the Marshalling of ...

How to enable active sockets in a Mochiweb application?

Does anyone know how to enable active instead of passive sockets in a Mochiweb application. Specifically, I am trying to adapt http://www.metabrew.com/article/a-million-user-comet-application-with-...

How to convert numbers to words in Erlang?

I found this interesting question about converting numbers into "words": Code Golf: Number to Words I would really like to see how you would implement this efficiently in Erlang.