erlang

Running multiple Erlang applications. One or many VMs?

三世轮回 提交于 2020-01-13 08:31:07
问题 I want to run multiple Erlang applications, one being Riak and another being a web server. Should I run them in the same of separate Erlang VMs and why? 回答1: If they don't have to do anything with each other: No. You might need to restart the VM for one of the applications, which would result in a downtime for both. 回答2: While many would recommend decoupling these subsystems I would take the opposite approach. Erlang has a built in strategy to run many applications on the same release. If

How to make two different source directories in a Makefile output to one bin directory?

。_饼干妹妹 提交于 2020-01-13 05:57:09
问题 I have the following Makefile to build my erlang project: .SUFFIXES: .erl .beam .yrl ERL_SRC := $(wildcard src/*.erl) ERL_OBJ := $(patsubst src/%.erl,ebin/%.beam,${ERL_SRC}) all: main main: ${ERL_OBJ} ebin/%.beam: src/%.erl erlc +debug_info -W -o ebin $< clean: rm -fr ebin/*.beam I'm trying to update this to also build my eunit tests in the test/eunit folder and have the output go to the same ebin folder as the src like this: .SUFFIXES: .erl .beam .yrl ERL_SRC := $(wildcard src/*.erl) ERL_OBJ

Postgresql connection pooling in Erlang

蹲街弑〆低调 提交于 2020-01-13 05:36:14
问题 I am looking for a robust connection pooling library for Postgresql. Something similar to https://github.com/dweldon/riakpool would be great. 回答1: Poolboy is a pretty good general-purpose pooling library: https://github.com/devinus/poolboy It comes with an example of how to use it with pgsql (scroll down the README file). 来源: https://stackoverflow.com/questions/7767415/postgresql-connection-pooling-in-erlang

Postgresql connection pooling in Erlang

做~自己de王妃 提交于 2020-01-13 05:36:12
问题 I am looking for a robust connection pooling library for Postgresql. Something similar to https://github.com/dweldon/riakpool would be great. 回答1: Poolboy is a pretty good general-purpose pooling library: https://github.com/devinus/poolboy It comes with an example of how to use it with pgsql (scroll down the README file). 来源: https://stackoverflow.com/questions/7767415/postgresql-connection-pooling-in-erlang

Erlang OTP编程初体验——gen_server和行为模式

假装没事ソ 提交于 2020-01-13 04:35:49
http://blog.sina.com.cn/s/blog_3fe961ae0101k4p6.html 行为模式其实非常类似于面向对象语言中的接口,至少笔者是这么理解的。OTP行为模式将一些反复出现的模式分成了两个部分,通用部分和具体应用相关的实现部分,这一过程其实就类似于面向对象编程中的抽象出接口的过程。本文给出一个OTP中最常见的行为模式的示例:通用服务器,即gen_server。 编写gen_server回调模块大致包括3相步骤: (1) 确定回调模块的名称; (2) 写接口函数(由客户端调用的); (3) 在回调模块中实现gen_server的6个回调函数(由gen_server容器来调用的)。 下面给出一个《Erlang OTP并发编程实战》中的示例代码,代码通过实现gen_server的接口,进而实现一个简单的RPC服务,这个RPC服务可以允许客户端调用服务器端任意模块中导出的任意函数。并且提供了一个get_count的查询接口,用于查询当前服务器已经处理过的请求数量。另外还有start_link()和stop()用于停止服务器进程。 tr_server.erl %%%------------------------------------------------------------------- %%% @author Martin & Eric %%%

Erlang nodes can't see each other

戏子无情 提交于 2020-01-13 01:41:11
问题 I am new to Erlang and trying to set two nodes on my laptop. In one terminal I type: eli@elimayost: ~/erlang_apps> erl -sname foo -setcookie secret And in the second terminal: eli@elimayost: ~/erlang_apps> erl -sname bar -setcookie secret If I use the first terminal to ping the second: (foo@elimayost)1> net_adm:ping(bar@elimayost). I get a pang response (same response if I use the second term to ping the first term). Any idea why? 回答1: Try starting the nodes like this: eli@elimayost: ~/erlang

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

谁说胖子不能爱 提交于 2020-01-12 23:44:52
问题 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

Centos7 手动编译 RabbitMQ ,并安装php amqp

让人想犯罪 __ 提交于 2020-01-12 09:37:54
RabbitMQ是一个在AMQP基础上完成的,可复用的企业消息系统,底层基于Erlang语言。 一:centos7安装RabbitMQ 这玩意儿安装很扯淡,官方推荐rpm安装,rpm安装本身是最简单的,但是安装RabbitMQ却不简单,很可能需要修改仓库地址。不同linux版本不一样,centos6和centos7也不一样。我这里不用rpm,手动编译Erlang,然后选择编译好的RabbitMQ。 1:安装Erlang 1):先安装几个必要的插件 yum -y install gcc glibc-devel make ncurses-devel openssl-devel autoconf unixODBC unixODBC-devel socat yum -y install wget 2):Erlang下载地址:http://www.erlang.org/downloads,我这里下载21.1版本 cd /usr/local/src/ wget http://erlang.org/download/otp_src_21.1.tar.gz #下载 tar -xvf otp_src_21.1.tar.gz #解压 ./configure --prefix=/usr/local/erlang --without-javac #忽略java编译 make && make install

rabbitmq搭建集群

▼魔方 西西 提交于 2020-01-12 08:40:21
安装Erlang 前期准备: GNU make Compiler -- GNU C Compiler, gcc or the C compiler frontend for LLVM, clang. Perl 5 GNU m4 -- If HiPE (native code) support is enabled. HiPE can be disabled using --disable-hipe ncurses, termcap, or termlib -- The development headers and libraries are needed, often known as ncurses-devel. Use --without-termcap to build without any of these libraries. Note that in this case only the old shell (without any line editing) can be used. sed -- Stream Editor for basic text transformation. 依赖的软件包和工具 如果缺少,需要安装(本次已centos7.5 最小化安装) # yum install gcc ncurses-devel clang sed perl

Determining IP address and port of an incoming TCP/IP connection in Erlang

∥☆過路亽.° 提交于 2020-01-12 07:21:08
问题 I would like to fetch the IP address and port number of an incoming TCP/IP connection. Unfortunately gen_tcp 's accept and recv functions only give back a socket, while gen_udp 's recv function also gives back the address information. Is there a straightforward way to collect address information belonging to a socket in Erlang? 回答1: You need inet/peername 1 . From the Erlang inet docs: peername(Socket) -> {ok, {Address, Port}} | {error, posix()} Types: Socket = socket() Address = ip_address()