tags:

views:

10

answers:

0

I created two tables whose definitions are


-record(student,{id,name1,name2}).
-record(student2,{reg,year}).


Assume the following macro definitions

-define(NODE_POOL(N),{node_pool,N}).
-define(FRAGS(N),{n_fragments,N}).
-define(DISC_COPIES(N),{n_disc_copies,N}).
-define(ATTRS(Rec),{attributes,record_info(fields,Rec)}).

Using the following macro definition, i could create (for each table), 4 fragments, with
n_disc_copies = 2, and i used a node pool of 2 nodes on the same host. check this below.

-define(CREATE(Table,Nodes,No_of_frags,N_disc_copies),
    mnesia:create_table(Table,[{frag_properties,[?NODE_POOL(Nodes),?FRAGS(No_of_frags),
    ?DISC_COPIES(N_disc_copies)]},?ATTRS(Table)])).

Using this piece of code,Nodes = ['[email protected]','[email protected]'],
No_of_frags = 4,N_disc_copies = 2

start(Nodes,No_of_frags,N_disc_copies)->
    ?CREATE(student2,Nodes,No_of_frags,N_disc_copies),
    ?CREATE(student,Nodes,No_of_frags,N_disc_copies),   
    ok.

I populated these two tables using a number of processes until mnesia:info(), returned results as these:

student_frag4  : with 1268103  records occupying 193047533 bytes on disc
student2_frag4 : with 1673066  records occupying 199942998 bytes on disc
student        : with 1269044  records occupying 193119653 bytes on disc
student_frag3  : with 1269578  records occupying 193114408 bytes on disc
student2_frag3 : with 1673945  records occupying 200058764 bytes on disc
student2       : with 1674954  records occupying 200088328 bytes on disc
student_frag2  : with 1267914  records occupying 192954162 bytes on disc
student2_frag2 : with 1672363  records occupying 200008994 bytes on disc
schema         : with 9        records occupying 1506     words of mem

In my application, i had several abstraction that provide more info, check these out below. I could get the memory used up by each fragment of table: student and student2 like this..

([email protected])9> ecampus_frag:memory(student).
[{student,{{bytes,193119653},
           {kilobytes,193119.653},
           {megabytes,193.119653},
           {gigabytes,0.193119653}}},
 {student_frag2,{{bytes,192954162},
                 {kilobytes,192954.162},
                 {megabytes,192.954162},
                 {gigabytes,0.192954162}}},
 {student_frag3,{{bytes,193114408},
                 {kilobytes,193114.408},
                 {megabytes,193.114408},
                 {gigabytes,0.193114408}}},
 {student_frag4,{{bytes,193047533},
                 {kilobytes,193047.533},
                 {megabytes,193.047533},
                 {gigabytes,0.193047533}}}]
([email protected])14> ecampus_frag:memory(student2).
[{student2,{{bytes,200088328},
            {kilobytes,200088.328},
            {megabytes,200.088328},
            {gigabytes,0.200088328}}},
 {student2_frag2,{{bytes,200008994},
                  {kilobytes,200008.994},
                  {megabytes,200.008994},
                  {gigabytes,0.200008994}}},
 {student2_frag3,{{bytes,200058764},
                  {kilobytes,200058.764},
                  {megabytes,200.058764},
                  {gigabytes,0.200058764}}},
 {student2_frag4,{{bytes,199942998},
                  {kilobytes,199942.998},
                  {megabytes,199.942998},
                  {gigabytes,0.199942998}}}]

To get the total memory use up by the entire table,(by summing up memory of individual fragments) i would call...

([email protected])17> ecampus_frag:total_memory(student2).
{{bytes,800099084},
 {kilobytes,800099.084},
 {megabytes,800.099084},
 {gigabytes,0.800099084}}

([email protected])18> ecampus_frag:total_memory(student).
{{bytes,772235756},
 {kilobytes,772235.756},
 {megabytes,772.235756},
 {gigabytes,0.772235756}}

To find the total number of records i had pumped in....

([email protected])23> ecampus_frag:total_records(student).
5074639
([email protected])24> ecampus_frag:total_records(student2).
6694328

The part i know that mnesia_frag distributes records well when the number of fragments are a power of 2 e.g 4,8,32,64,... But when i tried to add a fragment by this method below, the result is disturbing.

([email protected])19> mnesia:change_table_frag(student2,{add_frag,[]}).
{aborted,{combine_error,student2_frag5,
                        "Too few nodes in node_pool"}}

In the documentation, i cannot find an explanation for this.
How many erlang nodes are required against a given number of fragments?
Is there a relationship between n_disc_copies and the size of the node_pool?
What is the significance of node_pool size when working with Mnesia fragmentation

Thanks... /[email protected]