erlang

centOS系统安装-RabbitMq

倾然丶 夕夏残阳落幕 提交于 2019-12-06 14:35:54
前言 消息通知机制是我们在日常业务开发总常常都会遇到;在微服务架构里,消息也是必不可少的,我们可以借助它异步实现很多业务,就拿我们日常的购物需求来说,在我们下单支付之后,我们就可以通过消息机制来异步处理很多的业务(给商家发送下单成功消息;给用户发送短信;通知发货或生成凭证;修改订单状态等等); 此篇只介绍如何安装RabbitMq!!! 消息机制-Rabbitmq 作为消息通知中间件来说,Rabbitmq依靠它微秒级的时效、活跃的社区、万级的吞吐量等也得到了许多公司的青睐和使用; 接下来我们来在linux环境安装rabbitmq; Rabbitmq的安装 1. 首先我们下载安装erlang: rabbitmq是基于erlang开发实现的 wget https://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm 2. 利用yum安装下载好的erlang yum install erlang 3. 下载RabbitMq安装包 wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.5.1/rabbitmq-server-3.5.1-1.noarch.rpm 4. 安装Rabbitmq rpm --import http://www.rabbitmq

Erlang: Output Problem

三世轮回 提交于 2019-12-06 14:34:29
In my erlang web application, there is a list, which contains integers to be printed on the web page. But when the script executes, it prints this, instead of actual list, Please look at this Image showing characters for unicode codepoint 1, 1, 2, 3, 5, 8, whitespace, codepoint 15 How to format this to gain what I want? Target list is [1, 1, 2, 3, 5, 8, 13, 15] Muzaaya Joshua You should do this: P = [1, 1, 2, 3, 5, 8, 13, 15], Show_on_page = io_lib:format("~p",[P]), Show_on_page. This will represent any Erlang term on the web page the way you want to see it. You Web presentation probably like

Get next month in Elixir

大兔子大兔子 提交于 2019-12-06 14:26:18
问题 In my last question answered by Aleksei, I was trying to find the previous month for a given date. Now I'm trying to do the opposite: defmodule Dating do def next_month(%Date{year: year, month: month, day: day} = date) do first_day_of_next_month = Date.add(date, Calendar.ISO.days_in_month(year, month) - day + 1) %{year: year, month: month} = first_day_of_next_month Date.add(first_day_of_next_month, min(day, Calendar.ISO.days_in_month(year, month)) - 1) end end Though the code works correctly,

【原创】在CentOS 5.7上通过YUM安装Erlang的坑爹经历(更新)

人盡茶涼 提交于 2019-12-06 14:08:12
想要在虚拟机上的 Linux 环境下,重新搞一下 RabbitMQ 的相关实验,所以重新折腾了下如何操作: Since RabbitMQ is written in Erlang, we need to have installed the language libraries to run the broker. 首先还是要把 Erlang 的安装搞定,最简单的方式是直接重 官网 上下载源码包或rpm包再安装,但是我是个喜欢折腾的人,所以我选择了另外一种“比较笨拙”的方式 - 即通过 Linux 系统自带的包管理工具进行安装。 按照 www.erlang-solutions.com 上的说明: RPM-based Linux distributions RPM packages are signed. To add Erlang Solutions key to execute command: # rpm --import http://binaries.erlang-solutions.com/debian/erlang_solutions.asc Users of Fedora can add this file to /etc/yum.repos.d/ Users of Centos can add this file to /etc/yum.repos.d/ ( RPM

Centos 6 下安装 erlang 手记

99封情书 提交于 2019-12-06 14:07:49
在linux系统从事erlang开发的朋友都要使用到linux下erlang 【下载erlang源码安装包】:在linux安装erlang只能下载源码安装包来安装,可以到erlang官方网站上下载,如图。 【解压安装包】:下载的安装包是经过压缩的gz格式,在linux下解压用到系统自带的tar工具,在安装包所在目录执行命令:tar -zxvf otp_src_R16B03-1.tar.gz 【配置安装环境】: 出现错误大致为: No curses library functions found , 需要安装ncurses : yum install ncurses-devel。然后 打开解压后的目录-执行命令:cd otp_src_R16B03-1;配置安装环境-执行命令:./configure --prefix=/usr/local/servers/erlang --without-javac 【编译源码】:执行编译命令:make 【安装编译好的软件】:执行命令:make install 创建软链:执行命令:lln -s /usr/local/servers/erlang/bin/erl /usr/local/bin/erl 注意:如果当前用户不是root,则执行:sudo make install 【启动erlang工具】:执行命令erl,看到如下图安装成功。 来源:

Erlang sublist function performance

為{幸葍}努か 提交于 2019-12-06 14:07:09
I'm reading http://learnyousomeerlang.com/ which includes a tail recursive sublist function that reverses the list to preserve order. I have written an alternative that does not require the reverse call. Is mine more efficient (it is certainly more verbose, but I'm not concerned with that), or have I overlooked something? -module(sublist). -export([sublist/2,sublistR/2]). -include_lib("eunit/include/eunit.hrl"). sublist(_,0) -> []; sublist([],_) -> []; sublist(List,Length) -> sublist([hd(List)], tl(List), Length-1). sublist(Acc,[],_) -> Acc; sublist(Acc,_,0) -> Acc; sublist(Acc,Tail,Length) ->

Erlang并发机制 – 垃圾回收

爱⌒轻易说出口 提交于 2019-12-06 14:05:21
Erlang中每个进程都有独立的堆内存,默认的大小是233个words(可配置),并以 Fibonacci序列的顺序增长(233对应fib(11))。不过,当堆内存增大到一定程序时,增长速度减缓,比如内存大于fib(35)=14M的时候,堆内存开始不以Fibonacci序列增长(具体参见[$R15B_OTP_SRC/erts/emulator/beam/erl_gc.c --> erts_init_gc]里的说明)。一般情况下,进程所用到的数据都放在各自的堆内存中。 Erlang的GC机制跟其它语言(比如Java)相比,很重要的一点是,它的GC是以进程为单位进行的(一般情况下,GC搜索的根对象主要包括进程栈以及进程信箱中的对象)。Erlang系统中,GC进行时,会挂起整个系统(当前结点上的所以调度队列),也就是说它的GC也是“stop the world”。但是,就算一个系统中有大量进程,总共占用几个G的内存,它的GC的延迟也会很低,这是因为每个进程可能只使用很小的内存(比如20K),在这么小的内存上进行GC所花费的时间很小,基本可以忽略不计。 在Erlang中可以通过spawn_opt来指定初始堆内存大小,如果这个数值足够大(需要诊断后确定),那么就可以完全避免GC。进程在销毁时,统一收回其所拥有的所有堆内存,而不需要进行GC,因为堆内存是每个进程私有的。 Erlang中

Erlang Views in Couch DB

久未见 提交于 2019-12-06 13:56:47
Its possible to write views in Erlang to query Couch DB. The views written in Erlang are said to be faster than those written in JavaScript. This Article shows this possibility. However, it explains that we can type an Erlang fun as a temporary view directly in the futon : CouchDB Web interface Question 1: Where can i find examples of Couch DB views written in Erlang, or atleast a tutorial of whats required in doing so ( In your answer, i would appreciate an example of a view written in Erlang which shows all basic techniques for map and reduce as well as selecting and filtering from documents

Erlang gen_tcp:recv(Socket, Length) semantics

不问归期 提交于 2019-12-06 13:55:54
问题 After reading this answer, I want to understand if the same applies to the calls to gen_tcp:recv(Socket, Length) . My understanding of the documentation is that this if more than Length bytes are available in the buffer, they remain there; if there is less than Length bytes, the call blocks until enough is available or connection closes. In particular, this should work when packets are prefixed by 2 bytes holding packet length in little-endian order: receive_packet(Socket) -> {ok, <<Length:16

How do I start applications by command line as a daemon?

元气小坏坏 提交于 2019-12-06 13:32:11
问题 This has been my current routine sudo nohup erl -sname foo -pa ./ebin -run foo_supervisor shell -noshell -noinput & where the shell function looks something like this shell() -> {ok, Pid} = supervisor:start_link({local,?MODULE}, ?MODULE, _Arg = []), unlink(Pid). If I don't unlink from shell it immediately stops for some reason. Is there a way I can just start my application like I would normally ie application:start(foo). Also what if I want to start sasl too? Also where could I learn more