otp

Why does io:format support ~n when \\n does the same thing?

放肆的年华 提交于 2019-12-04 06:55:33
These two give identical output: 1> io:format("Hello, world!~n"). Hello, world! ok 2> io:format("Hello, world!\n"). Hello, world! ok Why does io:format support ~n when \n does the same thing? Are there any differences? According to "Programming Erlang", ~n outputs the platform-specific new line sequence ( \n on Unix, \r\n on Windows, etc.). I think \n just writes the \n character, but am not sure. According to io document , The general format of a control sequence is ~F.P.PadModC . So the format must begin with ~ , and character n is one of the control sequences with the definition Writes a

How does Erlang hot code swapping work in the middle of activity?

穿精又带淫゛_ 提交于 2019-12-04 05:54:05
I am currently working on a live media server, which will allow general consumers to send live video to us. In our current environment we've seen broadcasts sent to us with the duration of days, so the idea of being able to fix a bug (or add a feature) without disconnecting users is extremely compelling. However as I was writing code I realized that hot code swapping doesn't make any sense unless I write every process so that all state is always done inside a gen_server, and all external modules that gen_server calls must be as simple as possible. Let's take the following example: -module

Concurrency: Processes vs Threads

有些话、适合烂在心里 提交于 2019-12-03 23:01:10
What are the main advantages of using a model for concurrency based on processes over one based on threads and in what contexts is the latter appropriate? knutin Fault-tolerance and scalability are the main advantages of using Processes vs. Threads. A system that relies on shared memory or some other kind of technology that is only available when using threads, will be useless when you want to run the system on multiple machines. Sooner or later you will need to communicate between different processes. When using processes you are forced to deal with communication via messages, for example,

CouchDB as a part of an Erlang release

一个人想着一个人 提交于 2019-12-03 13:25:26
I would like to build and deploy an application which has Django as frontend, YAWS ( appmods ) or Mochiweb/Webmachine as a backend and CouchDB as a datastore. Furthermore, I plan to extensively use CouchDB's ability to replicate in order to provide high fault tolerance for the whole application. I tend to think that in order to achieve this, I must create a single OTP release which has YAWS and CouchDB as Erlang/OTP applications. Does this approach seem to be correct? How can I organize YAWS and CouchDB in terms of OTP applications in order to create a solid production setup? Are there any

Access project version within elixir application

a 夏天 提交于 2019-12-03 09:55:36
I have an elixir project with a defined version. How can I access this from within the running application. in mix.exs def project do [app: :my_app, version: "0.0.1"] end I would like to be access this version number in the application so I can add it to the returned message. I looking for something in the env hash like the following __ENV__.version # => 0.0.1 Here's a similar approach to retrieve the version string. It also relies on the :application module, but is maybe a bit more straightforward: {:ok, vsn} = :application.get_key(:my_app, :vsn) List.to_string(vsn) Mix.Project itself

Non-blocking TCP server using OTP principles

自作多情 提交于 2019-12-03 09:49:58
问题 I'm starting to learn Erlang, so I'm trying to write the "hello, world!" of concurrent programming, an IRC bot. I've already written one using Erlang without any OTP niceties (supervisor, application, etc. behaviours). I'm looking to rewrite it using OTP principles but unfortunately I can't figure out the "right" way to do socket programming with OTP. It seems the only reasonable way is to create another process manually and link it to the supervisor, but surely someone, somewhere, has done

What's the best way to run a gen_server on all nodes in an Erlang cluster?

廉价感情. 提交于 2019-12-03 09:25:11
问题 I'm building a monitoring tool in Erlang. When run on a cluster, it should run a set of data collection functions on all nodes and record that data using RRD on a single "recorder" node. The current version has a supervisor running on the master node ( rolf_node_sup ) which attempts to run a 2nd supervisor on each node in the cluster ( rolf_service_sup ). Each of the on-node supervisors should then start and monitor a bunch of processes which send messages back to a gen_server on the master

Erlang gen_server with long-running tasks

和自甴很熟 提交于 2019-12-03 08:13:12
Good day, I have a gen_server process which does some long-running state-updating tasks periodically in handle_info : handle_info(trigger, State) -> NewState = some_long_running_task(), erlang:send_after(?LOOP_TIME, self(), trigger), {noreply, NewState}. But when such task runs, then whole server gets unresponsive and any call to it leads to whole server crash: my_gen_server:status(). ** exception exit: {timeout,{gen_server,call,[my_gen_server,status]}} in function gen_server:call/2 How it is possible to avoid blocking of gen_server ? And when one call my_gen_server:status() at any time, the

Erlang: starting a remote node programmatically

拥有回忆 提交于 2019-12-03 07:59:34
I am aware that nodes can be started from the shell. What I am looking for is a way to start a remote node from within a module. I have searched, but have been able to find nothing. Any help is appreciated. A bit more low level that pool is the slave(3) module. Pool builds upon the functionality in slave. Use slave:start to start a new slave. You should probably also specify -rsh ssh on the command-line. So use pool if you need the kind of functionality it offers, if you need something different you can build it yourself out of slave. There's a pool(3) facility: pool can be used to run a set

Maximum number of globally registered processes

*爱你&永不变心* 提交于 2019-12-03 07:30:41
Is there a limit to the number of processes that can be register globally? Or is this only limited by the memory/ max number of atoms ? Ubuntu 12.04 and Erlang R15B01. Good question! I'd bet on the number of atoms, if you take into account the following. The Efficiency Guide has a section on system limits: Processes The maximum number of simultaneously alive Erlang processes is by default 32768. This limit can be raised up to at most 268435456 processes at startup (see documentation of the system flag +P in the erl(1) documentation). The maximum limit of 268435456 processes will at least on a