[Set] collection of common Erlang commands

Source: Internet
Author: User

Reprinted: 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"' % specifies the directory when starting Erlang

Mnesia: system_info (directory). % to get the directory stored in the mnesia table

Mnesia: Info ().

Mnesia: change_table_frag (Dictionary, {activate, []}). % activate mnesia Fragment

Activate table shards: (A @ localhost) 25> mnesia: change_table_frag (Dictionary, {activate, []}).

{Atomic, OK}

Check whether the resolution is activated:

(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]}]
Now we can add table shards. For convenience, create a function to obtain the frag_dist of the table.

(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.10967289768>

Test:

(A @ localhost)30> getfragnodes ().

[{B @ localhost, 0}, {c @ localhost, 0}, {A @ localhost, 1}]

Now you can add a shard. Through the node list returned by getfragnodes, mnesia can add the new Shard to a relatively idle node by load balancing:

(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, phash2 }}, {n_fragments, 2 }, {node_pool, [A @ localhost, B @ localhost, c @ localhost]}]

We can see {n_fragments, 2}, which has been increased to 2. Check the node to which the new part is assigned:

(A @ localhost)37> getfragnodes ().

[{C @ localhost, 0}, {A @ localhost, 1}, {B @ localhost, 1}]

We can see that each of node A and Node B has a shard, And the shard of Node B is new.

7. Erl-man ERL

Erl-man lists

8. Tool commands

TV: Start ()

Debugger: Start ()

Appmon: Start ()

Code: clash ()

Pman: Start ()

9. whereis (MOD)

10. process_info (PID, message_queue_len ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.