erlang

list convert to pid function list_to_pid/1 restriction

给你一囗甜甜゛ 提交于 2019-12-05 16:03:47
When test open source project 'gproc' function, I found list_to_pid is ok for local pid, and not ok for remote pid. My erlang runtime is R15B. (dist_test_n2@yus-iMac.local)29> D = list_to_pid("<0.239.0>"). <0.239.0> (dist_test_n2@yus-iMac.local)30> D == self(). %% equal here true (dist_test_n2@yus-iMac.local)31> f(E). ok (dist_test_n2@yus-iMac.local)32> E = gproc:where(Name). <8969.239.0> (dist_test_n2@yus-iMac.local)33> F = list_to_pid("<8969.239.0>"). <8969.239.0> (dist_test_n2@yus-iMac.local)34> F == E. %% not equal here false From user guide about this function, there is no such

[转]RabbitMQ集群原理与搭建

不打扰是莪最后的温柔 提交于 2019-12-05 15:36:36
摘要:实际生产应用中都会采用消息队列的集群方案,如果选择RabbitMQ那么有必要了解下它的集群方案原理 一般来说,如果只是为了学习RabbitMQ或者验证业务工程的正确性那么在本地环境或者测试环境上使用其单实例部署就可以了,但是出于MQ中间件本身的可靠性、并发性、吞吐量和消息堆积能力等问题的考虑,在生产环境上一般都会考虑使用RabbitMQ的集群方案。 对于RabbitMQ这么成熟的消息队列产品来说,搭建它并不难并且也有不少童鞋写过如何搭建RabbitMQ消息队列集群的博文,但可能仍然有童鞋并不了解其背后的原理,这会导致其遇到性能问题时无法对集群进行进一步的调优。本篇主要介绍RabbitMQ集群方案的原理,如何搭建具备负载均衡能力的中小规模RabbitMQ集群,并最后给出生产环境构建一个能够具备高可用、高可靠和高吞吐量的中小规模RabbitMQ集群设计方案。 一、RabbitMQ集群方案的原理 RabbitMQ这款消息队列中间件产品本身是基于Erlang编写,Erlang语言天生具备分布式特性(通过同步Erlang集群各节点的magic cookie来实现)。因此,RabbitMQ天然支持Clustering。这使得RabbitMQ本身不需要像ActiveMQ、Kafka那样通过ZooKeeper分别来实现HA方案和保存集群的元数据。集群是保证可靠性的一种方式

Erlang, pass an nif object between functions

[亡魂溺海] 提交于 2019-12-05 15:26:57
I write a C nif code and in function new , it creates a stack struct with enif_alloc_resource and returns that. when i use function enif_make_resources , it always returns <<>> in erlang. Here is my C code: #include "erl_nif.h" static ErlNifResourceType *MEM_RESOURCE; typedef struct { int n; int ps; int pe; ERL_NIF_TERM *data; } Stack; Stack *new(ErlNifEnv *env, int size) { Stack *s = (Stack*) enif_alloc_resource(MEM_RESOURCE, sizeof(Stack)); s->n = size; s->ps = 0; s->pe = size - 1; s->data = enif_alloc(sizeof(ERL_NIF_TERM) * size); return s; } static ERL_NIF_TERM new_nif(ErlNifEnv* env, int

Linux 部署 rabbitMQ集群

a 夏天 提交于 2019-12-05 14:26:34
1. 部署Erlang 1.1 RabbitMQ依赖于Erlang,版本对应请查看 https://www.rabbitmq.com/which-erlang.html 1.2 下载安装Erlang # 添加epel扩展源 yum install epel-release # 先删除可能存在的erlang(非必须) yum list erlang yum remove erl* # 清空和更新安装源(非必须) yum clean yum update # 参考 https://github.com/rabbitmq/erlang-rpm -> Erlang 21.x -> o use Erlang 21.x on CentOS 6 # 配置安装源 vim /etc/yum.repos.d/rabbitmq-erlang.repo [rabbitmq-erlang] name=rabbitmq-erlang baseurl=https://dl.bintray.com/rabbitmq-erlang/rpm/erlang/21/el/6 gpgcheck=1 gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc repo_gpgcheck=0 enabled=0 # 安装 yum

RabbitMQ安装

别说谁变了你拦得住时间么 提交于 2019-12-05 13:43:30
1.进入http://www.erlang.org/downloads 下载 Erlang,因为RabbitMQ 是由 Erlang 语言编写的。 2.tar zxvf otp_src_19.3.tar.gz 3.cd otp_src_19.3.tar.gz 4../configure --prefix=/opt/erlang 5.(遇到No ... found)yum install nucress-devel 3.(安装Erlang) make 7.make install 8.(遇到Makefile:248: /usr/local/otp_src_18.1/make/x86_64-unknown-linux-gnu/otp_ded.mk: No such file)yum install ncurses-devel.x86_64 9../configure --prefix=/hwd/software/erlang make make install 10.修改/etc/profile配置文件,添加: ERLANG_HOME=/opt/install export PAHT=$PATH:$ERLANG_HOME/bin export ERLANG_HOME source /etc/profile 11.验证 Erlang 是否安装成功:erl 来源: https://my

In Erlang, how do you invoke a function dynamically?

夙愿已清 提交于 2019-12-05 13:39:15
问题 I want to call xyz with the name of a function to be invoked. -module(sample). -export([xyz/1]). xyz(Name) -> Name(). p() -> "you called p". g() -> "you called g". But I get the following error: 1> c(sample.erl). ./sample.erl:6: Warning: function p/0 is unused ./sample.erl:7: Warning: function g/0 is unused {ok,sample} 2> sample:xyz('p'). ** exception error: bad function p in function sample:xyz/1 3> 回答1: It is correct that you have to export p and g. You can then use apply/3 to call it.

Call Erlang from Ruby

删除回忆录丶 提交于 2019-12-05 13:34:08
What is the most awesome gem I should use to call Erlang functions from Ruby app? I wish to use rspec for testing some gen_server stuff. Erlectricity looking solid, but there is no something like Node#rpc, just message passing. Any ideas? Well. I am using BERT-RPC and happy with it. http://github.com/mojombo/bertrpc For rpc calls, rinterface might be the right option. From the README: r = Erlang::Node.rpc("math","math_server","add",[10,20]) if r[0] == :badrpc puts "Got and Error. Reason #{r[1]}" else puts "Success: #{r[1]}" end I think (someone prove me wrong) that you shouldn't use rspec for

Is Erlang the C of the clustered computing world?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 13:11:32
Erlang seems to be very low level and performant on networks, but does not have a very rich type system or many of the things that other functional languages offer, so it seems to me that it will become the lowest level development language for clustered programming, until something else comes along and offers a decent clustered VM AND high level constructs. Any thoughts on this? Pete Kirkham C is the C of clustered computing. At least, every HPC cluster I've seen had lots of C and Fortran running MPI, and never Erlang. If anything, trends seem to be towards grid standards which are language

Integer to Binary Erlang

被刻印的时光 ゝ 提交于 2019-12-05 12:45:46
问题 I am trying to make an integer into a binary: 543 = <<"543">> How can I do this without integer_to_list(list_to_binary(K)). 回答1: If you want to convert 543 to <<"543">> I don't think you can find something faster than: 1> list_to_binary(integer_to_list(543)). <<"543">> Because in this case both functions implemented in C. If you want to convert integer to the smallest possible binary representation you can use binary:encode_unsigned function from the new binary module like this: 1> binary

Using fully qualified function calls in Erlang?

◇◆丶佛笑我妖孽 提交于 2019-12-05 12:27:25
I have just learnt how to upgrade a module in Erlang and I know that only the function calls that use the fully qualified names (eg. module:function() ) gets "relinked" to the current version loaded into the VM, but the function calls that do not specify the module's name do not get "relinked" to the current version, but keep using the older one. Is there a rule of thumb on when to use a fully qualified function call and when it's OK to call a function just by its name? Is it a bad idea to call all functions using their full name (like module:function() )? Erlang applications normally make use