[erlang-questions] pickler combinators + closure fetching from ets vs process registry

Joel Reymont joelr1@REDACTED
Mon Sep 15 16:30:12 CEST 2008


Has anyone benchmarked the speed of fetching a closure from ETS vs a  
process-based registry (gen_server + gb_trees)?

I implemented closure-based serialization [1] based on Andrew  
Kennedy's pickle combinators which lets me define both the pickler and  
the unpickler for a record like this:

test_start_game() ->
     record(test_start_game, {
              game_type(),
              expected_players(),
              limit(),
              start_delay(),
              player_timeout(),
              cards()
             }).

I can then marshall data into an io list with with  
pickle(test_start_game(), Data) and get a record back with  
unpickle(test_start_game(), Bin).

The problem is that a "command code" needs to be stored into the  
binary to make it possible to unpickle a proper record. This requires  
a mapping from record tag to command code and pickler as well as a  
mapping from command code to unpickler.

I have these mappings implemented as functions, e.g.

write(R) when is_record(R, bad) ->
     [?PP_BAD|pickle(bad(), R)];

and

read(<<?PP_BAD, Bin/binary>>) ->
     unpickle(bad(), Bin);

The two issues here for me are the long list of write and read clauses  
and the closured generated by bad() on every packet read and write.

I'm thinking of storing the tag to pickler and command code mappings  
in ETS or a process-based registry. This will both store pickler  
closures once and drastically trim the amount of code by getting rid  
of the write/read clauses.

Has anyone benchmarked ETS vs a process-based registry for retrieval  
of function closures?

	Thanks, Joel

P.S. I would appreciate comments or suggestions on how the pickler  
code could be further optimized.

[1] http://wagerlabs.com/erlang/pickle.erl

--
wagerlabs.com




More information about the erlang-questions mailing list