counting events reliably with storm riak
play

Counting events reliably with storm & riak Frank Schrder - eBay - PowerPoint PPT Presentation

Counting events reliably with storm & riak Frank Schrder - eBay Classi fi eds Group Amsterdam marktplaats.nl Classi fi eds Admarkt Pay-per-click ads for professional sellers Seller places ad, chooses a budget and cost per


  1. Counting events reliably with storm & riak Frank Schröder - eBay Classi fi eds Group Amsterdam

  2. marktplaats.nl � Classi fi eds

  3. Admarkt � Pay-per-click ads for professional sellers

  4. Seller places ad, 
 chooses a budget and cost per click

  5. We show the ad if it is relevant and budget is available

  6. We show the ad if it is relevant and budget is available

  7. 
 Count clicks & impressions Update budget & ranking

  8. We chose Storm & riak for ranking calculation

  9. Constraints

  10. 135M events/day @ 3.2K/sec peak

  11. accurate real-time scale horizontally handle events out-of-order

  12. accurate real-time scale horizontally handle events out-of-order

  13. Storm Real-time computation framework from Twitter Stream based producer-consumer topologies Nice properties for concurrent 
 processing

  14. Storm You write: a) code that handles a single event 
 in a single threaded context b) con fi guration how the events are produced and fl ow through the topology Then Storm sets up the queues and manages the Java VMs which run your code

  15. Storm Spouts emit tuples (Producer) Bolts consume tuples and can emit them, too (Consumer & Producer) Storm worker = Java VM, 
 Each spout & bolt = 1 thread in a worker Concurrency is con fi gurable 
 and independent of your code

  16. Storm simple topology event source AMQ Storm spout Topology bolt bolt riak riak

  17. Storm complex topology event source LB AMQ AMQ AMQ Storm Topology spout spout spout bolt bolt bolt bolt riak riak riak riak riak

  18. Storm our topology marktplaats.nl AMQ spout avg 1 read avg 2 read riak store store event handler avg 1 avg 2 update update

  19. Storm our topology 3 spouts on 3 servers marktplaats.nl AMQ spout 24 avg1 bolts avg 1 read 24 avg2 bolts avg 2 read riak store store 96 event handler bolts event 7 riak nodes handler avg 1 avg 2 update update

  20. Storm Hardware Setup stormzoo001 stormzoo002 stormzoo003 storm001 storm002 storm003 storm nimbus zoo zoo zoo storm keeper keeper keeper ui storm storm storm ActiveMQ ActiveMQ ActiveMQ worker worker worker stormriak001 stormriak002 stormriak003 stormriak004 stormriak005 stormriak006 stormriak007

  21. Admarkt click-counter 1. Service writes JSON event to fi le and sends it to ActiveMQ. Use same format for logs and Storm. 2. Spouts read JSON events from ActiveMQ and emit them into the topology 3. Bolts process events and update state in riak If something goes wrong we replay events by putting the logs on the queue again

  22. riak for persistence How fast can we write?

  23. Riak Write Performance riak 1.2.1, 5 node cluster 1 read + 1 write/sec peak 25000 20000 ops per second 15000 10000 5000 0 256 1024 4096 8192 16384 Document size in bytes

  24. Conclusion: Document size is important

  25. How can we be accurate? �

  26. How can we be accurate? � Handle each event exactly once

  27. But events can arrive 
 out-of-order… �

  28. But events can arrive 
 out-of-order…

  29. How can we know whether we have seen an event before?

  30. Idea 1: Comparing timestamps event timestamp < last timestamp : 
 we have seen it already Milliseconds are not accurate enough NTP clock skew Replaying and bootstrapping does not work since you can’t tell an old from a replayed event

  31. Idea 2: Sequential Counters event id < last id : we have seen it already How do you build a distributed, reliable, sorted counter? How do you handle service restarts? How can this not be the SPOF of the service? No idea ... Replaying and bootstrapping does not work for the same reasons as before

  32. Idea 3: Keep track of hashes Event hash in current document : 
 we have seen it already Bootstrapping and replaying just works Over-counting cannot happen On failure just replay the logs but ...

  33. How many hashes do we have?

  34. Keeping track of events 135M events per day -> 135M hashes 650K live ads -> 210 events per day/ad But a handful of outliers get 
 40.000 events / hour - each sha1: 40 chars, md5: 32 chars, crc32: 8 chars Collisions?

  35. Hash sizes Remember that document size is important sha1: 210*40 = 8.4KB md5: 210*32 = 6.7KB crc32: 210*8 = 1.7KB

  36. Keeping documents small Usually events are played forward in chronological order Only during replay and failure we need older hashes

  37. Keeping documents small Keep only the current hour in the main document (hot set) Hash must be unique per ad per hour 
 -> Should take care of collisions. Should ... At hh:00 move the older hashes into a separate document Keep documents with older hashes for as long we want to be able to replay (1-2 weeks)

  38. But with riak we don’t have TX …

  39. Moving hashes from one doc to another without TX 1. Write archive doc with older hashes but keep them in the main document 2. Remove older events from the current document and then write it

  40. Replaying events without TX 1. Load older hashes from riak and merge them with main document 2. Write archive doc with older hashes but keep them in the main document 3. Remove older events from the current document and then write it

  41. Serialization Document size is important -> 
 Serialization makes a di ff erence Kryo isn’t as fast as you might think JSON isn’t as bad as you might think Custom beats everything by a wide margin Maintainability is important, too

  42. Serialization Maintainability is important, too You can look at JSON (helpful) Schema evolution via 
 Content-Type headers

  43. Persistence Average ad has average number of hashes Can be written in real-time Outliers have orders of magnitude more hashes More hashes -> bigger docs & more writes -> kills riak (even a handful of them)

  44. Persistence Simple back pressure rule (deferred writes) saves us Small doc -> write immediately Larger doc -> wait up to 5 sec Volatile docs receive lots of events during defer period. Saves writes

  45. 8 months in � Lessons learned

  46. Riak Cleaning up riak is hard since you can’t shouldn’t list buckets or keys. Easier with 2.0 Can’t query riak for “how many docs have value x > 5” without a program. Easier with 2.0 MapRed with gzipped JSON requires Erlang code. JS can’t handle it. Not in 2.0

  47. Riak Deferred writes only help so much. Maybe use constant write rate to make system more predictable. Riak scales nicely with more nodes.

  48. Storm Mostly stable and fast (v0.8.2) Must understand internal queues and their sizing. Otherwise, topology just stops Need external tools for verifying that topology is working correctly

  49. Hashes Nice idea but creates unbounded number of documents. Disks fi ll up and cleaning up is hard. Replay logic kills performance. Replaying is too slow if we need to replay a full day or more.

  50. rethink

  51. We don’t want to know what we have seen � We want to know what we have not seen

  52. This would solve some problems: � doc size constant number of docs constant riak cleanup not necessary

  53. But how do we know what we haven’t seen if we don’t know what is coming?

  54. Idea 2: Sequential Counters event id < last id : we have seen it already How do you build a distributed, reliable, sorted counter? How do you handle service restarts? How can this not be the SPOF of the service? No idea ... Replaying and bootstrapping does not work for the same reasons as before

  55. Idea 2: Sequential Counters event id < last id : we have seen it already How do you build a distributed, reliable, sequential counter? How do you handle service restarts? How can this not be the SPOF of the service? No idea ... Replaying and bootstrapping does not work for the same reasons as before

  56. Why just one counter?

  57. Lets have multiple � �

  58. Lets have multiple e.g. one per service instance

  59. eventId = counterId + counterValue � e.g. � hostA-20131030_152543 : 15

  60. Create unique counter id at service start and 
 start counting from 0 � Increment atomically (AtomicLong) and send counter id + value to storm

  61. 
 Storm keeps track of counter value 
 per counter id 
 Keep gap lists of missed events

  62. Now we can predict what is coming

  63. Questions?

  64. Thank you � frschroeder@ebay.com

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