在分布式Erlang中发送大消息的性能特征是什么? [英] What are the performance characteristics of sending big messages in Distributed Erlang?
问题描述
假设我在Erlang应用程序中创建了新的本地进程,并且想向它发送一条大消息。
Suppose I create new local process in an Erlang application, and i want to send to it a big message.
-module(chain_hello).
start(N, Some_big_data)->
Pid1 = spawn(chain_hello, some_fun, [N]),
Pid1 ! Some_big_data,
io:format("done \n").
尽管 Some_big_data
是对大数据的引用数据(例如文件内容)-发送时是否复制?
despite Some_big_data
is a reference to really big data (eg. content of a file) - is it copied when sending? Are there big penalties for performance?
通常我会使用一些线程安全的共享对象(和/或互斥锁)。
Normally I would use some thread safe shared object (and/or mutex). Is there any solution in Erlang to avoid copying message content?
添加:
有趣的情况是Some_big_data是结构化内容-具体来说是:地图,我可以在上面执行一些操作。
ADDED:
Interesting case is when Some_big_data is structured content - to be specific: map, on which I can perform some operations.
ADDED2
我看到Erlang没有这样的解决方案(由于在Erlang中进行了设计,因此在工作进程中共享了一些结构化的数据,例如map)。但是我认为通过扎实的工作和轻松的并发管理是有道理的。
ADDED2
Ok, I see there is no such solution for Erlang (sharing some structured data like map in worker process) - because of Erlang design. But I think it is justified by solid work, and easily concurrence management.
推荐答案
作为建议,您只能将当前进程的pid(self())发送到所需的进程处理some_big_data。这样,当您要使用some_big_data时,可以从第二个过程中将其引用回去。
As a suggestion, you can send only the pid of the current process (self()) to the process that you want to handle that some_big_data. That way, when you want to use that some_big_data, you can reference it back to it from the 2nd process.
例如:
-module(proc1).
send_big_data() ->
BigData = get_some_big_data(),
Pid = spawn(fun proc2:start/0),
Pid ! {process_big_data, self()},
loop(Pid, BigData).
loop(Pid,BigData) ->
receive
get_first_element ->
[H|T] = BigData,
Pid ! {response, H};
_ ->
Pid ! {nothing}
end,
loop(Pid).
(很抱歉出现语法错误)。
(Sorry for the eventual syntax mistakes).
这篇关于在分布式Erlang中发送大消息的性能特征是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!