[erlang-questions] Re: Best way to implement a simple cache
Fri Nov 13 06:10:52 CET 2009
On Nov 12, 2009, at 5:17 PM, Thijs wrote:
> On Nov 13, 8:36 am, Scott Lystig Fritchie <fritc...@REDACTED>
>> ... except that public/protected ETS table access isn't free, either.
>> The VM has to play games with controlling multi-scheduler access to
>> ETS's underlying hash table/binary tree. I haven't measured with an
> You are right, but in my experience a public ETS table significantly
> outperforms process-mediated access. I'm curious how did you optimize
> this further?
Let's solve this with numbers!
Test || Multiplier || Percent Slowdown || Reads
ets plain 1.00x 0%
ets public 1.01x 1%
ets public named table 1.10x 10%
mnesia ram copies 1.87x 87%
process based cache 9.86x 886%
BDB driver 56.37x 5,537%
While I have my benchmarking hat on, let's check function calls too:
Call Method || Multiplier || Percent Slowdown || Calls
apply(?MODULE, foo, ) 1.00x 0%
?MODULE:foo() 1.01x 1%
foo() 1.09x 9%
fun() -> ok end() 3.15x 215%
apply(foo, ) 3.50x 250%
Module:Fun() 5.22x 422%
The slowest method of function invocation still yields 18+ million
calls per second.
• Tests were run on my ancient (almost four year old) iMac (Core
Erlang R13B02 (erts-5.7.3) [source] [smp:2:2] [rq:2] [async-threads:0]
• No scheduler binding to CPUs.
• For the function call benchmark: foo() -> ok. Module = ?MODULE,
Fun = foo.
• The "process based cache" is my fleshed out production version of
the duomark process cache.
Disclaimer: The results vary in absolute numbers for multiple runs of
but results retain their relative positions in the rankings each time.
I'll get around to making a statistically valid erlang benchmark suite
Matt Stancliff San Jose, CA
AIM: seijimr iPhone: 678-591-9337
"The best way to predict the future is to invent it." --Alan Kay
More information about the erlang-questions