Tobias McNulty
DjangoCon 2013
Slides: http://cakt.us/djangocon-scaling
Started at UChicago; 5Essentials team designs and conducts surveys to assess:
Schools with strong scores on at least 3 of these are 10 times more likely to improve math and reading.
5Essentials Survey Admin Module (SAM)
Many auxiliary views (about 80)
Model.objects.bulk_create() helps
Install it:
pip install django-debug-toolbar
And add it to your local development settings file:
INTERNAL_IPS = ('127.0.0.1',) MIDDLEWARE_CLASSES.append('debug_toolbar.middleware.DebugToolbarMiddleware') INSTALLED_APPS.append('debug_toolbar')
Common patterns include:
You need an easy way to generate load. JMeter's a good tool for that; here there are a few tips:
On Debian or Ubuntu:
apt-get install pgfouine
Edit postgresql.conf:
log_min_duration_statement = 0 # log all statements with durations log_line_prefix = '%t [%p]: [%l-1] ' # pgfouine-specific log prefix lc_messages = 'C' # character encoding pgfouine can understand
After generating some load, run pgfouine on your log file:
pgfouine -file /var/log/postgresql/postgresql.log -logtype stderr > report.html
We have the data, let's cache strategically. Options:
Install it:
pip install django-cache-machine
Activate it:
class MyModel(models.Model): # ... cached = caching.base.CachingManager()
Use it:
MyModel.cached.filter(...)
Some things to be aware of:
# settings.py CACHE_EMPTY_QUERYSETS = True
# settings.py CACHE_COUNT_TIMEOUT = 300
Install it:
pip install django-balancer
Configure it:
DATABASE_ROUTERS = ['balancer.routers.PinningWMSRouter'] MIDDLEWARE_CLASSES.append('balancer.middleware.PinningCookieMiddleware') DATABASE_POOL = { 'default': 1, 'db-slave': 1, } MASTER_DATABASE = 'default' MASTER_PINNING_KEY = 'master_db_pinned' MASTER_PINNING_SECONDS = 5
@uses_forced_read_router def my_view(request): # ... return render(...)
... is simple and painless if you:
COMPRESS_OFFLINE_MANIFEST = 'manifest-{{ current_changeset }}.json'
So far we have:
Optimizing postgresql.conf for heavy INSERT load:
(Note: this is now even better in PostgreSQL 9.2: http://cakt.us/pg-group-commit)
Table of Contents | t |
---|---|
Exposé | ESC |
Full screen slides | e |
Presenter View | p |
Source Files | s |
Slide Numbers | n |
Toggle screen blanking | b |
Show/hide slide context | c |
Notes | 2 |
Help | h |