erlang常用命令收集

来源:互联网 发布:java程序员为什么转行 编辑:程序博客网 时间:2024/05/18 02:13
 转载:http://www.cnblogs.com/gordonchao/archive/2011/01/06.html

1.net_adm:names()

2.record_info(fields, Tab)

3.Mod:module_info(attributes)

4.beam_lib:chunks("Mod.beam", [attributes]).

5. -vsn(1234).

  -author({gordon, chao}).

6. mnesia

erl -mnesia dir '"/home/gordon/mnesia"' %启动erlang时指定目录

mnesia:system_info(directory).%得到mnesia表存放的目录

mnesia:info().

mnesia:change_table_frag(dictionary, {activate, []}).%激活mnesia分片

激活表格的分片:(a@localhost)25> mnesia:change_table_frag(dictionary, {activate, []}).  

{atomic,ok}

查看分辨是否激活了:

(a@localhost)26> mnesia:table_info(dictionary, frag_properties).                [{base_table,dictionary}, {foreign_key,undefined}, {hash_module,mnesia_frag_hash}, {hash_state,{hash_state,1,1,0,phash2}}, {n_fragments,1}, {node_pool,[a@localhost,b@localhost,c@localhost]}]
现在我们可以添加表的分片了我为了方便,先创建一个函数,这个函数的作用是获得表的frag_dist

(a@localhost)28> GetTableInfo = fun(Item) -> mnesia:table_info(dictionary, Item) end. 

#Fun<erl_eval.6.35866844> 

(a@localhost)29> GetFragNodes = fun()-> mnesia:activity(sync_dirty, GetTableInfo, [frag_dist], mnesia_frag) end.#Fun<erl_eval.20.67289768>

测试一下:

(a@localhost)30> GetFragNodes().                

[{b@localhost,0},{c@localhost,0},{a@localhost,1}]

现在可以添加一个分片了,通过GetFragNodes返回的节点列表,mnesia可以负载均衡的把新的分片添加到相对空闲的节点上:

(a@localhost)35> mnesia:change_table_frag(dictionary, {add_frag, GetFragNodes()}).{atomic,ok}

(a@localhost)36> mnesia:table_info(dictionary, frag_properties).                [{base_table,dictionary}, {foreign_key,undefined}, {hash_module,mnesia_frag_hash}, {hash_state,{hash_state,2,1,1,phash2}}, {n_fragments,2}, {node_pool,[a@localhost,b@localhost,c@localhost]}]

看到了 {n_fragments,2},增加到2个了。看看新的分片分派到哪个节点了:

(a@localhost)37> GetFragNodes().            

[{c@localhost,0},{a@localhost,1},{b@localhost,1}]

看到了a节点和b节点各有一个分片,b节点的分片是新的。

7.erl -man erl

   erl -man lists

8.工具类命令

tv:start()

debugger:start()

appmon:start()

code:clash()

pman:start()

9.whereis(Mod)

10.process_info(Pid, message_queue_len).

原创粉丝点击