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

Polyglot Persistence at Parse

Polyglot Persistence at Parse

from data day 2014 in Austin, Texas

Charity Majors

January 12, 2014
Tweet

More Decks by Charity Majors

Other Decks in Technology

Transcript

  1. •Ops-oriented case study •Overview of architecture diagram and products •Deeper

    dive into each backend • some challenges and success stories • scaling tips and performance tuning details Case study on Parse Sunday, January 12, 14
  2. What is Parse? Platform for mobile developers •iOS, Android, WinRT

    •API and native SDKs •Scales automatically to handle traffic •Analytics, cloud code, file storage, push notifications, hosting Sunday, January 12, 14
  3. • Developers • Apps • API usage • Nodes and

    compute resources • Connected devices Parse is growing fast Sunday, January 12, 14
  4. Developers 06 ‘11 07 ‘11 08 ‘11 09 ‘11 10

    ‘11 11 ‘11 12 ‘11 01 ’12 02 ’12 03 ’12 04 ’12 05 ’12 06 ’12 07 ’12 08 ’12 09 ’12 10 ’12 11 ’12 12 ’12 01 ’13 02 ’13 03 ’13 04 ’13 05 ’13 06 ’13 07 ’13 08 ’13 09 ’13 10 ’13 11 ’13 12 ’13 When PARSE was acquired Sunday, January 12, 14
  5. Infrastructure design choices • Chef • Route53 • Use real

    hostnames • Distribute evenly across 3 AZs • Fail over automatically • Single source of truth • All inbound traffic through ELBs • Autoscaling groups Sunday, January 12, 14
  6. API path • ELB • nginx • haproxy • Ruby

    app servers (unicorns) • Go api servers (go rewrite from the ground up) • Go logging servers to FB endpoint Sunday, January 12, 14
  7. Hosting • ELB • Elastic IPs for apex domain redirect

    service • Go service that wraps cloud code and S3 Sunday, January 12, 14
  8. Cloud code • Server-side javascript in v8 virtual machine •

    Third-party modules for partners (Stripe, Twilio, etc) • Restrictive security groups • Scrub IPs with squid Sunday, January 12, 14
  9. Push • Resque on redis • Billions of pushes per

    month • 700/sec steady state • Spikes to 10k/sec (15x burst) • PPNS holds sockets open to all android devices • PDNS to serve android phone-home IPs (only place we run our own DNS) Sunday, January 12, 14
  10. MongoDB summary • 20 replica sets, ~70 nodes, 2-6 TB

    per rs • Running 2.4.6 - 2.4.8 (current) • Over 1M collections • Over 200k schemas • Used for structured mobile app data, real-time query analysis, backend billing & analytics, central routing • Fully instrumented provisioning with chef Sunday, January 12, 14
  11. MongoDB hardware • m2.4xlarge • 68 gigs of RAM, 26

    virtual cpus • 3 nodes + 2 arbiters • one node set to priority = 0 and hidden = true for snapshots • PIOPS (striped RAID, 4000-16000 PIOPS/vol) • totally saved our bacon. EBS was a killer. • i2.4xlarge • 122 gb RAM, 53 virtual cpus • 4x800 gb SSD striped Sunday, January 12, 14
  12. MongoDB tuning • blockdev --setra • warm up your working

    set before an election • monitor page faults • continuous compaction on snapshot nodes • perf goes off a cliff after an initial sync (for us -- not most people!) Sunday, January 12, 14
  13. MongoDB sharding • Implemented our own app-level sharding • Mongo

    sharding works ok for small # of large collections • We use a separate mongo replset for routing apps -> shards • Apps are local to a replset • lets us do things like balance performance • Transfer unused apps to graveyard Sunday, January 12, 14
  14. MongoDB indexing • Every query should have an index •

    Auto-indexing of the keys based on entropy of values • Analyze real query traffic to generate intelligent compound indexes Sunday, January 12, 14
  15. MongoDB noc • Latency, counts and errors for each API

    query • Aggregated by api key and shard Sunday, January 12, 14
  16. MongoDB logs & analytics • Logs uploaded to S3 hourly

    from nodes • pulled down by ruby workers, aggregated by app id & time • events written back to mongo Sunday, January 12, 14
  17. Hive analytics pipeline • parallel pipeline to replace our mongo

    logs • Each log event tagged with unique id • Custom service written in go • Interfaces with Facebook’s Scribe endpoint • Scribe dumps data to daily Hive table partitions • Run aggregations on hive • Load per-app aggregated data into mongo on AWS • 4k msg/sec steady, 10k msg/sec peak Sunday, January 12, 14
  18. MongoDB closing thoughts • Mongo is still a young database

    • Flexible and powerful • Elections work • MongoDB is not magic. You still have to understand your data store! Sunday, January 12, 14
  19. Cassandra • Powers the client side Parse analytics • Super

    fast writes and increments • We use lots of counters • 90k writes/sec • 25k reads/sec • Hashed by app id Sunday, January 12, 14
  20. Cassandra hardware • 24 node ring • c3.4xlarges • 55

    cpu units • ephemeral storage • 2x160gb ssd • never i/o bound, always cpu bound Sunday, January 12, 14
  21. Cassandra + Priam • Initial token assignments • Incremental backups

    to S3 • Uses Auto Scaling Groups • SimpleDB for tracking tokens, instance identities • Non-trivial to set up but WORTH IT Sunday, January 12, 14
  22. Cassandra perf stuff • increase sstable size -- default was

    5mb! • log GC pauses • compaction strategy • restart every couple weeks to reduce heap contention • we are still on 1.1 so a lot of our issues are solved later Sunday, January 12, 14
  23. Redis stats & tuning • Sets of 3 m2.4xlarge instances

    • ephemeral storage • Currently ~20k ops/sec, down from max ~40k ops/sec • Always disable flush to disk on primary • Use RPS to distribute eth0 software interrupts across multiple cores • watch cat /proc/interrupts, cat /proc/softirqs Sunday, January 12, 14
  24. Redis • Limited applications but rock solid at what it

    does • Single threaded (all that shiny wasted cpu) • Problematic automatic failover schemes • but twemproxy looks rad Sunday, January 12, 14
  25. MySQL • Trivially tiny and we would love to get

    rid of it • ... but rails • Considered RDS • No chained replication • Visibility is challenging • Even tiny periodic blips impact the API • ... but AZ failover would be sooo nice Sunday, January 12, 14
  26. Zookeeper • Service registration and discovery • Distributed lock coordination

    • Single consistent source of truth about your infrastructure • (there are up and coming RAFT alternatives but none of them are production ready) Sunday, January 12, 14