Why my supervisor terminating?

I'm very new to OTP, I'm trying to create simple example to understand supervisor behaviour: Here is simple increment server -module( inc_serv ). -behaviour( gen_server ). -export( [ start/0, inc/1, stop/0 ] ). -export( [ init/1, handle_call/3, terminate/2 ] ). start() -> gen_server:start_link( { local, ?MODULE }, ?MODULE, no_args, [] ). stop() -> gen_server:cal

为什么我的主管会终止?

我对OTP非常陌生,我试图创建一个简单的例子来理解主管的行为: 这里是简单的增量服务器 -module( inc_serv ). -behaviour( gen_server ). -export( [ start/0, inc/1, stop/0 ] ). -export( [ init/1, handle_call/3, terminate/2 ] ). start() -> gen_server:start_link( { local, ?MODULE }, ?MODULE, no_args, [] ). stop() -> gen_server:call( ?MODULE, stop ). inc( Num ) -> gen_

Synchronous vs. Asynchronous messaging

Disclaimer: erlang newbie. One of the things that attracted me to erlang in the first place is the Actor model; the idea that different processes run concurrently and interact via asynchronous messaging. I'm just starting to get my teeth into OTP and in particular looking at gen_server. All the examples I've seen - and granted they are tutorial type examples - use handle_call() rath

同步与异步消息

免责声明:erlang新手。 首先吸引我去erlang的其中一件事就是Actor模型; 不同进程同时运行并通过异步消息传递的思想。 我刚刚开始接受OTP并特别关注gen_server。 我见过的所有示例(并授予它们为教程类型示例)都使用handle_call()而不是handle_cast()来实现模块行为。 我觉得有点混乱。 据我所知,handle_call是一个同步操作:调用者被阻止,直到被调用者完成并返回。 这似乎与异步消息传递哲学背道而驰。 我即将开

Trouble Understanding Erlang Gen

I am in early stages of learning Erlang and I need some further assistance. Not sure if this will get any sunlight but here it goes ... I am looking for a flow diagram on how the example works. Example Code: https://github.com/erlware/Erlang-and-OTP-in-Action-Source/blob/master/chapter_03/tr_server.erl Let me explain my problem ... 1> tr_server:start_link(). I understand this, it calls

麻烦了解Erlang Gen

我正处于学习Erlang的初级阶段,我需要一些进一步的帮助。 不知道这是否会得到任何阳光,但在这里它...我正在寻找一个关于如何工作的流程图。 示例代码:https://github.com/erlware/Erlang-and-OTP-in-Action-Source/blob/master/chapter_03/tr_server.erl 让我解释我的问题... 1> tr_server:start_link(). 我明白这一点,它调用start_link(?DEFAULT_PORT),它调用gen_server:start_link - 并且实际上将回调到t

Erlang: how to deal with long running init callback?

I have a gen_server that when started attempts to start a certain number of child processes (usually 10-20) under a supervisor in the supervision tree. The gen_server's init callback invokes supervisor:start_child/2 for each child process needed. The call to supervisor:start_child/2 is synchronous so it doesn't return until the child process has started. All the child processes are als

Erlang:如何处理长时间运行的init回调?

我有一个gen_server ,它在启动时尝试在监督树中的一个主管下启动一定数量的子进程(通常是10-20)。 gen_server的init回调为每个需要的子进程调用supervisor:start_child/2 。 对supervisor:start_child/2的调用supervisor:start_child/2是同步的,所以直到子进程启动后才会返回。 所有子进程也是gen_servers,所以start_link调用在init回调返回之前不会返回。 在初始化回调中,会对第三方系统进行调用,这可能需要一段时间

What OTP pattern to use for gen

So I have a non- blocking OTP socket server very similar to the one in Learn Yorself Some Erlang: http://learnyousomeerlang.com/buckets-of-sockets The supervisor passes the listening socket to dynamically spawned gen_servers, each of which can accept a single connection; in this way the listening socket isn't blocked by (blocking) calls to gen_tcp:accept, and each gen_server spawned by t

gen用什么OTP模式

所以我有一个非阻塞的OTP套接字服务器,与Learn Yorself中的一个非常相似。一些Erlang: http://learnyousomeerlang.com/buckets-of-sockets 监督者将监听套接字传递给动态生成的gen_servers,每个gen_servers可以接受单个连接; 通过这种方式,监听套接字不会被(阻塞)对gen_tcp:accept的调用阻塞,并且由监督器产生的每个gen_server都有效地代表单个客户端。 现在,这一切都非常好,我可以通过telnet与服务器通话,这

server become a bottleneck?

I'm currently writing a piece of software in erlang, which is now based on gen_server behaviour. This gen_server should export a function (let's call it update/1) which should connect using ssl to another service online and send to it the value passed as argument to the function. Currently update/1 is like this: update(Value) -> gen_server:call(?SERVER, {update, Value}). So once

服务器成为瓶颈?

我目前正在编写erlang中的一个软件,它现在基于gen_server行为。 这gen_server应该导出一个函数(我们称之为update / 1),它应该使用ssl连接到另一个在线服务,并将作为参数传递给函数的值发送给它。 目前更新/ 1是这样的: update(Value) -> gen_server:call(?SERVER, {update, Value}). 所以一旦被调用,就会调用?SERVER,它的处理方式如下: handle_call({update, Value}, _From, State) -> {ok, Socket}

Erlang queue problems

I am using the queue api and have encountered to errors which crash my program. First off I fetch the queue from the dictionary which returns this in a printout The fetched queue is [{[],[]}] Is this normal? Is the queue created correctly? Then either when I try add to the queue or get its length I get an error badargs on both. TorrentDownloadQueue = dict:fetch(torrentDownloadQueue, Sta

Erlang队列问题

我正在使用队列api,并遇到错误,它会导致我的程序崩溃。 首先我从字典中获取队列,并在打印输出中返回该队列 获取的队列是[{[],[]}] 这是正常的吗? 队列是否正确创建? 然后,无论我尝试添加队列还是获取其长度,我都会遇到一个错误badargs。 TorrentDownloadQueue = dict:fetch(torrentDownloadQueue, State), io:format("The fetched queue is ~p~n", [dict:fetch(torrentDownloadQueue, State)]), % Add the ite

What's the best way to do something periodically in Erlang?

I have a process that needs to do some work every fifteen seconds. I'm currently doing it like this: -behavior(gen_server). interval_milliseconds ()-> 15000. init()-> {ok, _State = FascinatingStateData, _TimeoutInterval = interval_milliseconds () }. %% This gets called automatically as a result of our handlers %% including the option

在Erlang定期做某些事情的最佳方式是什么?

我有一个过程需要每十五秒做一些工作。 我目前正在这样做: -behavior(gen_server). interval_milliseconds ()-> 15000. init()-> {ok, _State = FascinatingStateData, _TimeoutInterval = interval_milliseconds () }. %% This gets called automatically as a result of our handlers %% including the optional _TimeoutInterval value in the returned %%

exit, true)

After watching the Pragmatic Studio screen casts on Erlang, the last video on Supervisors mentioned that in order for a supervisor to get a notification about one of its children so it can properly restart it, the child should register with process_flag(trap_exit, true) . Perhaps I just misunderstood the author (and chances are VERY high that I did misunderstand), but I thought supervisors autom

退出,是)

在观看了Erlang的Pragmatic Studio屏幕后,Supervisors上的最后一段视频提到,为了让主管得到关于其中一个子项的通知,以便它可以正确地重新启动它,那么应该向process_flag(trap_exit, true) 。 也许我只是误解了作者(而且我误解的可能性非常高),但我认为主管自动地知道他们的孩子何时死亡(可能通过spawn_link或类似的背景)。 这真的有必要吗? 什么时候应该在实际案例中使用process_flag(trap_exit,true),因为文档

Function equality/ordering in erlang

What does it mean to compare functions in Erlang with the operators =:= , == , < , > , =< , >= ? I was playing around with the interpreter and got these results: Eshell V5.9.2 (abort with ^G) 1> X = fun() -> {} end. #Fun<erl_eval.20.82930912> 2> Y = fun() -> {} end. #Fun<erl_eval.20.82930912> 3> 3> {X == X, X =:= X}. {true,true} 4> {X >= X, X =&

erlang中的函数相等/排序

将Erlang中的函数与运算符=:= , == , < , > , =< , >=进行比较意味着什么? 我和翻译一起玩,并得到了这些结果: Eshell V5.9.2 (abort with ^G) 1> X = fun() -> {} end. #Fun<erl_eval.20.82930912> 2> Y = fun() -> {} end. #Fun<erl_eval.20.82930912> 3> 3> {X == X, X =:= X}. {true,true} 4> {X >= X, X =< X}. {true,true} 5> {X > X, X < X}. {fa