[erlang-questions] Is a process necessary in front of mnesia?
Evans, Matthew
mevans@REDACTED
Thu Oct 14 23:37:32 CEST 2010
If you mean remove your own gen_server, then yes it is.
One thing that a "private" gen_server does give you is the ability to manage certain operations in a more efficient manner, while keeping a consistent API.
For example I have an application that normally does quick key-based lookups. Sometimes however it is necessary to do select or match_object queries on large data-sets. Having a gen_server "front" these requests allows you to wrap the whole operation in a spawn, while providing a simple to use API for the user.
e.g.
handle_call({really_complex_search,SearchStuff},From,State) ->
Pattern = #mnesia_table{some_element = SearchStuff, _ = '_'}
spawn(fun()->
case mnesia:dirty_match_object(SearchStuff) of
[Rec] -> gen_server:reply(From,Rec);
_ -> gen_server:reply(From,error)
end
end)
{noreply,State};
Certainly the calling application could do that too, but in our case the access method needs to be simple.
Another thing I use a gen_server intermediately for is to prioritize certain operations over others. In one case we are supposed to process many writes as a low-priority task that doesn't affect the read rate. Having a gen_server in the way lets us do that.
Matt
-----Original Message-----
From: erlang-questions@REDACTED [mailto:erlang-questions@REDACTED] On Behalf Of Woody Peterson
Sent: Thursday, October 14, 2010 1:41 PM
To: Erlang-Questions Questions
Subject: [erlang-questions] Is a process necessary in front of mnesia?
Hi All,
In the pragmatic screencasts' Erlang series, there is a gen_server in
charge of writing to mnesia. In refactoring a small erlang system my
company's building, we still have that boilerplate handling mnesia,
but thought we should remove the gen_server entirely, as we could just
use a function instead of a process as per erlang's best practices (http://www.erlang.se/doc/programming_rules.shtml#HDR16
). Note that this gen_server holds no state, which is probably not a
rule for when to not use a process, but seems like it could be a
smell. I figure the gen_server in the screencasts could have just been
there as a learning tool, so is there a reason beyond education to put
a serializing process in front of mnesia as a rule? Are we right to
assume we can have possibly tens of thousands of processes sending
write messages to mnesia directly as opposed to a gen_server in front
of it?
Thanks,
-Woody
________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
More information about the erlang-questions
mailing list