It is not obvious, but try change your write:<br><br>
write(_,0) -> ok;<br>
write(X,N) -><br> T = now(),<br>
mnesia:write(X#a{id = T, first = T, second = T}),<br>
write(X,N-1).<br><br>and think what happened to indexes in previous version :-)<br><br><div class="gmail_quote">On Tue, Jun 10, 2008 at 1:51 PM, Ben Hood <<a href="mailto:0x6e6562@gmail.com">0x6e6562@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br>
<br>
I'm looking into the rate of inserting rows in mnesia.<br>
<br>
Having written the attached test (that can be parameterized to insert<br>
an arbitrary amount of rows in arbitrary chunk sizes), I've found out<br>
so far that the highest throughput seems to be somebody where between<br>
50 and 200 per transaction.<br>
<br>
What surprised me a bit is the magnitude of the effect that index<br>
maintenance has on the rate of insertion.<br>
<br>
If I place secondary indexes on two non-key attributes, the throughput<br>
drops off considerably.<br>
<br>
For example, inserting 10000 rows in batches of 1000 whilst<br>
maintaining 2 non-key indexes produces the following rates of<br>
insertion per batch:<br>
<br>
rate:insert(10000,1000).<br>
Batch rate = 10688<br>
Batch rate = 7182<br>
Batch rate = 5001<br>
Batch rate = 4072<br>
Batch rate = 3300<br>
Batch rate = 2866<br>
Batch rate = 2377<br>
Batch rate = 2166<br>
Batch rate = 1807<br>
Batch rate = 1303<br>
<br>
The Batch rate is the amount of inserts per second in each batch.<br>
<br>
This tallies up with the idea that at the beginning the index overhead<br>
is tiny, but grows on each insertion, which is normal.<br>
<br>
I just didn't think that the throughput would drop off so sharply.<br>
<br>
Does anybody know if I'm doing something completely wrong or if there<br>
is a much better way to use mnesia with large tables?<br>
<br>
Thanks,<br>
<br>
Ben<br>
<br>
-module(rate).<br>
<br>
-compile(export_all).<br>
<br>
-record(a, {id,first,second}).<br>
<br>
init() -><br>
mnesia:create_schema([node()]),<br>
mnesia:start(),<br>
mnesia:delete_table(a),<br>
mnesia:create_table(a,<br>
[{attributes, record_info(fields, a)}]),<br>
mnesia:add_table_index(a,first),<br>
mnesia:add_table_index(a,second),<br>
ok.<br>
<br>
insert(N,BatchSize) -><br>
mnesia:clear_table(a),<br>
batch(N, BatchSize).<br>
<br>
batch(0,_) -> ok;<br>
batch(N,BS) -><br>
F = fun() -> write(#a{first = BS,second = BS},BS) end,<br>
{Time,_} = timer:tc(mnesia,transaction,[F]),<br>
io:format("Batch rate = ~p~n",[round(BS / Time * 1000000)]),<br>
batch(N - BS, BS).<br>
<br>
write(_,0) -> ok;<br>
write(X,N) -><br>
mnesia:write(X#a{id = now()}),<br>
write(X,N-1).<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>--Hynek (Pichi) Vychodil