Keeping an eye on memory usage
So, while working on a project recently we were faced with the reality that Drupal was using too much memory for our server to handle. The culprit was an AJAX refresh script that helped us to keep the page content up-to-date without refreshing. We had spent a good amount of time tuning the amount of processing and bandwidth used by the module, but the Drupal full bootstrap was just killing us with a 10 second refresh rate.
The solution we settled on was to not bootstrap Drupal if it wasn't necessary. We implemented a preliminary PHP script that the AJAX request was first passed to. This script opened a MySQL connection and ran a single query to check for updated content. If there was none, the script returned empty JSON. If content was found, then Drupal was fully bootstrapped to load the content and return a full JSON structure with the new content.
The results shouldn't be surprising, but still blew me away. Using the PHP function memory_get_peak_usage() we were able to see just how much memory the scripts were using at the point where the JSON was returned. When new content was found and Drupal bootstrapped PHP used 16961212 bytes (16.18 MB) of memory, but when there was no new content, the intermediate script only used 86968 bytes (84.9 KB) of memory.
Read more for the code...
Putting together a Drupal testing server
So, I've been playing around Drupal 7 and wanted to put together a local server for testing. The only crux is that the only "server" I had to work with was a cruddy old eMachines desktop with 640MB of ram running Fedora Core 5. Well, long story short, I had neither the time, patience nor the bandwidth to download Fedora 9. Unfortunately the Fedora 5 distro only comes with php 5.1 yet Drupal 7 requires PHP 5.2. Yum showed no available updates, so I had to scour pbone.net for a bunch of FC5 RPMs to get it up and running. Here's a quick Breakdown:
First, locate and remove the old PHP installation and extras:
$ rpm -qa | grep phpthe -qa option shows which RPMs have been installed and | grep php filters out anything not containing "php"
$ rpm -e php-cli php-common php php-gd php-pdo php-pearthe above, run as root, will remove any of the listed RPM packages installed
Second, download the new RPM files from a repository like pbone.net - I grabbed the following RPMs for Fedora 5:
- php-cli
- pcre
- php-common
- php-5.2
- php-mbstring (required for D7)
- php-gd
- t1lib (libt1.so.5 is required by gd)
- php-pdo
- php-pear
- php-mysql
- sqllite (required for php-mysql)
Third, install the above RPM files
$ rpm -Uvh pcre-6.6-1.fc5....$ rpm -ivh php-common-5.2....and repeat for the additional packages. Note, use the -Uvh to upgrade packages that are installed, and -ivh to install the ones you do not currently have installed.
Fourth, set up CVS on the server and check out the latest from HEAD:
$ yum install cvs$ cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal checkout -d var/www/html drupalFifth, and final step, was to tune apache a bit, set up the database and install Drupal 7! Now I've got a server that I can quickly keep up to date with Drupal HEAD and compare patches against the CVS.

