algorithmic improvements for fast concurrent cuckoo
play

Algorithmic Improvements for Fast Concurrent Cuckoo Hashing - PowerPoint PPT Presentation

Algorithmic Improvements for Fast Concurrent Cuckoo Hashing Xiaozhou Li ( Princeton ) David G. Andersen (CMU) Michael Kaminsky (Intel Labs) Michael J. Freedman


  1. Algorithmic ¡Improvements ¡for ¡ Fast ¡Concurrent ¡Cuckoo ¡Hashing ¡ Xiaozhou ¡Li ¡ ( Princeton ) ¡ David ¡G. ¡Andersen ¡(CMU) ¡ Michael ¡Kaminsky ¡(Intel ¡Labs) ¡ Michael ¡J. ¡Freedman ¡(Princeton) ¡

  2. In ¡this ¡talk ¡ • How ¡to ¡build ¡a ¡fast ¡concurrent ¡hash ¡table ¡ – algorithm ¡and ¡data ¡structure ¡engineering ¡ • Experience ¡with ¡hardware ¡transacJonal ¡memory ¡ – does ¡NOT ¡obviate ¡the ¡need ¡for ¡algorithmic ¡opJmizaJons ¡

  3. Concurrent ¡hash ¡table ¡ • Indexing ¡key-­‑value ¡objects ¡ – Lookup(key) – Insert(key, value) – Delete(key) • Fundamental ¡building ¡block ¡for ¡modern ¡systems ¡ – System ¡applicaJons ¡(e.g., ¡kernel ¡caches) ¡ – Concurrent ¡user-­‑level ¡applicaJons ¡ • Targeted ¡workloads: ¡ small ¡objects, ¡high ¡rate ¡

  4. Goal: ¡memory-­‑efficient ¡and ¡high-­‑throughput ¡ ¡ • Memory ¡efficient ¡(e.g., ¡> ¡90% ¡space ¡uJlized) ¡ • Fast ¡concurrent ¡reads ¡(scale ¡with ¡# ¡of ¡cores) ¡ • Fast ¡concurrent ¡writes ¡(scale ¡with ¡# ¡of ¡cores) ¡

  5. Preview ¡our ¡results ¡on ¡a ¡quad-­‑core ¡machine ¡ 64-­‑bit ¡key ¡and ¡64-­‑bit ¡value ¡ 120 ¡million ¡objects, ¡ ¡100% ¡ Insert C++11 ¡std::unordered_map ¡ Google ¡dense_hash_map ¡ Intel ¡TBB ¡concurrent_hash_map ¡ cuckoo+ ¡with ¡fine-­‑grianed ¡locking ¡ cuckoo+ ¡with ¡HTM ¡ cuckoo+ ¡uses ¡(less ¡than) ¡half ¡of ¡ 0 ¡ 10 ¡ 20 ¡ 30 ¡ 40 ¡ the ¡memory ¡compared ¡to ¡others ¡ Throughput ¡(million ¡reqs ¡per ¡sec) ¡

  6. Background: ¡separate ¡chaining ¡hash ¡table Chaining ¡items ¡hashed ¡in ¡same ¡bucket ¡ lookup K V K V K V Good: ¡simple ¡ K V Bad: ¡poor ¡cache ¡locality ¡ ¡ ¡ Bad: ¡pointers ¡cost ¡space ¡ K V - e.g., ¡Intel ¡TBB ¡ concurrent_hash_map K V

  7. Background: ¡open ¡addressing ¡hash ¡table Probing ¡alternate ¡locaJons ¡for ¡vacancy ¡ e.g., ¡linear/quadraJc ¡probing, ¡double ¡hashing ¡ Good: ¡cache ¡friendly ¡ lookup ¡ Bad: ¡poor ¡memory ¡efficiency ¡ - performance ¡dramaJcally ¡degrades ¡when ¡the ¡ usage ¡grows ¡beyond ¡70% ¡capacity ¡or ¡so ¡ - e.g., ¡Google ¡ dense_hash_map ¡wastes ¡50% ¡ memory ¡by ¡default. ¡ ¡

  8. Our ¡starJng ¡point ¡ • MulJ-­‑reader ¡single-­‑writer ¡cuckoo ¡hashing ¡[Fan, ¡NSDI’13] ¡ – Open ¡addressing ¡ – Memory ¡efficient ¡ – OpJmized ¡for ¡read-­‑intensive ¡workloads ¡

  9. Cuckoo ¡hashing ¡ Each ¡bucket ¡has ¡ b ¡slots ¡for ¡items ¡( b -­‑way ¡set-­‑associaJve) ¡ Each ¡key ¡is ¡mapped ¡to ¡two ¡random ¡buckets ¡ – stored ¡in ¡one ¡of ¡them ¡ buckets ¡ 0 1 2 hash 1 (x) ¡ 3 4 key ¡x ¡ 5 6 hash 2 (x) ¡ 7 8

  10. Predictable ¡and ¡fast ¡lookup ¡ • Lookup : ¡read ¡2 ¡buckets ¡in ¡parallel ¡ – constant ¡Jme ¡in ¡the ¡worst ¡case ¡ ¡ 0 1 2 3 4 Lookup ¡x ¡ 5 6 7 x ¡ 8

  11. Insert ¡may ¡need ¡“cuckoo ¡move” ¡ • Insert : ¡ 0 1 2 Write ¡to ¡an ¡empty ¡slot ¡in ¡ 3 one ¡of ¡the ¡two ¡buckets ¡ 4 Insert y ¡ 5 6 7 8

  12. Insert ¡may ¡need ¡“cuckoo ¡move” ¡ • Insert : ¡ 0 1 r ¡ e ¡ 2 s ¡ 3 b ¡ Both ¡are ¡full ? ¡ c ¡ f ¡ 4 Insert y ¡ n ¡ 5 a ¡ 6 k ¡ 7 x ¡ 8

  13. Insert ¡may ¡need ¡“cuckoo ¡move” ¡ • Insert : ¡ move ¡keys ¡to ¡alternate ¡buckets ¡ 0 1 r ¡ possible ¡ b ¡ e ¡ 2 locaBons ¡ s ¡ b ¡ 3 possible ¡ a ¡ c ¡ f ¡ 4 locaBons ¡ Insert y ¡ n ¡ 5 a ¡ possible ¡ x ¡ ¡ 6 locaBons ¡ k ¡ 7 x ¡ 8

  14. Insert ¡may ¡need ¡“cuckoo ¡move” ¡ • Insert : ¡move ¡keys ¡to ¡alternate ¡buckets ¡ – find ¡a ¡“cuckoo ¡path” ¡to ¡an ¡empty ¡slot ¡ ¡ – move ¡hole ¡backwards ¡ 0 A ¡technique ¡in ¡[Fan, ¡NSDI’13] ¡ ¡ 1 No ¡reader/writer ¡false ¡misses ¡ 2 3 b ¡ b ¡ 4 Insert y ¡ y ¡ 5 a ¡ a ¡ 6 7 x ¡ x ¡ 8

  15. Review ¡our ¡starJng ¡point ¡[Fan, ¡NSDI’13]: ¡ MulJ-­‑reader ¡single-­‑writer ¡cuckoo ¡hashing ¡ • Benefits ¡ – support ¡concurrent ¡reads ¡ – memory ¡efficient ¡for ¡small ¡objects ¡ over ¡ 90% ¡space ¡uJlized ¡when ¡ set-­‑associaBvity ¡≥ ¡4 ¡ • Limits ¡ 50% ¡Lookup ¡ 100% ¡Lookup ¡ – Inserts ¡are ¡serialized ¡ poor ¡performance ¡for ¡ write-­‑heavy ¡ workloads ¡

  16. Improve ¡write ¡concurrency ¡ • Algorithmic ¡opJmizaJons ¡ - Minimize ¡criJcal ¡secJons ¡ - Exploit ¡data ¡locality ¡ • Explore ¡two ¡concurrency ¡control ¡mechanisms ¡ - Hardware ¡transacJonal ¡memory ¡ - Fine-­‑grained ¡locking ¡

  17. Algorithmic ¡opJmizaJons ¡ • Lock ¡aoer ¡discovering ¡a ¡cuckoo ¡path ¡ – minimize ¡criJcal ¡secJons ¡ • Breadth-­‑first ¡search ¡for ¡an ¡empty ¡slot ¡ – fewer ¡items ¡displaced ¡ – enable ¡prefetching ¡ • Increase ¡set-­‑associaJvity ¡(see ¡paper) ¡ – fewer ¡random ¡memory ¡reads ¡

  18. Previous ¡approach: ¡writer ¡locks ¡the ¡table ¡ during ¡the ¡whole ¡insert ¡process ¡ All ¡ Insert ¡operaBons ¡of ¡other ¡threads ¡are ¡ blocked ¡ lock(); Search f for a a cu cuckoo p path; // ¡at ¡most ¡hundreds ¡of ¡bucket ¡reads ¡ Cuckoo mo move ve a and i insert; // ¡at ¡most ¡hundreds ¡of ¡writes ¡ unlock();

  19. Lock ¡aoer ¡discovering ¡a ¡cuckoo ¡path ¡ MulBple ¡ Insert ¡threads ¡can ¡look ¡for ¡cuckoo ¡paths ¡concurrently ¡ Search for a cuckoo path; // ¡no ¡locking ¡required ¡ lock(); Cuckoo mo move ve a and i insert; unlock(); ¡ ←collision ¡

  20. Lock ¡aoer ¡discovering ¡a ¡cuckoo ¡path ¡ MulBple ¡ Insert ¡threads ¡can ¡look ¡for ¡cuckoo ¡paths ¡concurrently ¡ while(1) { Search for a cuckoo path; // ¡no ¡locking ¡required ¡ lock(); valid; ¡ Cuckoo mo move ve a and i insert w while t the p path i is v if(success) unlock(); break; unlock(); }

  21. Cuckoo ¡hash ¡table ¡ ⟹ ¡undirected ¡cuckoo ¡graph ¡ bucket ¡ ⟶ ¡vertex ¡ ¡ ¡ ¡ ¡ ¡ ¡key ¡ ⟶ ¡edge ¡ 0 x ¡ 0 ¡ 1 ¡ 1 a ¡ x ¡ x ¡ a ¡ a ¡ 3 3 ¡ ⟹ ¡ b ¡ b ¡ y ¡ y ¡ c ¡ b ¡ 6 7 ¡ 6 ¡ y ¡ 7 c ¡ z ¡ z ¡ c ¡ z ¡ 9 9 ¡

  22. Previous ¡approach ¡to ¡search ¡for ¡an ¡empty ¡slot: ¡ ¡ random ¡walk ¡ on ¡the ¡cuckoo ¡graph ¡ Insert ¡ y ¡ a ¡ * ¡ cuckoo ¡path: ¡ ¡ a ➝ e ➝ s ➝ x ➝ k ➝ f ➝ d ➝ t ➝∅ ¡ * ¡ e ¡ 9 ¡writes ¡ * ¡ s ¡ x ¡ * ¡ One ¡ Insert ¡may ¡move ¡at ¡most ¡ hundreds ¡ of ¡items ¡when ¡table ¡occupancy ¡> ¡90% ¡ * ¡ k ¡ * ¡ f ¡ d ¡ * ¡ t ¡ * ¡ * ¡ ∅ ¡

  23. Breadth-­‑first ¡search ¡for ¡an ¡empty ¡slot ¡ Insert ¡ y ¡ Insert ¡ y ¡ a ¡ * ¡ a ¡ * ¡ * ¡ * ¡ * ¡ e ¡ z ¡ * ¡ * ¡ s ¡ * ¡ * ¡ * ¡ u ¡ * ¡ * ¡ * ¡ * ¡ x ¡ * ¡ * ¡ * ¡ * ¡ ∅ ¡ * ¡ k ¡ * ¡ f ¡ d ¡ * ¡ t ¡ * ¡ * ¡ ∅ ¡

  24. Breadth-­‑first ¡search ¡for ¡an ¡empty ¡slot ¡ Insert ¡ y ¡ cuckoo ¡path: ¡ ¡ a ¡ * ¡ a ➝ z ➝ u ➝∅ ¡ ¡ ¡ ¡ ¡ 4 ¡writes ¡ * ¡ * ¡ z ¡ * ¡ Reduced ¡to ¡a ¡ logarithmic ¡factor ¡ * ¡ * ¡ * ¡ u ¡ * ¡ * ¡ * ¡ * ¡ • Same ¡# ¡of ¡reads ¡ ⟶ ¡unlocked ¡ * ¡ * ¡ * ¡ ∅ ¡ • Far ¡fewer ¡writes ¡ ⟶ ¡ locked ¡ Prefetching : ¡ scan ¡ one ¡bucket ¡and ¡ load ¡ next ¡bucket ¡concurrently ¡

  25. Concurrency ¡control ¡ • Fine-­‑grained ¡locking ¡ – spinlock ¡and ¡lock ¡striping ¡ • Hardware ¡transacJonal ¡memory ¡ – Intel ¡TransacJonal ¡SynchronizaJon ¡Extensions ¡(TSX) ¡ – Hardware ¡support ¡for ¡lock ¡elision ¡

  26. Lock ¡elision ¡ Thread ¡1 ¡ Thread ¡2 ¡ Lock: ¡ Free ¡ acquire ¡ acquire ¡ Time ¡ criJcal ¡ secJon ¡ criJcal ¡ secJon ¡ release ¡ release ¡ Hash ¡Table ¡ No ¡serializaFon ¡if ¡no ¡data ¡conflicts ¡

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