Fuller Web Development

  BLOG | CONTACT | CLIENTS

Memory Optimizations for Mochilla.com

I just spent the last two days optimizing the Python backend for the Mochilla.com website. We are running the website on a 256MB VPS at Slicehost. They have been getting a larger number of hits the last week because of their new Timeless video they are releasing, and several people have been embedding the videos on their websites. All this was causing the server to lockup and need to be restarted a couple of times a day. So the initial outdated code that was running the site before has been trimmed down and there has been a dramatic increase in speed on the website and a reduction of the amount of memory it requires. I’ve done away with using classes for various objects, and the data is stored in a dictionary instead. I’m also using straight SQL to get data from the database rather than using an expression language or an ORM that would just add another level of complexity. I’ve also consolidated various tables that really should be one as all the information is being queried at once anyways. It’s a small but large move, that has made the website much lighter weight and easier to manage.

Browsing is now faster and the server is more stable with higher amounts of traffic, take a look: Mochilla.com

The database now has this schema:


mysql> show tables;
+--------------------+
| Tables_in_mochilla |
+--------------------+
| documents          |
| templates          |
| uri                |
+--------------------+
3 rows in set (0.06 sec)

mysql> describe documents;
+------------+---------------+------+-----+---------+----------------+
| Field      | Type          | Null | Key | Default | Extra          |
+------------+---------------+------+-----+---------+----------------+
| oid        | int(11)       | NO   | PRI | NULL    | auto_increment |
| modified   | datetime      | YES  |     | NULL    |                |
| created    | datetime      | YES  |     | NULL    |                |
| parent_oid | int(11)       | YES  |     | NULL    |                |
| html       | varchar(1000) | YES  |     | NULL    |                |
| image      | varchar(1000) | YES  |     | NULL    |                |
| video      | varchar(1000) | YES  |     | NULL    |                |
| audio      | varchar(1000) | YES  |     | NULL    |                |
| uri        | varchar(100)  | YES  |     | NULL    |                |
| name       | varchar(100)  | YES  |     | NULL    |                |
| weight     | int(11)       | YES  |     | NULL    |                |
+------------+---------------+------+-----+---------+----------------+
11 rows in set (0.46 sec)

mysql> describe templates;
+----------+---------------+------+-----+---------+----------------+
| Field    | Type          | Null | Key | Default | Extra          |
+----------+---------------+------+-----+---------+----------------+
| vid      | int(11)       | NO   | PRI | NULL    | auto_increment |
| name     | varchar(100)  | YES  |     | NULL    |                |
| source   | varchar(255)  | YES  |     | NULL    |                |
| parent   | int(11)       | YES  |     | NULL    |                |
| children | varchar(1000) | YES  |     | NULL    |                |
+----------+---------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

mysql> describe uri;
+----------+---------------+------+-----+---------+-------+
| Field    | Type          | Null | Key | Default | Extra |
+----------+---------------+------+-----+---------+-------+
| location | varchar(1000) | NO   | PRI | NULL    |       |
| oid      | int(11)       | YES  |     | NULL    |       |
| vid      | int(11)       | YES  | MUL | NULL    |       |
| children | varchar(1000) | YES  |     | NULL    |       |
+----------+---------------+------+-----+---------+-------+
4 rows in set (0.00 sec