startups to scale

19
Scaling an early stage startup by Mark Maunder <[email protected]>

Upload: guest73ced5

Post on 11-May-2015

873 views

Category:

Economy & Finance


0 download

DESCRIPTION

Tips for scalable architectures

TRANSCRIPT

Page 1: Startups to Scale

Scaling an early stage startupby Mark Maunder <[email protected]>

Page 2: Startups to Scale

Why does performance and scaling quickly matter?

• Slow performance could cost you 20% of your revenue according to Google.

• Any reduction in hosting costs goes directly to your bottom line as profit or can accelerate growth.

• In a viral business, slow performance can damage your viral growth.

Page 3: Startups to Scale

My first missteps

• Misconfiguration. Web server and DB configured to grab too much RAM.

• As traffic builds, the server swaps and slows down drastically.

• Easy to fix – just a quick config change on web server and/or DB.

Page 4: Startups to Scale

Traffic at this stage

• 2 Widgets per second

• 10 HTTP requests per second.

• 1 Widget = 1 Pageview

• We serve as many pages as our users do, combined.

Page 5: Startups to Scale

Keepalive – Good for clients, bad for servers.

• As http requests increased to 10 per second, I ran out of server threads to handle connections.

• Keepalive was on and Keepalive Timeout was set to 300.

• Turned Keepalive off.

Page 6: Startups to Scale

Traffic at this stage

• 4 Widgets per second

• 20 HTTP requests per second

Page 7: Startups to Scale

Cache as much DB data as possible• I used Perl’s Cache::FileCache to cache either DB

data or rendered HTML on disk.• MemCacheD, developed for LiveJournal, caches

across servers. • YMMV – How dynamic is your data?

Page 8: Startups to Scale

MySQL not fast enough

• High number of writes & deletes on a large single table caused severe slowness.

• Writes blow away the query cache.• MySQL doesn’t support a large number of small tables (over

10,000).• MySQL is memory hungry if you want to cache large

indexes. • I maxed out at about 200 concurrent read/write queries per

second with over 1 million records (and that’s not large enough).

Page 9: Startups to Scale

Perl’s Tie::File to the early rescue

• Tie::File is a very simple flat-file API.

• Lots of files/tables.• Faster – 500 to 1000

concurrent read/writes per second.

• Prepending requires reading and rewriting the whole file.

Page 10: Startups to Scale

BerkeleyDB is very very fast!

• I’m also experimenting with BerkeleyDB for some small intensive tasks.

• Data From Oracle who owns BDB: Just over 90,000 transactional writes per second.

• Over 1 Million non-transactional writes per second in memory.

• Oracle’s machine: Linux on an AMD Athlon™ 64 processor 3200+ at 1GHz system with 1GB of RAM. 7200RPM Drive with 8MB cache RAM.

Source: http://www.oracle.com/technology/products/berkeley-db/pdf/berkeley-db-perf.pdf

Page 11: Startups to Scale

Traffic at this stage• 7 Widgets per second

• 35 HTTP requests per second

Page 12: Startups to Scale

Created a separate image and CSS server

• Enabled Keepalive on the Image server to be nice to clients.

• Static content requires very little memory per thread/process.

• Kept Keepalive off on the App server to reduce memory.

• Added benefit of higher browser concurrency with 2 hostnames.

Source: http://www.die.net/musings/page_load_time/

Page 13: Startups to Scale

Now using Home Grown Fixed Length Records

• A lot like ISAM or MyISAM• Fixed length records mean we

seek directly to the data. No more file slurping.

• Sequential records mean sequential reads which are fast.

• Still using file level locking.• Benchmarked at 20,000+

concurrent reads/writes/deletes.

Page 14: Startups to Scale

Traffic at this stage

• 12 Widgets per second

• 50 to 60 HTTP requests per second

• Load average spiking to 12 or more about 3 times per day for unknown reason.

Page 15: Startups to Scale

Blocking Content Thieves

• Content thieves were aggressively crawling our site on pages that are CPU intensive.

• Robots.txt is irrelevant. • Reverse DNS lookup with

‘dig –x’• Firewall the &^%$@’s with

‘iptables’

Page 16: Startups to Scale

Moved to httpd.prefork• Httpd.worker consumes more memory than

prefork because worker doesn’t share memory.• Tuning the number of Perl interpreters vs number

of threads didn’t improve things.• Prefork with no keepalive on the app server uses

less RAM and works well – for Mod_Perl.

Page 17: Startups to Scale

The amazing Linux Filesystem Cache

• Linux uses spare memory to cache files on disk.

• Lots of spare memory == Much faster I/O.

• Prefork freed lots of memory. 1.3 Gigs out of 2 Gigs is used as cache.

• I’ve noticed a roughly 20% performance increase since using it.

Page 18: Startups to Scale

Tools• httperf for benchmarking your server• Websitepulse.com for perf monitoring.

Page 19: Startups to Scale

Summary

• Make content as static as possible.• Cache as much of your dynamic

content as possible.• Separate serving app requests and

serving static content.• Don’t underestimate the speed of

lightweight file access API’s .• Only serve real users and search

engines you care about.