Improving Running Components at Twitter
Improving Running Components at Twitter
Components
Evan Weaver
Twitter, Inc.
QCon London, 2009
Many tools:
Rails
C
Scala
Java
MySQL
Rails front-end:
rendering
cache composition
db querying
Middleware:
Memcached
Varnish (cache)
Kestrel (MQ)
comet server
Milestone 1: Cache policy
Optimization plan:
1. stop working
2. share the work
3. work faster
Old
Everything runs from
memory in Web 2.0.
First policy change:
vector cache
Generational keys
Low hit rate (40%)
Visibility was lacking.
Peep tool
Dumps a live memcached
heap
Cache only was living
five hours
mysql> select round(round(log10(3576669 - last_read_time) * 5, 0) / 5, 1) as log, round(avg(3576669 - last_read_time), -2) as freshness, count(*),
rpad('', count(*) / 2000, '*') as bar from entries group by log order by log desc;
+------+-----------+----------+------------------------------------------------------------------------------------------------------------------+
| log | freshness | count(*) | bar |
+------+-----------+----------+------------------------------------------------------------------------------------------------------------------+
| NULL | 0 | 13400 | ******* |
| 6.6 | 3328300 | 940 | |
| 6.2 | 1623200 | 1 | |
| 5.2 | 126200 | 1 | |
| 5.0 | 81100 | 343 | |
| 4.8 | 64800 | 3200 | ** |
| 4.6 | 34800 | 18064 | ********* |
| 4.4 | 24200 | 96739 | ************************************************ |
| 4.2 | 15700 | 212865 | ********************************************************************************************************** |
| 4.0 | 10200 | 224703 | **************************************************************************************************************** |
| 3.8 | 6500 | 158067 | ******************************************************************************* |
| 3.6 | 4100 | 108034 | ****************************************************** |
| 3.4 | 2600 | 82000 | ***************************************** |
| 3.2 | 1600 | 65637 | ********************************* |
| 3.0 | 1000 | 49267 | ************************* |
| 2.8 | 600 | 34398 | ***************** |
| 2.6 | 400 | 24322 | ************ |
| 2.4 | 300 | 19865 | ********** |
| 2.2 | 200 | 14810 | ******* |
| 2.0 | 100 | 10108 | ***** |
| 1.8 | 100 | 8002 | **** |
| 1.6 | 0 | 6479 | *** |
| 1.4 | 0 | 4014 | ** |
| 1.2 | 0 | 2297 | * |
| 1.0 | 0 | 1733 | * |
| 0.8 | 0 | 649 | |
| 0.6 | 0 | 710 | |
| 0.4 | 0 | 672 | |
| 0.0 | 0 | 319 | |
+------+-----------+----------+------------------------------------------------------------------------------------------------------------------+
What does a timeline miss
mean?
Container union
Ruby is “optimization-
resistant”
Mainly due to the GC
If the consumers could not
keep pace, the MQ would fill
up and crash
JConsole
Yourkit
Poor tooling for the Ruby
GC:
Railsbench w/patches
BleakHouse w/patches
Valgrind/Memcheck
MBARI 1.8.6 patches
Our Railsbench GC tunings
Small rewrite:
No new features added
Well-defined interface
Already went over the wire
Deployed to 1 MQ host
Fixed regressions
Compatibility among
memcached clients is critical
Twitter is big, and runs hot
JVM tools:
- Kestrel http://github.com/robey/kestrel/
- Smile http://github.com/robey/smile/
- Jconsole http://openjdk.java.net/tools/svc/jconsole/
- Yourkit http://www.yourkit.com/
Ruby tools:
- BleakHouse http://github.com/fauna/bleak_house/
- Railsbench Ruby patches http://github.com/skaes/railsbench/
- MBARI Ruby patches http://github.com/brentr/matzruby/tree/v1_8_6_287-mbari
General:
- Danga stack http://www.danga.com/words/2005_oscon/oscon-2005.pdf
- Seymour Cray quote http://books.google.com/books?client=safari&id=qM4Yzf8K9hwC&dq=rapid
+development&q=cray&pgis=1
- Last.fm downtime http://blog.last.fm/2008/04/18/possible-lastfm-downtime
twitter.com/evan
blog.evanweaver.com
cloudbur.st