a study of erlang ets table implementations and
play

A Study of Erlang ETS Table Implementations and Performance Or: - PowerPoint PPT Presentation

A Study of Erlang ETS Table Implementations and Performance Or: Judy Arrays Are Amazing Data Structures Scott Lystig Fritchie <slfritchie@snookles.com> Snookles Music Consulting A Study of Erlang ETS Table Implementations and Performance


  1. A Study of Erlang ETS Table Implementations and Performance Or: Judy Arrays Are Amazing Data Structures Scott Lystig Fritchie <slfritchie@snookles.com> Snookles Music Consulting A Study of Erlang ETS Table Implementations and Performance – p.1/19

  2. Overview ETS table data structures Judy arrays “Contiguous Key Problem” Solving the “Contiguous Key Problem” Performance results A Study of Erlang ETS Table Implementations and Performance – p.2/19

  3. Audience Erlang community Using ETS directly Using ETS indirectly via Mnesia and other OTP applications C/C++ developers using hash tables and balanced trees Performance gains by using “Judy arrays” can be impressive Consider using Judy arrays in your applications A Study of Erlang ETS Table Implementations and Performance – p.3/19

  4. ETS Table Implementations Types included in Erlang/OTP: AVL balanced binary tree: ordered_set Resizable linear hash table: set, bag, duplicate_bag New research types: In-memory B-tree: btree Judy arrays (based on tries): judysl, judyesl, judyeh A Study of Erlang ETS Table Implementations and Performance – p.4/19

  5. Judy Arrays Invented by Doug Baskins, implemented by Hewlett-Packard. Named after Baskins’s sister. Source code now available under GNU LGPL license. Source & docs at http://judy.sourceforge.net/ A Study of Erlang ETS Table Implementations and Performance – p.5/19

  6. Judy Arrays (continued) Judy arrays are dynamic arrays Index = 1 word, 32- or 64-bit Value = 1 bit or 1 word Handles small & large populations, sparse & dense populations, no tuning parameters! Implemented as a logical 256-ary trie A Study of Erlang ETS Table Implementations and Performance – p.6/19

  7. Data Structures Review: The Trie *ABC . . . Z Root Node *ABCDEFGHIJKLMNOPQRSTUVWXYZ *ABC . . . QRST . . . Z *ABC . . . JKL . . . Z *ABCDEFGHIJ . . . Z A AIR AISLE ASK ASKED ASKING A Study of Erlang ETS Table Implementations and Performance – p.7/19

  8. Data Structures Review: The Trie *ABC . . . Z Root Node *ABCDEFGHIJKLMNOPQRSTUVWXYZ *ABC . . . QRST . . . Z *ABC . . . JKL . . . Z *ABCDEFGHIJ . . . Z A AIR AISLE ASK ASKED ASKING A Study of Erlang ETS Table Implementations and Performance – p.7/19

  9. Data Structures Review: The Trie *ABC . . . Z Root Node *ABCDEFGHIJKLMNOPQRSTUVWXYZ *ABC . . . QRST . . . Z *ABC . . . JKL . . . Z *ABCDEFGHIJ . . . Z A AIR AISLE ASK ASKED ASKING A Study of Erlang ETS Table Implementations and Performance – p.7/19

  10. Data Structures Review: The Trie *ABC . . . Z Root Node *ABCDEFGHIJKLMNOPQRSTUVWXYZ *ABC . . . QRST . . . Z *ABC . . . JKL . . . Z *ABCDEFGHIJ . . . Z A AIR AISLE ASK ASKED ASKING A Study of Erlang ETS Table Implementations and Performance – p.7/19

  11. Data Structures Review: The Trie *ABC . . . Z Root Node *ABCDEFGHIJKLMNOPQRSTUVWXYZ *ABC . . . QRST . . . Z *ABC . . . JKL . . . Z *ABCDEFGHIJ . . . Z A AIR AISLE ASK ASKED ASKING A Study of Erlang ETS Table Implementations and Performance – p.7/19

  12. JudySL: A Trie of JudyL Arrays BE \0 \0 \0 BEAR BEEH Short−cut leaf JudyL HOUS E−PAINT\0 I VE\0 Short−cut leaf JudyL Words: BE, BEAR, BEEHOUSE−PAINT, BEEHIVE A Study of Erlang ETS Table Implementations and Performance – p.8/19

  13. JudyESL: A Variation of JudySL len=−2, data= Short−cut leaf BE \0 \0 BEAR len=0, data= BEEH Short−cut leaf JudyL len=3, data=IVE Short−cut leaf Words: BE, BEAR, BEEHIVE A Study of Erlang ETS Table Implementations and Performance – p.9/19

  14. The Contiguous Key Problem Example tuple Atom Table {scott, "scott", Binary: Binary: <<"To">>, <<"scott">>} start = 3 start = 0 number name length = 5 length = 2 val val Tuple, size = 4: element 0 = atom #A A − 1 foo element 1 A scott element 2 A + 1 bar element 3 99 116 Ref−counted binary: c t refcount = 2 size = 8 115 data = 84,111,58,115,99,111,116,116 111 116 s T o : s c o t t o t A Study of Erlang ETS Table Implementations and Performance – p.10/19

  15. Judy-Based Tables judysl table type Serialized key = encode_NUL_bytes(term_to_binary(Key)) judyesl table type The JudyESL library uses explicit string length, not NUL termination. Serialized key = term_to_binary(Key) NOTE: JudySL and JudyESL preserve lexigraphic sort order of serialized keys, not of original Erlang key terms . A Study of Erlang ETS Table Implementations and Performance – p.11/19

  16. � ✁✂ ✄ � Judy-Based Tables (continued) judyeh table type JudyL array for hash table: hash buckets! No serialization, unlike judysl and judyesl No meta-trie: search one JudyL array, not several Hash collision rate % for 7 million items ☎✝✆ A Study of Erlang ETS Table Implementations and Performance – p.12/19

  17. ✠ ✟ ☎ ✟ ☎ ✡ ✞ ✄ Experiment Design Intentionally maximize time executing ETS-related code. Show table differences as much as possible. Benchmark time in ETS-related code: 35-70% SCCT time in ETS-related code: 18% All other parts of VM unchanged. Benchmark result graphs Overall, set is fastest “old” table type. All run times normalized against set ’s time. Run time 1.0 better CPU cache size reflected between and keys. A Study of Erlang ETS Table Implementations and Performance – p.13/19

  18. Sequential Insertion Into Empty Table 2 1.8 1.6 Time relative to ’set’ type 1.4 1.2 1 0.8 0.6 0.4 0.2 10 2 10 3 10 4 10 5 10 6 10 7 10 8 Number of keys set judysl judyeh judyesl ordered_set btree A Study of Erlang ETS Table Implementations and Performance – p.14/19

  19. Sequential Insertion, Per 1K Keys 0.25 0.2 Seconds per thousand keys 0.15 0.1 0.05 0 10 6 10 7 10 8 Number of keys set judysl judyeh judyesl ordered_set btree A Study of Erlang ETS Table Implementations and Performance – p.15/19

  20. Random Lookup in Full Table 3 2.5 Time relative to ’set’ type 2 1.5 1 0.5 10 2 10 3 10 4 10 5 10 6 10 7 10 8 Number of keys set judysl judyeh judyesl ordered_set btree A Study of Erlang ETS Table Implementations and Performance – p.16/19

  21. Forward Traversal of Full Table 3 2.5 Time relative to ’set’ type 2 1.5 1 0.5 0 10 2 10 3 10 4 10 5 10 6 10 7 10 8 Number of keys set judysl judyeh judyesl ordered_set A Study of Erlang ETS Table Implementations and Performance – p.17/19

  22. Memory Utilization Table type Memory used Memory used Difference from set by 70K keys by 21M keys 10.4MB 1,055MB 7.7% btree 10.4MB 1,036MB 5.7% judyeh 10.4MB 1,033MB 5.4% judysl 11.3MB 1,324MB 35% judyesl 10.7MB 1,129MB 15% ordered set 10.2MB 980MB — set A Study of Erlang ETS Table Implementations and Performance – p.18/19

  23. Conclusion Judy array-based ETS tables perform very well for ETS table sizes that exceed CPU cache size. Table traversal performance is probably fixable. Performance gain of Judy-based tables far exceeds extra memory consumption. JudySL- or JudyESL-based technique could perform better than set and still preserve key sort order. Using Judy arrays in a “real world” application can improve performance. Your application can probably benefit, too. A Study of Erlang ETS Table Implementations and Performance – p.19/19

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend