15
Scalable Web Site Antipatterns Justin Leitgeb Stack Builders Inc.

Scalable Web Site Antipatterns Justin Leitgeb Stack Builders Inc

Embed Size (px)

Citation preview

Page 1: Scalable Web Site Antipatterns Justin Leitgeb Stack Builders Inc

Scalable Web Site Antipatterns

Justin LeitgebStack Builders Inc.

Page 2: Scalable Web Site Antipatterns Justin Leitgeb Stack Builders Inc

Overview

• Based on architectures that have caused significant down-time and pain

• Like examples in Nygard's book, but more emphasis on essential rather than accidental properties of system

Page 3: Scalable Web Site Antipatterns Justin Leitgeb Stack Builders Inc

Anti-pattern 1: Monotonically-increasing data set with rapid growth• Having a system that relies on querying all historical data• Requires joins from mega-tables (hundreds of millions of

rows)• Often from automatically aggregated data

Page 4: Scalable Web Site Antipatterns Justin Leitgeb Stack Builders Inc

Detection

• Slow query log• SHOW FULL PROCESSLIST• SHOW ENGINE INNODB STATUS• vmstat

Page 5: Scalable Web Site Antipatterns Justin Leitgeb Stack Builders Inc

vmstat

Page 6: Scalable Web Site Antipatterns Justin Leitgeb Stack Builders Inc

Anti-solutions

• Partitioning• Pre-caching (cron jobs)• Switching to MyISAM• NoSQL?

Page 7: Scalable Web Site Antipatterns Justin Leitgeb Stack Builders Inc

NoSQL

• Out-of-the box solutions with NoSQL (e.g., Mongo) help with data modeling

• Use CAP instead of ACID• May lead to better ability to distribute algorithms• But:

o Haven't had as much effort yet expended on engines as MySQL (INNODB)

o Often use the same algorithms (e.g., Btree indexes)o Can require more dev time (e.g., Cassandra and good

implementation of distributed algorithms)

Page 8: Scalable Web Site Antipatterns Justin Leitgeb Stack Builders Inc

Stop the bleeding

• Cut off long queries• Turn off site sections• Fail whale

Page 9: Scalable Web Site Antipatterns Justin Leitgeb Stack Builders Inc

Band-aids

• Obvious - adding app servers, memcached, bigger DB server

• Adding app servers puts more pressure on DB server• HTTP Caching (varnish)• MySQL tuning (look for things like FILESORT)• Read slaves

Page 10: Scalable Web Site Antipatterns Justin Leitgeb Stack Builders Inc

Solutions

• Hard-limit data volume - look for cases where data decreases in value with timeo Add features related to scale

• Distributed algorithms and data stores• Data warehousing

Page 11: Scalable Web Site Antipatterns Justin Leitgeb Stack Builders Inc

Anti-pattern 2: Allowing "risky" writes to block HTTP responses • Symptoms:

o Slow requestso Servers hitting MaxClients and 500 error

Page 12: Scalable Web Site Antipatterns Justin Leitgeb Stack Builders Inc

Possible Causes

• Possible causes: database backed analytics tracking• Session management• Any SQL DML (UPDATE, DELETE)

Page 13: Scalable Web Site Antipatterns Justin Leitgeb Stack Builders Inc

Risk increases with:

• The number of requests invoking the write operation • Traffic• Concurrent background operations• The algorithmic complexity of the write• Slow AWS I/O on EBS

Page 14: Scalable Web Site Antipatterns Justin Leitgeb Stack Builders Inc

Solutions

• Asynchronize!o Write to a queue

• Write to memcached or other non-ACID storeo Later bring to data warehouse for advanced analytics

Page 15: Scalable Web Site Antipatterns Justin Leitgeb Stack Builders Inc

More info

1. Nygard, Michael T. Release It!: Design and Deploy Production-ready Software. Raleigh, NC: Pragmatic, 2007.

2. Fowler, Martin. Patterns of Enterprise Application Architecture. Boston: Addison-Wesley, 2003.

3. Kimball, Ralph. The Data Warehouse Toolkit: Practical Techniques for Building Dimensional Data Warehouses: John Wiley & Sons 2010.

4. Schwartz, Baron. High Performance MySQL: O'Reilly, 2008