Scaling on a single machine

I recently had an interesting requesting from someone with a website that was having difficulty scaling. The request was effectively a “help!” we are not sure how to make the beast go faster.

First I asked for some information on the site, what software they were running, what machine they were running on, etc… The information I got back was pretty light, but enough to give some general help. The site is running on a single machine, one dual core CPU, 2 GB of RAM and one 250 GB disc. Not the worlds most robust configuration. In terms of software they were running Apache (dropped in favor of Lighttpd) and are starting to use memcached to cache data coming out of MySQL.

The machine is immutable, can’t be changed or added to, that would have been too easy.

I made the following suggestions:

  • Taking a look at the mix of MySQL queries coming in, if they were getting a lot more reads than insert/update/deletes, then it would make sense to cache as much as possible in memcached. But this is not entirely clear cut. It was not clear whether the tables were myisam tables or innodb tables. If the former were true, then it is likely that the site is slow because of contention issues, if the latter then perhaps memcached is the way to go. Neither was it clear how large the database was, if it was pretty small then it would likely all fit into memory and there would be little difference in speed whether you got the data out of memcached or MySQL. But that also depends on what kind of data you are caching. If the data is heavily preprocessed, then caching that makes sense since you don’t want to process it over and over again.
  • Taking a close look at the schema. I have already covered myisam vs. innodb above, and my rule of thumb here is to default to innodb unless there is a very good reason to use myisam (usually a combination of good reasons). You want to make sure that your tables are normalized and have as few indices as possible, those can really slow down the insert/update/delete process. I also recommended doing away with all foreign key dependencies and moving that up in the code layers.
  • Tunning MySQL appropriately. There is already lots published about that so I won’t cover it here, but a badly tuned engine will really hurt you.
  • Using atop to see whether the machine is CPU or I/O bound.

Since the machine is immutable, there is little else that can be done unfortunately.

Advertisements

One Response to Scaling on a single machine

  1. Pingback: Good reasons to use myisam tables « François Schiettecatte’s Blog

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: