<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:12pt">Thanx a lot.. This worked like a charm.. Performance boost is 50x. Earlier I could get 11k fetches per second, now I can get 550k per second.<br><br>-- baliga<br><div> </div>"The quality of programmers is a decreasing function of the density of GOTO statements in the programs they produce." - Edsger W. Dijkstra<br><br><span><a target="_blank" href="http://dudefrommangalore.blogspot.com/">http://dudefrommangalore.blogspot.com/</a></span><br><div><br></div><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><br><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"><font size="2" face="Tahoma"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Tony Rogvall <tony@rogvall.se><br><b><span style="font-weight: bold;">To:</span></b>
Yogish Baliga <yogishb@yahoo.com><br><b><span style="font-weight: bold;">Cc:</span></b> erlang-questions@erlang.org<br><b><span style="font-weight: bold;">Sent:</span></b> Monday, March 30, 2009 12:53:22 AM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [erlang-questions] Sharing data by reference<br></font><br>
<br><br>On 30 mar 2009, at 01.49, Yogish Baliga wrote:<br>> <br>> I read in this post<br>> <br><span>> <a target="_blank" href="http://www.erlang.org/pipermail/erlang-questions/2009-March/042503.html">http://www.erlang.org/pipermail/erlang-questions/2009-March/042503.html</a></span><br>> <br>> that compile time constants are in constant pool and are used by reference in each process. This works well for compile time constants. What about the the run-time constant, for example configuration read from the file. This configuration remains constant through-out the life time of the VM. Is it possible to put that in the constant pool and have a reference to it in each process instead of copying around?<br><br>A couple of years ago I implement a (yet an other) configuration system that<br>generated a module for some of the constants on the fly. At that time the<br>reason was to have a faster access to constants.<br><br>With the latest
development using shared module constants this approach may<br>be even better.<br><br>Since compilation is a bit slow (compared to accessing the constants)<br>The rate the constants are updated should be slow :-)<br><br>The idea is basically:<br><br>- System change it's configuration.<br>- Generate some part of the configuration to a module.<br>- Compile and load that module.<br><br>If the configuration change is done asynchronously in a live system, some code may require<br>a consistent view of constants in the generated module (The constants are related somehow).<br>Then a access function reference may come in handy, since it will be connected to<br>the module version that it was created with.<br><br>Example:<br><br>-module(my_globs).<br>-export([name/0, version/0, value1/0, value2/0]).<br><br>name() -> "System name".<br>version() -> "1.1".<br><br>value1() -> 100.<br>value2() -> 200.<br><br>%--<br>Assume that value1 MUST be
less than value2. Then we MAY have a problem when if this module is reloaded<br>while executing the following code:<br><br> true = my_globs:value1() < my_globs:value2().<br><br>Since the configuration may be reloaded between the calls to my_globs!<br>If we add an access function to my_globs:<br><br>-module(my_globs).<br>-export([name/0, version/0, value1/0, value2/0]).<br>-export([access/0]).<br><br>name() -> "System name".<br>version() -> "1.2".<br><br>value1() -> 50.<br>value2() -> 100.<br><br>access() -><br> fun(value1) -> value1();<br> (value2) -> value2()<br> end.<br>% -<br><br>We can now use a transaction like test like:<br><br> Access = my_globs:access(),<br> true = (Access(value1) < Access(value2))<br><br>This will work as long the code is not reloaded twice during the evaluation of the
'Access' function.<br>In which case I guess the code would be killed anyway ;-)<br><br>Hope this may be useful idea.<br><br>/Tony<br><br>> <br>> Thanx,<br>> -- baliga<br>> <br>> <br>> "The quality of programmers is a decreasing function of the density of GOTO statements in the programs they produce." - Edsger W. Dijkstra<br>> <br><span>> <a target="_blank" href="http://dudefrommangalore.blogspot.com">http://dudefrommangalore.blogspot.com</a></span><br>> _______________________________________________<br>> erlang-questions mailing list<br>> <a ymailto="mailto:erlang-questions@erlang.org" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br><span>> <a target="_blank" href="http://www.erlang.org/mailman/listinfo/erlang-questions">http://www.erlang.org/mailman/listinfo/erlang-questions</a></span><br><br></div></div></div></body></html>