Reputation: 3235
I implemented an otp system using gen_server and gen_fsm. There is a configuration file to be read for some values that the software needs in order to run, an example may be:
{values, [value1, value2, value3]}.
I used a macro to extract one of these values
define(VALUES, my_utility:get_conf_value(values)).
The question is the following: since ?VALUES may be called very often, and therefore the configuration file is parsed many times, should I embed ?VALUES inside the state of my gen_server of gen_fsm and extract it with a call any time I need it?
In fact I really appreciated the previous implementation because one could change the behaviour of the software just by changing the values inside the configuration file, without any #state{} change or call.
Which solution do you prefer?
Upvotes: 1
Views: 262
Reputation: 26121
Personally I think best solution is make configuration as module. Benefits are:
P.S.: See network module load (aka nl/1 in shell) for cluster wide config change.
Upvotes: 2
Reputation: 5103
This is actually a topic that is much harder than what one would first think. For example :
So, to analyse your current solutions:
Another solution would be to store the configuration as code. You could for example have a special configuration module, which you create using a parse transform or by generating the actual source file. With this solution, the configuration values resides in the constant pool of the VM and fetching them creates as little garbage as possible (depending on what do you with the data later).
Upvotes: 2
Reputation: 16577
The solution will depend upon your requirements. Performance vs "correctness".
A possible solution would be to keep the configuration in a process state and re-read it regularly (checking if the file modification time has changed). This might be a good compromise between the two worlds.
Summary:
Requirements not considered: security, stability (corrupt config file?)
Upvotes: 2