Source

oscon-2011 / index.html

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Scaling Django Apps</title>

<!-- metadata -->
<meta name="generator" content="S5" />
<meta name="version" content="S5 1.1" />
<meta name="presdate" content="20110728" />
<meta name="author" content="Charles McLaughlin" />
<meta name="company" content="Atlassian" />
<!-- configuration parameters -->
<meta name="defaultView" content="slideshow" />
<meta name="controlVis" content="hidden" />
<!-- style sheet links -->
<link rel="stylesheet" href="ui/default/slides.css" type="text/css" media="projection" id="slideProj" />
<link rel="stylesheet" href="ui/default/outline.css" type="text/css" media="screen" id="outlineStyle" />
<link rel="stylesheet" href="ui/default/print.css" type="text/css" media="print" id="slidePrint" />
<link rel="stylesheet" href="ui/default/opera.css" type="text/css" media="projection" id="operaFix" />
<!-- S5 JS -->
<script src="ui/default/slides.js" type="text/javascript"></script>
</head>
<body>

<div class="layout">
<div id="controls"><!-- DO NOT EDIT --></div>
<div id="currentSlide"><!-- DO NOT EDIT --></div>
<div id="header"></div>
<div id="footer">
 <a href="https://bitbucket.org/cmclaughlin/oscon-2011">
  bitbucket.org/cmclaughlin/oscon-2011
 </a>
</div>
</div>


<div class="presentation">

<div class="slide">
  <h1>Scaling Django Apps</h1>
  <h4>Lessons learned at Bitbucket</h4>
  <br>
  <h4>Charles McLaughlin</h4>
  <h4>@mclaughlinct</h4>
  <h4>July 28, 2011</h4>
  <div class="right-align">
    <img src="images/Bitbucket.png">
  </div>
</div>

<div class="slide">
  <h1>Outline</h1>
  
  <h2>Intro</h2>
  <ul><li>Me, Bitbucket, and Atlassian</li></ul>
  
  <h2>How we do it</h2>
  <ul><li>Backstage at Bitbucket</li></ul>
  
  <h2>Lessons Learned</h2>
  <ul><li>Tips and Tricks</li></ul>
</div>

<div class="slide">
  <h1>Charles McLaughlin</h1>
  <h2>System Administrator</h2>
  <h2>Pythonista</h2>
  <ul><li>Zope, Plone, TurboGears, Django</li></ul>
  <h2>@mclaughlinct</h2>
  <div class="right-align">
    <img src="images/rack.jpg">
  </div>
</div>

<div class="slide">
  <h1>Charles McLaughlin</h1>
  <h2>System Administrator</h2>
  <h2>Pythonista</h2>
  <ul><li><strike>Zope, Plone, TurboGears</strike>, Django</li></ul>
  <h2>@mclaughlinct</h2>
  <div class="right-align">
    <img src="images/rack.jpg">
  </div>
</div>

<div class="slide">
  <h1>About Bitbucket</h1>
  <h2>Free code hosting for Mercurial DVCS</h2>
  <h2>Launched June 2008 by @jespern</h2>
  <h2>Acquired by Atlassian September 2010</h2>
  <h2>In the last year</h2>
  <ul>
    <li>Stablized the infrastructure, migrated off EC2</li>
    <li>Grew the team to 7 developers and 1 sysadmin</li>
    <li>Per-user pricing, lots of UI improvements, new features</li> 
  </ul>
</div>

<div class="slide">
  <h1>About Bitbucket</h1>
  <a href="images/bb-compare-view.png" target="_blank">
    <img src="images/bb-compare-view.png">
  </a>
</div>

<div class="slide">
  <h1>About Atlassian</h1>
  <h2>Founded in 2002</h2>
  <h2>Makers of JIRA and Confluence</h2>
  <h2>Strong SAS presense</h2>
  <h2>Offices in Sydney, San Francisco, and Amsterdam</h2>
  <h2>We're hiring!</h2>
</div>

<div class="slide">
  <h1>Our Scale</h1>
  <h2>150,000+ users</h2>
  <h2>200,000+ repositories</h2>
  <h2>3-4 terabytes of data on disk</h2>
  <h2>1 terabyte transferred per month</h2>
  <h2>1000 requests per second</h2>
  <h2>4.5 million page views per month</h2>
  <h2>1 million visitors per month</h2>
  <a href="images/ga.png" target="_blank">
    <img src="images/ga.png">
  </a>
</div>

<div class="slide">
  <h1>Our Infrastructure - Frontend</h1>
  <h2>Nginx</h2>
  <h2>Django</h2>
  <h2>Gunicorn</h2>
  <h2>Pgbouncer</h2>
  <h2>Memcached</h2>
  <h2>Celeryd</h2>
  <h2>Supervisord</h2>
</div>

<div class="slide">
  <h1>Our Infrastructure - Backend</h1>
  <h2>Stunnel</h2>
  <h2>HAProxy</h2>
  <h2>CloudFront</h2>
  <h2>RabbitMQ</h2>
  <h2>Redis</h2>
  <h2>PostgreSQL 9</h2>
  <h2>NFS</h2>
</div>

<div class="slide">
  <h1>Request Paths</h1>
  <h2>HTTP</h2>
  <img src="images/http-request.png">
 
  <br/>
  <br/>
  <h2>Hg over SSH: HAProxy &rarr; Custom Shell</h2>
</div>

<div class="slide">
  <h1>Our Infrastructure</h1>
  <h2>One size does not fit all, there is no recipe</h2>
  <h2>We've scaled from small to medium</h2>
  <h2>Currently scaling from medium to large</h2>
  <h2>Focusing on high availability</h2>
  <h2>Managed hosting at Contegix</h2>
  <div class="right-align">
    <img src="images/Baby_sleeping.jpg">
  </div>
</div>

<div class="slide">
  <h1>Bitbucket at EC2</h1>
  <a href="images/bb-at-ec2.png" target="_blank">
    <img src="images/bb-at-ec2.png">
  </a>
</div>

<div class="slide">
  <h1>Bitbucket Migrated to Contegix</h1>
  <a href="images/hardware-iteration-1.png" target="_blank">
    <img src="images/hardware-iteration-1.png">
  </a>
</div>

<div class="slide">
  <h1>Postgres9 Replication, Sharded Storage</h1>
  <a href="images/hardware-iteration-2.png" target="_blank">
    <img src="images/hardware-iteration-2.png">
  </a>
</div>

<div class="slide">
  <h1>HAProxy</h1>
  <a href="images/hardware-iteration-3.png" target="_blank">
    <img src="images/hardware-iteration-3.png">
  </a>
</div>

<div class="slide">
  <h1>Storage++</h1>
  <a href="images/hardware-iteration-4.png" target="_blank">
    <img src="images/hardware-iteration-4.png">
  </a>
</div>

<div class="slide">
  <h1>Dev Cycles<h1>
  <h2>One or two week iterations</h2>
  <h2>Local development</h2>
  <h2>Push to staging, pull to production</h2>
  <h2>Staging matches production</h2>
  <ul><li>Cobbler, Koan, KVM, Puppet</li></ul>
  <h2>Rotating release manager/deployer role</h2>
</div>

<div class="slide">
  <h1>Testing</h1>
  <h2>Selenium and Cram for functional tests</h2>
  <ul><li>Nose tests driven by Bamboo</li></ul>
  <h2>status.bitbucket.org</h2>
  <ul><li>Twill tests driven by Django Kong</li></ul>
  <h2>Beta features</h2>
  <ul>
    <li>Designed our own middleware</li>
    <li>Recently switched to Django Waffle</li>
  </ul>
</div>

<div class="slide">
  <h1>Deployment</h1>
  <h2>Puppet right up to our apps</h2>
  <h2>pip and virtualenv</h2>
  <h2>Scheduled deploys, hotfixes anytime</h2>
  <h2>Upgrades are easy (most of the time)</h2>
</div>

<div class="slide">
  <h1>Deployment</h1>
  <h2>Puppet right up to our apps</h2>
  <h2>pip and virtualenv</h2>
  <h2>Scheduled deploys, hotfixes anytime</h2>
  <h2>Upgrades are easy (most of the time)</h2>
  <ul><li><pre>hg pull -u && kill -HUP `cat local/*pid`</pre></li></ul>
</div>

<div class="slide">
  <h1>Monitoring</h1>
  <h2>Good</h2>
  <ul>
    <li>Configured by Puppet
      <ul>
	<li>Nagios</li>
	<li>Munin</li>
	<li>Monit</li>
      </ul>
    </li>
  </ul>
  <br/>
  <ul>
    <li>Pingdom</li>
    <li>Cacti</li>
  </ul>
</div>

<div class="slide">
  <h1>Monitoring</h1>
  <h2>Bad</h2>
  <ul><li>Cron</li></ul>
  <br/>
  <h2>Ugly</h2>
  <ul><li>Hyperic</li></ul>
</div>

<div class="slide">
  <h1>Configuration Management with Puppet</h1>
  <pre>
node production-host {
  include base
  include autofs::production
  include nagios::client
}

node frontend inherits production-host { 
  include bitbucket-skel::production
  include nginx
  include memcached
  include java
}

node "bitbucket01.managed.contegix.com" inherits frontend {
}
  </pre>
</div> 

<div class="slide">
  <h1>Configuration Management with Puppet</h1>
  <pre>
class memcached {
  package { "memcached": ensure => installed }

  service { "memcached":
    ensure  => running, enable  => true, hasstatus => true,
    restart => "/etc/init.d/memcached reload",
    require => Package['memcached']
  }

  file {
    "/etc/sysconfig/memcached":
      owner   => root, group   => root,
      mode    => 0644, ensure  => file,
      source  => "puppet:///memcached/memcached",
      notify  => Service["memcached"]
  }

  munin::munin-node::plugin { "memcached_bytes":
      target => "/usr/share/munin/plugins/memcached_"
  }
}
  </pre>
</div>

<div class="slide">
  <h1>Configuration Management with Puppet</h1>
  <pre>
class nagios {
...
  class client {
  ...
    @@nagios_host { $fqdn:
        ensure             => present,
        alias              => $hostname,
        address            => $ipaddress,
        use                => "generic-host",
        max_check_attempts => 10,
        contact_groups     => "admins",
    }

    @@nagios_service {"check_disk_${hostname}":
      check_command       => "check_nrpe!check_disk",
      use                 => "generic-service",
      host_name           => "$fqdn",
      notification_period => "24x7",
      service_description => "${hostname}_check_disk",
    }
  </pre>
</div>

<div class="slide">
  <h1>Configuration Management with Puppet</h1>
  <h2>This is written to the Nagios config files:</h2>
  <br/>
  <pre>
define host {
  address                        172.16.10.1
  max_check_attempts             10
  contact_groups                 admins
  host_name                      bitbucket01.managed.contegix.com
  use                            generic-host
  alias                          bitbucket01
}

define service {
  check_command                  check_nrpe!check_disk
  host_name                      bitbucket01.managed.contegix.com
  notification_period            24x7
  use                            generic-service
  service_description            bitbucket01_check_disk
}
  </pre>
</div>

<div class="slide">
  <h1>Tuning and Stress Testing</h1>
  <h2>I/O</h2>
  <ul>
    <li>Small XFS volumes</li>
    <li>Mounted with noatime</li>
    <li>Deadline I/O scheduler</li>
    <br/>
    <li><pre>bonnie++ -d /tmp -s 64g -u user:group -f -n 0 -r 7687 -b 2</li>
  </ul>
</div>

<div class="slide">
  <h1>Tuning and Stress Testing</h1>
  <h2>Postgres</h2>
  <ul>
    <li>
      Autocommit and connection pooling [<a href="http://thebuild.com/blog/2009/11/07/django-postgresql-and-autocommit/">1</a>, <a href="https://code.djangoproject.com/ticket/16047">2</a>]</li>
    <li>Slow querry logging, middleware</li>
    <li>
      Common tuning:
      <ul>
        <li>max_connections</li>
        <li>shared_mem</li>
        <li>effective_cache_size</li>
        <li>work_mem</li>
        <li>kernel.shmmax</li>
      </ul>
    </li>
    <br/>
    <li><pre>pgbench -T seconds -j threads -c clients dbname</li>
  </ul>
</div>

<div class="slide">
  <h1>Tuning and Stress Testing</h1>
  <h2>Network</h2>
  <ul>
    <li>Read <a href="http://datatag.web.cern.ch/datatag/howto/tcp.html">How to achieve Gigabit speeds with Linux</a></li>
    <li>Read the HAProxy docs and mailing list</li>
    <li>Beware of c-states and Broadcom NICs on recent kernels [<a href="http://lists.us.dell.com/pipermail/linux-poweredge/2011-June/044901.html">1</a>, <a href="http://support.citrix.com/article/CTX127395">2</a>]</li></ul>
</div>

<div class="slide">
  <h1>Must Have Django Apps</h1>
  <h2>South</h2>
  <h2>Piston</h2>
  <h2>Dogslow</h2>
  <h2>Fabric</h2>
  <h2>Debug Toolbar</h2>
  <h2>Compressor</h2>
  <h2>Waffle</h2>
</div>

<div class="slide">
  <h1>T-SHIRTS!!!</h1>
  <h2>Grab one from me after the presentation</h2>
</div>

<div class="slide">
  <h1>Thanks for coming</h1>
  <br/>
  <br/>
  <h3>Questions or comments?</h2>
</div>

</div>
</body>
</html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.