performance

26 Apr

XHProf in 30 Seconds: How to get started profiling PHP

in performance, php, programming, xhprof

The task was simple: I wanted to run xhprof (the Facebook-developed PHP profiler) to get some quick-and-dirty metrics on a PHP script. While xhprof is actually really easy to install and use, I had to read a surprising amount of material in order to run a simple install and write three lines of code.

To spare others the agony of cruising old Facebook docs in the Internet Archive, here's a 30 second guide to installing and using xhprof.

25 Apr

Misplaced Optimization: A story of PHP performance woes

in drupal, performance, php, programming

I recently began working on some PHP code for resolving HTML5 entities into their Unicode codepoints. According to the code, it had been optimized for performance. The code was moderately complex, and the authors appeared to have gone through great pains to build a specialized lookup algorithm. But when I took a closer look, I doubted. I decided to compare the "optimized" version with what I would call a naive version -- the simplest solution to the problem.

Here I show the two solutions, and then benchmark them for both memory and speed.

26 Oct

PHP and curl_multi_exec

in curl, performance, php, programming

This post explain how to get data off of a curl_multi handle. Some time back I posted this snippet of code inside of a larger sample of code:

<?php
  $active = NULL;
  do {
    $ret = curl_multi_exec($multi, $active);
  } while ($ret == CURLM_CALL_MULTI_PERFORM);
 
  while ($active && $ret == CURLM_OK) {
    if (curl_multi_select($multi) != -1) {
      do {
         $mrc = curl_multi_exec($multi, $active);
      } while ($mrc == CURLM_CALL_MULTI_PERFORM);
    }
  }
?>

I didn't really document or explain it. And so it seems that this code snippet has caused some confusion. Let me explain what it does.

01 Aug

Chaos Monkey and the Coffee Shop: A Quality Emergency Plan

in drupal, performance, programming

In the last 24 hours, I have had three glimpses into emergency plans. First, my local coffee shop -- the true source of my productivity -- experienced a water main break. Second, a site I manage experienced a server failure. Third, I came across Netflix's recently open sourced Chaos Monkey tool.

18 Jun

Connection Sharing with CURL in PHP: How to re-use HTTP connections to knock 70% off REST network time.

in curl, drupal, hpcloud, performance, php, programming

The PHP CURL library is the most robust library for working with HTTP (and other protocols) from within PHP. As a maintainer of the HPCloud-PHP library, which makes extensive use of REST services, I've been tinkering around with ways of speeding up REST interactions.

What I've found is a way to cut off nearly 70% of the processing time for a typical usage scenario. For example, our unit tests used to take four minutes to run, and we're now down to just over a minute, while our Drupal module's network time has been cut by over 75%.

This article explains how we accomplished this with a surprisingly simple (and counter-intuitive) modification.

31 Aug

The Best Tool for Web Page Speed Evaluation

in memcached, nginx, performance

It seems that, for me, this is the year of website performance optimization. From working with nginx and a crazy memcached setup to recently deploying a handful of Varnish servers, I have been deeply entrenched in the world of website page speed optimizations.
Side-by-sideSide-by-side

22 Mar

A 53,900% speedup: Nginx, Drupal, and Memcache bring concurrency up and page load time way down

in drupal, memcached, nginx, performance

With a clever hack utilizing Memcache, Nginx, and Drupal, we have been able to speed the delivery time of many of our major pages by 53,900% (from 8,100 msec to 15 msec, according to siege and AB benchmarks). Additional, we went from being able to handle 27 concurrent requests to being able to handle 3,334 concurrent requests (a 12,248% increase).

While we performed a long series of performance optimizations, this article is focused primarily on how we managed to serve data directly from Memcached, via Nginx, without invoking PHP at all.
Nginx, Memcached, and DrupalNginx, Memcached, and Drupal

Read on for the full explanation of how we achieved this huge speedup.

01 Dec

Streamlining Iterators in QueryPath 3.x

in performance, php, php 5.3, querypath

Work has officially begun on QueryPath 3.x. The upcoming release is focused on implementing and supporting many of the new features introduced in PHP 5.3, including enhanced SPL support, namespaces, closures, and phar archives.

In an earlier article, I examined the performance of various iteration strategies in QueryPath. After taking a hard look at the patterns I observed there, I revisited QueryPath's QueryPathIterator class to see if I could make a sizable performance improvement.

26 Nov

Iteration Techniques and Performance in QueryPath

in performance, php, php 5.3, querypath

QueryPath provides multiple methods of iterating. This article demonstrates the performance impact of various looping types. In this article, we are going to look at four different ways of iterating through the items wrapped by a QueryPath object:

  • Using QueryPath's iterator
  • Looping through DOMNode objects
  • Using each() and a callback
  • Using each() and an anonymous function

This last item is specific to PHP 5.3 and later, and offers intriguing possibilities when paired with closures.

Finally, at the end of the article, I will show some representative performance numbers.