horizontally (keep adding cache and load balancers/proxies). all you have to do is keep making more profits and keep buying more hardware into infinity. sure, one day you'll have to build a nuclear reactor and tap a dam to provide all the power and cooling for the datacenter space, but it's easier than a redesign.
How do you scale your web application?
31–40 of 41 posts
Re: How do you scale your web application?
#32Second step is usually cache - local, in-application cache. It's pretty much auto-pilot now, writing a cache function.
Cache helps, but not as much as you'd think. When it gets serious though it's still useful because its shape makes it easy to go to step three: mix the cache with a bit of refactoring. This can mean simply pre-fetching: there is a huge difference from doing 20 "select * from order_items where id=xxx" and just one "select * from order_items where order=yyy". And with the cache in place it usually means only a few extra lines of code. (This example is for building reports, not for displaying orders. I'm not that of an idiot to get each order_item separately).
If things get heavy refactoring can go as far as breaking the abstractions in place. Last month I squeezed an extra second by sending to the browser a big table in batches, while I was computing it. Not something I want to do every day, but occasionally it's fun.
This is also the step when I usually realize I made a stupid mistake along the way which caused the delay.
The only problem I met which was mostly impervious to this was a design decision. In one app I decided (as I usually do) to compute stuff like balances and debts on-the-fly. It usually (well, always) is a good idea, because any intermediary result is a source for bugs. But this particular app grew rather unexpectedly large, with the result that computing an overall balance takes 3-10 seconds. It's not a huge problem for the client, but my pride suffers. I'm still looking into this one - I think some refactoring may make it ok.
Re: How do you scale your web application?
#33After the easy stuff: move your database to its own server, add a load balancer in front of additional web servers, implement memcached, start splicing your database to multiple servers, continue to add web servers, serve your static files from a cdn
I only point this out, as load balancers and additional servers can be expensive.
Re: How do you scale your web application?
#34Earlier quoted context omitted.
What would be the first thing you do? All that adds up...
first thing to do, IMO: Add more RAM
Re: How do you scale your web application?
#35Earlier quoted context omitted.
Adding lots of application servers isn't the hard part, generally (from what I've read... I have to admit I've never had to do more than the 'easy stuff'). The database is. How's Mnesia scale up? Where does it work well, and where does it not work so well?
If you find it difficult to scale up databases, try looking at CouchDB instead http://couchdb.apache.org/index.html
I also tried to read about in the first chapter of the upcoming CouchDB book, but it only contains vague generalizations like "Erlang makes you scalable automatically" or "it is built on the same technology (HTTP) as the web which is proved to be scalable".
I am still not convinced.
Re: How do you scale your web application?
#36Scaling on the cheap: 1. Host all your static files (images,css,js) on Google App Engine 2. Avoid hitting your database. Cache everything possible.
Re: How do you scale your web application?
#37Design it well in the first place! Here's something I recently wrote about speed and web apps: http://bens.me.uk/2009/fast-web-applications
Designing it well doesn't mean that you won't have to scale eventually (unless you stop growing.)
Re: How do you scale your web application?
#38What are the effective strategies to use when the bottleneck is disk I/O? We have memcached to cache data that is frequently accessed. However our usage pattern is such that repeated access of data in a short span of time is rare.
At the very least, make sure each system bus (i.e. PCIe/PCI-X for commodity x86) slot is populated with a host adapter (ideally a hardware RAID controller) which can saturate that slot.
For each host adapter, ensure that each port has enough disks behind it that, even with worst-case contention (not fully-random, unless you've somehow managed to magically induce 512-byte transfers), they can saturate the the upstream system bus, even after RAID processing is done by the adapter.
After that, upgrade to a server with more slots and repeat the saturation.
Repeat once more for the largest single server available, while starting the project to implement (perhaps write from scratch) a distributed database.
I have yet to see anyone make even a concerted effort on the first step, instead skipping to the second part of the last step, probably because that appears, at first glance, to require only a Small Matter Of Programming.
Re: How do you scale your web application?
#39Ah caching, the cause of and solution to all of life's problems.
There are only two hard things in Computer Science: cache invalidation and naming things. -Phil Karlton
Re: How do you scale your web application?
#40Do the easy stuff first: 1. Enable caching & get the HTTP-headers with e-tags and stuff. 2. Get DB schema with proper indexes & tune database settings. 3. Buy better hardware where there are bottlenecks 4. Fix the software ;)
I disagree with "buy better hardware" (unless you are thinking of just additional RAM or getting a SSD instead of a regualar hardware) imho you need to design with horizontal scaling in mind
Given 8 x 3Ghz core / 32GB / 5TB machines for cheap you're packing as much power as 15+ servers of a few years ago. Even quite large web sites can be run off a few beefy (but cheap!) servers. This means money saved on network infrastructure, power, space, management, etc.
Probably 80% of the Alexa top 1000 could each be run off less than 20 modern beefy machines.