Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Counting At Scale with Scalding

Counting At Scale with Scalding

Slides from a talk I gave at Coursera on using approximate data structures for scaling operations on very large datasets

Avatar for Ian O'Connell

Ian O'Connell

October 21, 2014

Other Decks in Technology

Transcript

  1. Who am I? What I do? • Who: • Ian

    O’Connell @0x138 • Engineer @ Twitter • Build data tools and products • e.g. Algebird/Scalding/Summingbird/ Storehaus/Bijection…
  2. This talk 1. Sample real world problems & solutions A.

    Hyper Log Log B. Count Min Sketch 2. How Algebraic concepts helps us get more from these 3. Scalding / using the above 4. But I want it exact! 5. Other applications?
  3. Problems • How many unique users viewed each tweet? •

    How many of those are really twitter junkies and viewed both tweets?
  4. Naïve approach • Set’s and Set intersection • Set[Long] of

    User Id’s per tweet • 10^8 tweets/day • 10^8 users
  5. HyperLogLog • For cardinalities > 10^9 • Error ~ 2%

    => 1.5kb of space • 10^8 Tweets per day, @ Max(1.5kb/tweet) • 150GB/day uncompressed
  6. Problem • How many views of the tweet the day

    it was posted? between 5 and 7? • How many views in Spokane of the tweet? • How many of those users were using an iPhone 6? • Key: (TweetId, Geo, Device, Minute)
  7. Challenge • 1 Month of storage: • Tweets: 10^9/month •

    Geo’s: 10^5 • Devices: 10^2 • Time: 10^4 minutely buckets ~10^20 keys/month
  8. Count Min Sketch Sketchyness • Upper bound: x • Lower

    bound: max(0, x - ((e/w) * N)) • Probability: 1 - 1/ed
  9. And back to the problem • Can make a 160GB

    cms or more per month • Take 10 hash functions • Width is ~10^9 • Upper bound looks like: 10^-9 * N • At N = 1 trillion ==> lower bound: -3000. • With probability: 99.99%
  10. Making these accessible • Don’t want any special code in

    Scalding/ Summingbird for ease of use • We use them outside of hadoop/data processing • Generic testing ability
  11. Monoids • Have a well defined plus under associativity •

    (a + b) + c == a + (b + c) • Not needed: (a + b) + c == (b + a) + c (commutativity) • Have a zero, such that a + 0 == a
  12. Scalding • API for running a sequence of Map reduce

    jobs • Based on the Scala collections API • Type safe, easily testable • Stable/robust
  13. Scalding • Map-like functions • map, flatMap, filter • Grouping

    functions • sum, mapGroup, toList, sumByKey, reduce, sortedTake, head, min • Join functions • join, leftJoin, rightJoin, sketchJoin
  14. Scalding • def sumByKey[K, V](implicit ev: T <:< (K, V),

    ord: Ordering[K], plus: Semigroup[V])
  15. But I want it exact • Having exact results in

    big data is a myth • Everything has error rates in it • Reporting from devices • Logging pipelines • Corrupted Lzo/Serialization
  16. Other applications of CMS? • CMS’s are great • Heavy

    Hitters, associative! • Sketch Map, not… but top N. Often what you want even if its less accurate — (related headlines on twitter) • Storehaus cache filter with a CMS to efficiently only cache frequent keys