• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
DjangoCon 2010 Scaling Disqus
 

DjangoCon 2010 Scaling Disqus

on

  • 95,038 views

PDF version of slides: http://dl.dropbox.com/u/116385/DjangoCon%202010%20Scaling%20Disqus.pdf

PDF version of slides: http://dl.dropbox.com/u/116385/DjangoCon%202010%20Scaling%20Disqus.pdf

Statistics

Views

Total Views
95,038
Views on SlideShare
59,112
Embed Views
35,926

Actions

Likes
191
Downloads
1,436
Comments
16

88 Embeds 35,926

http://ontwik.com 17769
http://www.insight-it.ru 8771
http://blog.disqus.com 2446
http://nosql.mypopescu.com 1585
http://ultimatearchitecture.net 1347
http://www.rusdigi.org 1224
http://disqus.com 1163
http://feeds.feedburner.com 276
http://www.nerdyang.com 166
http://www.bretthutley.com 165
http://www.redditmedia.com 148
http://tech.isatya.in 121
http://code.disqus.com 120
http://feber.se 89
http://lanyrd.com 53
http://xss.yandex.net 48
http://www.disqus.com 40
http://bretthutley.com 29
http://ericescarrat.blogspot.fr 24
https://twitter.com 20
http://webcache.googleusercontent.com 20
http://www.salman.ca 19
http://static.slidesharecdn.com 18
http://blog.chedushi.com 16
http://127.0.0.1:8000 16
http://internetcocaine.com 15
http://irr.posterous.com 14
http://devslides.com 14
http://translate.googleusercontent.com 14
http://feedbang.ru 14
http://tumblr.ericharrison.info 13
http://cache.baidu.com 11
https://bretthutley.com 7
http://www.socialmobile.co.uk 7
http://www.techgig.com 6
http://www.xinyuandan.me 6
http://www.ianlewis.org 6
http://www.techgig.com 6
http://hasgeek.tv.local 5
https://trillr.coremedia.com 5
http://ericescarrat.blogspot.com 5
http://www.ninjaas.com 4
http://maxghostwriter.wordpress.com 4
https://www.bretthutley.com 4
http://192.168.6.52 3
http://yanng.sinaapp.com 3
http://www.mefeedia.com 3
http://cache.baiducontent.com 3
http://hn.embed.ly 3
http://safe.tumblr.com 3
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

110 of 16 previous next Post a comment

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…

110 of 16 previous next

Post Comment
Edit your comment
  • Hi. I&apos;m Jason (and I&apos;m David), and we&apos;re from Disqus. <br />
  • Show of hands, How many of you know what DISQUS is? <br />
  • For those of you who are not familiar with us, DISQUS is a comment system <br /> that focuses on connecting communities. We power discussions on such sites as CNN, IGN, and <br /> more recently Engadget and TechCrunch. <br /> <br /> Our company was founded back in 2007 by my co-founder, <br /> Daniel Ha, and I back where we started working out of our dorm room. <br /> Our decision to use Django came down primarily to our dislike for PHP which <br /> we were previously using. Since then, we&apos;ve grown Disqus to over 250+ <br /> million visitors a month. <br />
  • We&apos;ve peaked at over 17,000 requests per second, to Django, and we currently <br /> power comments on nearly half a million websites which accounts for more than <br /> 15 million profiles who have left over 75 million comments. <br /> <br />
  • As you can imagine we have some big challenges when it comes to scaling a large Django application. <br /> For one, it&#x2019;s hard to predict when events happen like last year with Michael Jackson&#x2019;s death, and more recently, the Gulf Oil Spill. <br /> Another challenge we have is the fact that discussions never expire. When you visit that blog post from 2008 we have to be ready to serve those comments immediately. Not only does THAT make caching difficult, but we also have to deal with things such as dynamic paging, realtime commenting, and other personal preferences. This makes it even more important to be able to serve those quickly without relying on the cache. <br />
  • So we also have some interesting infrastructure problems when it comes to scaling Disqus. <br /> We&apos;re not a destination website, so if we go down, it affects other sites as well as ours. <br /> Because of this, it&apos;s difficult for us to schedule maintenance, so we face some interesting <br /> scaling and availbility challenges. <br />
  • As you can see, we have tried to keep the stack pretty thin. This is because, as we&apos;ve learned, <br /> the more services we try to add, the more difficult it is to support. And especially because we have <br /> a small team, this becomes difficult to manage. <br /> So we use DNS load balancing to spread the requests to multiple HAProxy servers which are our software <br /> load balancers. These proxy requests to our backend app servers which run mod_wsgi. We use memcache <br /> for caching, and we have a custom wrapper using syslog for our queue. For our data store, we use PostgreSQL, <br /> and for replication, we use Slony for failover and read slaves. <br /> <br />
  • As I said, we use HAProxy for HTTP load balancing. It&apos;s a high performance <br /> software load balancer with intelligent failure detection. It also <br /> provides you with nice statistics of your requests. We use heartbeat for <br /> high availability and we have it take over the IP address of the down machine. <br /> <br />
  • We have about 100GB of cache. Because of our high availability requirements, 20% <br /> are allocated to high availability and load balancing. <br /> <br />
  • Our web servers are pretty standard. We use mod_wsgi mostly because it just <br /> works. Performance wise, you&apos;re really going to be bottlenecked on the application. <br /> The cool thing we do is that we actually hasve a custom middleware that does <br /> performance monitoring. What this does is ship data from our application about <br /> external calls like database, cache calls, and we collect it and graph <br /> it with Ganglia. <br /> <br />
  • The more interesting aspect of our server architecture is how we have our database <br /> setup. As I mentioned, we use Postgres as our database. Honestly, we used it because <br /> Django recommended it, and my recommendation is that if you&#x2019;re not already an expert in a <br /> database, you&apos;re better off going with Postgres. <br /> We use slony for replication Slony is trigger-based which means that every write <br /> is captured and strored in a log table and those events are replayed to slave databases. <br /> This is nice over otehr methods such as log shipping because it allows us to have <br /> flexible schemas across read lsaves. For example, some of our read slaves have different <br /> indexes. We also use slony for failover for high availbility. <br /> <br />
  • There are a few things we do to keep our database healthy. We keep our indexes in memory, <br /> and when we can&apos;t, we partition our data. We also have application-specific indexes on <br /> our readslaves. Another important thing we&apos;ve done is measure I/O. Any time we&apos;ve seen <br /> high I/O is usually because we&apos;re missing indexes or indexes aren&apos;t fitting in memory. <br /> Lastly, we monitor slow queries. We send logs to pgfouine via syslog which genererates <br /> a nice report showing you which queries are the slowest. <br /> <br />
  • The last thing we&apos;ve found to be really helpful is switching to database connection pool. <br /> Remember, Django doesn&apos;t do this for you. We use pgbouncer for this, and there are a few <br /> easy wins for using it. One is that it limits the maximum connections to the database so <br /> it doesn&apos;t have to handle as many concurrent connections. Secpondly, you save the cost <br /> of opening and tearing down new connections per request. <br /> <br />
  • Moving on to our application, we&#x2019;ve found that most of the struggle is with the database layer. <br /> We&#x2019;ve got a pretty standard layout if you&#x2019;re familiar with forums. Forum has many threads, which has many posts. Posts use an adjacency list model, and also reference Users. With this kind of data model, one of our quickest wins has been the ability to partition data. <br />
  • It&#x2019;s almost entirely done at the application level, which makes it fairly easy to implement. The only thing not handled by the app is replication, and Slony does that for us. We handle partitioning in a couple of ways. <br />
  • The first of which are vertical partitions. This is probably the simplest thing you can implement in your application. Kill off your joins and spread out your applications on multiple databases. Some database engines might make this easier than others, but Slony allows us to easily replicate very specific data. <br />
  • Using this method you&#x2019;ll need to handle joins in your Python application. We do this by performing two separate queries and mapping the foreign keys to the parent objects. For us the easiest way has been to throw them into a dictionary, iterate through the other queryset, and set the foreignkey cache&#x2019;s value to the instance. <br />
  • A few things to keep in mind when doing pythonic joins. They&#x2019;re not going to be as fast in the database. You can&#x2019;t avoid this, but it&#x2019;s not something you should worry about. With this however, you get plain and simple vertical partitions. You also can cache things a lot easier, and more efficiently fetch them using things like get_many and a singular object cache. Overall your&#x2019;e trading performance for scale. <br />
  • Another benefit that comes from vertical partitioning is the ability to designate masters. We do this to alleviate some of the load on our primary application master. So for example, server FOO might be the source for writes on the Users table, while server BAR handles all of our other forum data. Since we&#x2019;re using Django 1.2 we also get routing for free through the new routers. <br />
  • Here&#x2019;s an example of a simple application router. It let&#x2019;s us specify a read-slave based on our app label. So if its users, we go to FOO, if its forums, we go to BAR. You can handle this logic any way you want, pretty simple and powerful. <br />
  • While we use vertical partitioning for most cases, eventually you hit an issue where your data just doesn&#x2019;t scale on a single database. You&#x2019;re probably familiar with the word sharding, well that&#x2019;s what we do with our forum data. We&#x2019;ve set it up so that we can send certain large sites to dedicated machines. This also uses designated masters as we mentioned with the other partitions. <br />
  • We needed this when write and read load combined became so big that it was just hard to keep up on a single set of machines. It also gives the nice added benefit of high availability in many situations. Mostly though, it all goes back to scaling our master databases. <br />
  • So again we&#x2019;re using the router here to handle partitioning of the forums. We can specify that CNN goes to this database alias, which could be any number of machines, and everything else goes to our default cluster. The one caveat we found with this, is sometimes hints aren&#x2019;t present in the router. I believe within the current version of Django they are only available when using a relational lookup, such as a foreign key. All in all it&#x2019;s pretty powerful, and you just need to be aware of it while writing your queries. <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

DjangoCon 2010 Scaling Disqus DjangoCon 2010 Scaling Disqus Presentation Transcript