Skip to content
X
X

Drupal Performance Profiling With Tracelytics

TwitterFacebookLinkedInRedditEmail
 Tracelytics

When AppNeta acquired Tracelytics and their awesome team – we decided to keep their great blog content to document AppNeta’s journey!

Getting a comprehensive view of the causes of poor performance and latency in your Drupal instance can be tricky. AllPlayers.com, a Tracelytics user, has developed a module to integrate Drupal with Tracelytics and make the process of tracking Drupal performance much more straightforward. This module is an excellent example of how one can integrate custom code with the Tracelytics API to provide greater insight into application performance. Let’s explore the functionality of this module, and the source to see how that was implemented to report on full stack application tracing data.

Installation

Installing the Drupal module is as straightforward as downloading it and extracting the .tar.gz or zip. The files should then be installed in your Drupal installation, under sites/all/modules. You can also install the module through the Drupal Admin UI.  You should have also already installed the instrumentation, including instrumentation for your web server and PHP.

Features

Additional Layers

The module provides information on various Drupal-specific layers, each corresponding to a specific Drupal hook. Hooks are PHP functions called by the Drupal framework code at various times during request processing, and are used to generate Tracelytics layer entry and exit events. These events allow Tracelytics to determine how much time each request spent processing in an individual layer. The layers supported today are:

Controller / Action

A controller and action pair is reported for each request by examining currently active Drupal “menu item”, which provides information on the code handling each request. This is particularly important with Drupal since almost all non-static requests are handled by the root index.php file, meaning the URL itself is not useful for categorizing a request.

  • Controller: The ‘page_callback’ function associated with the active Drupal menu item (from the menu_get_item() call).
  • Action: The first argument in the ‘page_arguments’ array associated with the active menu item.

Drupal Performance 1

Request Partitioning

Requests are associated with a specific partition, depending on the type of request. This is crucial for determining where your heaviest requests come from, and when. The support partitions today are:

Drupal Performance 2

  • Admin : Drupal admin user
  • Anonymous : Anonymous user (not logged-in)
  • Authenticated : Logged in user
  • Cron : Periodic / cron execution
  • Drush : Command line shell / script (seewww.drush.org)

Complete Error Logging

Drupal provides a “watchdog” function for logging error/warning/debug messages. More severe messages can be forwarded to Tracelytics and will be tracked as errors.

Drupal Performance 3

Note that it also integrates with Drush, a command line / shell scripting package.

How’s it work?

How does this module integrate with Tracelytics?  If we examine the module code, we’ll see that it makes extensive use of the oboe_log function.  This is a function added to PHP by the Tracelytics PHP instrumentation (“oboe”) module. It allows a code to log events, and is described in more detail in our knowledge base.  The particular snippet logs an “info” event to report the partition based on the currently logged in user:

1
2
3
4
5
6
7
8
9
10
11
12
13
switch ($user->uid) {
  case 1:
    oboe_log('info', array('Partition' => 'Admin'));
    break;
  case 0:
    oboe_log('info', array('Partition' => 'Anonymous'));
    break;
  default:
    oboe_log('info', array('Partition' => 'Authenticated'));
    break;
}

If we browse through the rest of the code (specially the tracelytics_early and tracelytics_late sub-modules), we’ll see that each module registers the same hook. The “early” module executes first and sends the “entry” event, while the “late” module executes last and sends the “exit” event. The order of Drupal module execution is controlled by assigning each module a weight.

Depending on the site configuration, various other modules would also register the same hooks and perform processing. Using the timestamps on the events allows Tracelytics to determine the processing time spent in each layer.  Snippets for the “init” hooks (which are called for all non-cached page requests) are shown below:

tracelytics_early.module:

1
2
3
4
5
function tracelytics_early_init() {
  if (variable_get('tracelytics_layers', FALSE)) {
    oboe_log('drupal_hook_init', 'entry', array());
  }
}

tracelytics_late.module:

The pattern used for other hooks is the same.

1
2
3
4
5
function tracelytics_late_init() {
  if (variable_get('tracelytics_layers', FALSE)) {
    oboe_log('drupal_hook_init', 'exit', array());
  }
}

As you can see, integrating Tracelytics as part of your application is very straightforward! In future blog articles, we’ll explore integrations with other languages and platforms, including Python, Ruby, and Java.

TwitterFacebookLinkedInRedditEmail

Get the most awesome monitoring for your entire site.

Create your free account of TraceView and AppView today!

Create your free account