erlang

How to refine the debugging?

故事扮演 提交于 2019-12-07 22:50:17
问题 Crash report (SASL) gives more or less where and why a bug happens. But is it possible to refine this (the function, the line de code, etc) ? 回答1: If you can reproduce the fault, the best way to get more information is to put a dbg trace on sections in question and review that output. dbg:tracer(),dbg:p(all,c),dbg:tpl(Mod,Func,x). This usually does the trick for me. Replace Mod and Func with whatever module and function you want to debug. If you are looking for more detailed post-mortem

Erlang sublist function performance

天大地大妈咪最大 提交于 2019-12-07 21:31:01
问题 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

Erlang: Strange chars in a generated list

烈酒焚心 提交于 2019-12-07 20:33:37
问题 Trying to generate a list through comprehension and at some point I start seeing strange character strings. Unable to explain their presence at this point (guessing the escape chars to be ASCII codes - but why?): 45> [[round(math:pow(X,2))] ++ [Y]|| X <- lists:seq(5,10), Y <- lists:seq(5,10)]. [[25,5], [25,6], [25,7], [25,8], [25,9], [25,10], [36,5], [36,6], [36,7], "$\b","$\t","$\n", [49,5], [49,6], [49,7], "1\b","1\t","1\n", [64,5], [64,6], [64,7], "@\b","@\t","@\n", [81,5], [81,6], [81,7],

Practical difference between Erlang maps:remove/2 and maps:without/2

这一生的挚爱 提交于 2019-12-07 19:49:46
问题 Checking over the documentation for one of the new R17 features, maps, brought me to maps:remove/2 and maps:without/2. The only clear distinction I can see is that remove/2 takes a single key and returns a view of the map without it, where without/2 accepts a list and returns a completely new map lacking the listed keys. 22> M1 = #{foo => bar, spam => eggs}. #{foo => bar,spam => eggs} 23> M2 = maps:without([foo], M1). #{spam => eggs} 24> M3 = maps:remove(foo, M1). #{spam => eggs} 25> M1. #

Erlang Mysql: How to prevent SQL Injections

我只是一个虾纸丫 提交于 2019-12-07 18:55:13
问题 I'm very new to erlang and I need to code something which inserts rows in a MySQL Database. How can I prevent SQL Injections with Erlang? Is there also something like prepared statements in other Languages or how should I do it? Thanks for your replies. 回答1: This answer depends on the driver you are using. Erlang ODBC has a function param_query that binds a set of parameters to the query and it might also escape all the SQL special characters. erlang-mysql-driver has prepared statements: %%

Can Circular Lists be defined in Erlang?

喜夏-厌秋 提交于 2019-12-07 18:28:46
问题 is it possible to define a circular list in erlang? http://en.wikipedia.org/wiki/Linked_list first question would be what exactly a circular list mean in erlang? is it with two elements, one element its self and next to it address to the next element, stored in a list? if so i can say there is a possibility of defining a circular list in erlang. but i need clarification weather is it what i think a circular list is in erlang? 回答1: There is no built-in list mechanism to do it. However, you can

Erlang and Redis: read performance

可紊 提交于 2019-12-07 18:26:16
问题 I suddenly encountered performance problems when trying to read 1M records from Redis sorted set. I used ZSCAN with cursor and batch size 5K. Code was executed using Erlang R14 on the same machine that hosts Redis. Receiving of 5K elements batch takes near 1 second. Unfortunately, I failed to compile Erlang R16 on this machine, but I think it does not matter. For comparison, Node.js code with node_redis (hiredis parser) does 1M in 2 seconds. Same results for Python and PHP. Maybe I do

游戏服务器架构调研报告

隐身守侯 提交于 2019-12-07 17:33:59
服务器架构调研报告 刘源霖 20151119 1. 前言 本文档主要是调研分析新的手游服务端架构,为下一款手游服务端研发提供可参考的方案。主要的参考点是数据持久化,并发效率,分布式,沙盒机制,热更新机制,研发维护成本。如果从头根据需求开发一款新的服务器架构,需要大量的时间,而且可能会得不偿失,一款新的架构稳定都需要时间的。我们应该尝试使用开源的,成熟的,活跃度高的开源框架。正文将先从服务器设计需要考虑的因素进行需求分析,以至明确我们需要的服务器架构原型,然后再分析现有的开源架构方案。 2. 游戏服务器设计因素 2.1. 服务器运行平台选择 服务器操作系统大多采用 Unix 和 Linux 操作系统,而 Linux 发行版本系统中,多使用 CentOS 、 Redhat 、 Ubuntu 、 Gentoo 、 Debian 。而这些发行版本可以大体分为两类,一类是商业公司维护的发行版本,一类是社区组织维护的发行版本,前者以著名的 Redhat ( RHEL )为代表,后者以 Debian 为代表。 Redhat 的稳定性和硬件兼容性都比 Debian 高。并且 RHEL 的生命周期是 7 到 10 年,基本上可以覆盖硬件的生命周期,也就意味着一个新硬件安装以后,不用再次安装操作系统。而 Debian 的生命周期是不固定的,一般新版本发布以后,上个版本再维护 18 个月。而

Mnesia equivalent of SQL NOT IN

隐身守侯 提交于 2019-12-07 17:32:02
问题 I have two records: -record(foo, {timestamp, name}). -record(bar, {timestamp, name}). And I would like to execute a Mnesia query that mimics the following SQL query SELECT f.* FROM foo f WHERE f.timestamp NOT IN ( SELECT b.timestamp FROM boo b) What would be an efficient Mnesia equivalent? 回答1: Good Question ! Now, i have thought of two ways. One where we use qlc and another where we use mnesia's own table iteration methods with accumulators . Here is the first option: %% Here i use 'qlc',

Rust、Erlang 并发数量比较

北城以北 提交于 2019-12-07 17:21:37
最近在看Rust,于是就心血来潮的把Rust的并发和erlang的拿来做比较,想看看谁支持的数量大。于是就有了下面的小片段,皆因好空虚、好寂寞、好冷。 我的机器配置如下:宏基4738G 笔记本,CPU Inter i3 2.53GHZ ,内存 2G 1)Rust代码如下: fn main() { let mut i = 0; while i < 1000000 { println(fmt!("The %dth task", i)); do spawn {loop{}}; //这个任务无限循环,不停止 i += 1; } } 初学Rust,可能写的比较蹩脚,别见笑。 2)Erlang代码如下: -module(spawntest). -export([test/0, loop/1]). loop(N) -> if N /= 0 -> io:format("the ~wth task has spawn~n", [N]); true-> void end, loop(0). //无限循环,不停止 test()-> [spawn(?MODULE, loop, [N]) || N <- lists:seq(1,1000000)]. 运行结果如下图: Rust的到9万多进程的时候,就Out of memory了。 erlang到3万多条就超出系统限制了,CMD里 Erl + P