Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Erlang Exploration - Dict, Maps, Ets, Mnesia - Array Implemetation & Performance Profiling

4,162 views

Published on

Erlang Array implementation by Dict, Maps, Ets, or Mnesia.
Performance profiling

Published in: Technology
  • DOWNLOAD FULL. BOOKS INTO AVAILABLE FORMAT, ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL. BOOKS INTO AVAILABLE FORMAT, ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL. BOOKS INTO AVAILABLE FORMAT, ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL. BOOKS INTO AVAILABLE FORMAT, ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL. BOOKS INTO AVAILABLE FORMAT, ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Erlang Exploration - Dict, Maps, Ets, Mnesia - Array Implemetation & Performance Profiling

  1. 1. Erlang/OTP Exploration Dict, Maps, Ets, Menesia Array Implementation and their Performance Profiling by Kai Zhou http://ca.linkedin.com/in/kaizhou93/
  2. 2. Array by Ets build_ets_arr(Array_size) -> build_ets_arr(Array_size, ets:new(ets_arr,[set])). build_ets_arr(0, Arr) -> Arr; build_ets_arr(Array_size, Arr) -> ets:insert(Arr, {Array_size-1, 0}), build_ets_arr(Array_size-1, Arr). %% Array index is from 0 to N-1, each element is initiated as 0; %% Tail recursive; %% The same below.
  3. 3. Array by Dict build_dict_arr(Array_size) -> build_dict_arr(Array_size, dict:new()). build_dict_arr(0, Arr) -> Arr; build_dict_arr(Array_size, Arr)-> build_dict_arr(Array_size-1, dict:store(Array_size-1, 0, Arr)).
  4. 4. Array by Maps build_map_arr(Array_size) -> build_map_arr(Array_size, maps:new()). build_map_arr(0, Arr) -> Arr; build_map_arr(Array_size,Arr) -> build_map_arr(Array_size-1, maps:put(Array_size-1, 0, Arr)). %% Note, maps is not available until OTP R17. %% The test described behind was run on R17 rc2. %% Why “put(N, 0 Arr)” instead of “Arr#{N=>0}” ? %% Because a variable as a key is not supported  -- may need improve here ?
  5. 5. Array by Mnesia -record(db_arr,{ind,val}). build_db_arr(Array_size) -> application:start(mnesia), mnesia:create_table(db_arr, [{attributes, record_info(fields, db_arr)}, {ram_copies, [node()]}]), build_db_arr(Array_size, go). build_db_arr(0,_) -> db_arr; build_db_arr(Array_size,_) -> mnesia:dirty_write(#db_arr{ind=Array_size-1, val=0}), build_db_arr(Array_size-1). %% start(mnesia) inserted here is not good practice, it is just for easy use of the test. %% It costs only a few milliseconds when mnesia is started already. %% type “set” and “ram_copies” are default for creating a new table.
  6. 6. An array factory build_array(Method, Array_size) -> case Method of ets -> build_ets_arr(Array_size); dict -> build_dict_arr(Array_size); map -> build_map_arr(Array_size); mnesia -> build_db_arr(Array_size); _ -> 'method not supported!' end . lookup(Method, Arr, I) -> case Method of ets -> ets:lookup(Arr, I); dict -> dict:fetch(I, Arr); map -> maps:find(I, Arr); mnesia -> mnesia:dirty_read({Arr, I}); _ -> 'method not supported!' end .
  7. 7. Profiling their performance prof(Method, Array_size, Ntimes) -> if Method==mnesia -> application:start(mnesia), mnesia:delete_table(db_arr); true -> ok end, {Tb,Arr}= timer:tc(fun() -> build_array(Method, Array_size) end), io:format("To create ~w elements of ~w array takes ~w milliseconds~n", [Array_size,Method,Tb]), Samples=[0|[X*(Array_size div Ntimes)-1||X<-lists:seq(1, Ntimes)]], lists:foreach(fun(I)-> {Tl,_}= timer:tc(fun() -> lookup(Method, Arr, I) end), io:format("To find the ~wth element of ~w array takes ~w milliseconds~n", [I,Method,Tl]) end , Samples).
  8. 8. Test Environment 3> erlang:system_info(system_version). "Erlang/OTP 17 [RELEASE CANDIDATE 2] [erts-6.0] [source] [64-bit] [smp:4:4] [async- threads:10] [hipe] [kernel-poll:false]n"
  9. 9. How is Dict ? 5> which_array:prof(dict, 50000, 30). To create 50000 elements of dict array takes 117950 milliseconds To find the 0th element of dict array takes 2 milliseconds To find the 1665th element of dict array takes 2 milliseconds To find the 3331th element of dict array takes 1 milliseconds To find the 4997th element of dict array takes 1 milliseconds To find the 6663th element of dict array takes 1 milliseconds To find the 8329th element of dict array takes 1 milliseconds To find the 9995th element of dict array takes 1 milliseconds To find the 11661th element of dict array takes 2 milliseconds To find the 13327th element of dict array takes 1 milliseconds To find the 14993th element of dict array takes 2 milliseconds To find the 16659th element of dict array takes 1 milliseconds To find the 18325th element of dict array takes 2 milliseconds To find the 19991th element of dict array takes 1 milliseconds To find the 21657th element of dict array takes 1 milliseconds To find the 23323th element of dict array takes 1 milliseconds To find the 24989th element of dict array takes 1 milliseconds To find the 26655th element of dict array takes 1 milliseconds To find the 28321th element of dict array takes 1 milliseconds To find the 29987th element of dict array takes 1 milliseconds To find the 31653th element of dict array takes 1 milliseconds To find the 33319th element of dict array takes 1 milliseconds To find the 34985th element of dict array takes 1 milliseconds To find the 36651th element of dict array takes 1 milliseconds To find the 38317th element of dict array takes 1 milliseconds To find the 39983th element of dict array takes 1 milliseconds To find the 41649th element of dict array takes 1 milliseconds To find the 43315th element of dict array takes 1 milliseconds To find the 44981th element of dict array takes 1 milliseconds To find the 46647th element of dict array takes 1 milliseconds To find the 48313th element of dict array takes 1 milliseconds To find the 49979th element of dict array takes 1 milliseconds ok %% Impressive. Dict, written of purely Erlang, performed very well. %% 1.2 seconds to create 50K-elelment array and almost constantly 1 milliseconds to find an element by given key. Well hashed obviously.
  10. 10. How is Maps ? 7> which_array:prof(map, 50000, 30). To create 50000 elements of map array takes 6194249 milliseconds To find the 0th element of map array takes 1 milliseconds To find the 1665th element of map array takes 3 milliseconds To find the 3331th element of map array takes 4 milliseconds To find the 4997th element of map array takes 6 milliseconds To find the 6663th element of map array takes 7 milliseconds To find the 8329th element of map array takes 8 milliseconds To find the 9995th element of map array takes 11 milliseconds To find the 11661th element of map array takes 11 milliseconds To find the 13327th element of map array takes 14 milliseconds To find the 14993th element of map array takes 17 milliseconds To find the 16659th element of map array takes 18 milliseconds To find the 18325th element of map array takes 19 milliseconds To find the 19991th element of map array takes 21 milliseconds To find the 21657th element of map array takes 24 milliseconds To find the 23323th element of map array takes 25 milliseconds To find the 24989th element of map array takes 26 milliseconds To find the 26655th element of map array takes 29 milliseconds To find the 28321th element of map array takes 30 milliseconds To find the 29987th element of map array takes 32 milliseconds To find the 31653th element of map array takes 33 milliseconds To find the 33319th element of map array takes 35 milliseconds To find the 34985th element of map array takes 37 milliseconds To find the 36651th element of map array takes 39 milliseconds To find the 38317th element of map array takes 40 milliseconds To find the 39983th element of map array takes 42 milliseconds To find the 41649th element of map array takes 43 milliseconds To find the 43315th element of map array takes 45 milliseconds To find the 44981th element of map array takes 47 milliseconds To find the 46647th element of map array takes 48 milliseconds To find the 48313th element of map array takes 51 milliseconds To find the 49979th element of map array takes 52 milliseconds ok %% Map doesn’t seem to provide efficient key-value store. Lookup time is growing. %% Map is more intended to replace record some time ? %% More discussions: http://joearms.github.io/2014/02/01/big-changes-to-erlang.html
  11. 11. How is Ets ? 8> which_array:prof(ets, 50000, 30). To create 50000 elements of ets array takes 24851 milliseconds To find the 0th element of ets array takes 2 milliseconds To find the 1665th element of ets array takes 2 milliseconds To find the 3331th element of ets array takes 2 milliseconds To find the 4997th element of ets array takes 3 milliseconds To find the 6663th element of ets array takes 3 milliseconds To find the 8329th element of ets array takes 2 milliseconds To find the 9995th element of ets array takes 1 milliseconds To find the 11661th element of ets array takes 1 milliseconds To find the 13327th element of ets array takes 3 milliseconds To find the 14993th element of ets array takes 3 milliseconds To find the 16659th element of ets array takes 2 milliseconds To find the 18325th element of ets array takes 2 milliseconds To find the 19991th element of ets array takes 2 milliseconds To find the 21657th element of ets array takes 2 milliseconds To find the 23323th element of ets array takes 1 milliseconds To find the 24989th element of ets array takes 1 milliseconds To find the 26655th element of ets array takes 0 milliseconds To find the 28321th element of ets array takes 1 milliseconds To find the 29987th element of ets array takes 1 milliseconds To find the 31653th element of ets array takes 2 milliseconds To find the 33319th element of ets array takes 1 milliseconds To find the 34985th element of ets array takes 1 milliseconds To find the 36651th element of ets array takes 1 milliseconds To find the 38317th element of ets array takes 1 milliseconds To find the 39983th element of ets array takes 1 milliseconds To find the 41649th element of ets array takes 2 milliseconds To find the 43315th element of ets array takes 1 milliseconds To find the 44981th element of ets array takes 1 milliseconds To find the 46647th element of ets array takes 1 milliseconds To find the 48313th element of ets array takes 1 milliseconds To find the 49979th element of ets array takes 1 milliseconds ok %% Amazing. Fast on both insert and lookup.
  12. 12. How is Mnesia In-memory DB ? 9> which_array:prof(mnesia, 50000, 30). To create 50000 elements of mnesia array takes 24254789 milliseconds To find the 0th element of mnesia array takes 5 milliseconds To find the 1665th element of mnesia array takes 4 milliseconds To find the 3331th element of mnesia array takes 3 milliseconds To find the 4997th element of mnesia array takes 3 milliseconds To find the 6663th element of mnesia array takes 69 milliseconds To find the 8329th element of mnesia array takes 2 milliseconds To find the 9995th element of mnesia array takes 2 milliseconds To find the 11661th element of mnesia array takes 2 milliseconds To find the 13327th element of mnesia array takes 6 milliseconds To find the 14993th element of mnesia array takes 3 milliseconds To find the 16659th element of mnesia array takes 3 milliseconds To find the 18325th element of mnesia array takes 2 milliseconds To find the 19991th element of mnesia array takes 2 milliseconds To find the 21657th element of mnesia array takes 2 milliseconds To find the 23323th element of mnesia array takes 4 milliseconds To find the 24989th element of mnesia array takes 3 milliseconds To find the 26655th element of mnesia array takes 3 milliseconds To find the 28321th element of mnesia array takes 3 milliseconds To find the 29987th element of mnesia array takes 3 milliseconds To find the 31653th element of mnesia array takes 3 milliseconds To find the 33319th element of mnesia array takes 3 milliseconds To find the 34985th element of mnesia array takes 2 milliseconds To find the 36651th element of mnesia array takes 2 milliseconds To find the 38317th element of mnesia array takes 2 milliseconds To find the 39983th element of mnesia array takes 3 milliseconds To find the 41649th element of mnesia array takes 2 milliseconds To find the 43315th element of mnesia array takes 3 milliseconds To find the 44981th element of mnesia array takes 2 milliseconds To find the 46647th element of mnesia array takes 3 milliseconds To find the 48313th element of mnesia array takes 2 milliseconds To find the 49979th element of mnesia array takes 4 milliseconds ok %% 24 seconds to create a 50K-element array, too slow but fine for fixed-sized array. %% Lookup is very good.
  13. 13. Which one I choose for my project ? • Obviously I won’t use Maps. • Dict is beautiful, but my array is big and part of status of a very busy gen_server. I don’t want it be copied over and over like crazy. Dict is gone. • Ets is amazing, and it is kind of local global, need no copy. However, I may need a distributed global to scale my product, need to use Mnesia by then. • I will use Ets or Mnesia, it is easy to switch between them as shown before.

×