Drupal 6 Performance Optimization Using Throttle and Devel Module

Exclusive offer: get 50% off this eBook here
Drupal 6 Performance Tips

Drupal 6 Performance Tips — Save 50%

Learn how to maximize and optimize your Drupal framework using Drupal 6 best practice performance solutions and tools

$23.99    $12.00
by TJ Holowaychuk Trevor James | February 2010 | Content Management Drupal Open Source PHP

In this article by Trevor James and TJ Holowaychuk, authors of Drupal 6 Performance Tips, we're going to learn how to throttle modules and blocks on our site in order to increase performance and reduce server load during high traffic periods. We will use the Throttle module to do this. We'll also discuss the Devel module and how it can be used to generate dummy content, users, and taxonomy categories for our development site. Using Devel to generate test or dummy content provides an easy method of building a test or demo site quickly. To summarize, here's what we'll be doing:

  • Throttling modules and blocks
  • Using the Development module to generate taxonomy, users, and content

Enabling and configuring the Throttle module

Drupal allows you to control when your modules and blocks get enabled and shown to your site visitors. This helps you to prevent bottlenecks in your server's web traffic and to optimize your server load to prevent any congestion that it might experience with its bandwidth and traffic. Throttling blocks and modules becomes increasingly important on larger scale websites where you have many blocks and modules active. You may have a site that contains a large number of blocks, for example, that have been built with the Views module. You can throttle these blocks, so they only get enabled when the site visitor calls a page that is supposed to show that block. The throttle module allows you to configure it, so it automatically gets enabled when the usage of your site goes above a certain threshold. For example, this can be the number of anonymous users visiting your site. When a certain amount of visitors are on your site, you can have Drupal enable throttling.

Using the Throttle module is essential on shared servers where you may not have all of the resources on the server made available to you at any given time or on a server that gives you limited CPU resources and bandwidth. You may not need to use Throttle on higher performance-dedicated servers because they will most likely be providing you with good performance. But on shared servers it does become important to use Throttle.

If you did not enable the Throttle module after we upgraded our site to Drupal 6.13, we need to enable it first. Once enabled, we can then configure the module. Follow these steps:

Under your Core-optional module list, check the box next to Throttle and then save your module configuration.

Drupal 6 Performance Optimization Using Throttle and Devel Module

There are two methods of accessing the Throttle module configuration. You can visit the main Throttle configuration page to set auto throttling settings for your site. Also, you can enable throttling for each module and block on your site. We'll look at both methods now. Note that your modules admin page explains how to access and enable both types of throttling (module and auto) at the top of the page in its introductory help text. You will only see your module throttle checkboxes available if you have enabled the Throttle module first.

Configuring the Throttle module for auto throttling features

Go to Site configuration | Throttle to load your Throttle module settings form or click on the throttle configuration page link through your main modules admin page.

The Throttle configuration page explains what the Throttle module does and gives you a link to more information through the more help link. If you click on that link and have the Advanced Help module active, you will launch a detailed Throttle module help and explanation page.

On this page you can configure three throttle elements that fall under the default Throttle module congestion control feature:

  • Auto-throttle on anonymous users
  • Auto-throttle on authenticated users
  • Auto-throttle probability limiter

Auto-throttle on anonymous users allows you to set a threshold for enabling your congestion control throttle dependent on anonymous user activity. So, for example, you will want to choose a threshold number of anonymous users to enter into this field. When this number of anonymous users is reached, the auto-throttle feature will be enabled. If you want the auto-throttle to be enabled after 250 anonymous users are on your site at the same time, you can type 250 into this field. Set this field to 0 if you do not want to use the auto-throttle feature.

Drupal also tells you here that you can determine how many users are on your site at any given time by enabling the Who's Online block—this will show you all of the anonymous users who are browsing your site and authenticated users who are logged into your site.

The Auto-throttle on authenticated users works using the same method. Add the threshold number of authenticated users that you want logged into your site before the point your throttle gets enabled. We'll set this to 50 authenticated users.

Drupal 6 Performance Optimization Using Throttle and Devel Module

The Auto-throttle probability limiter helps to reduce the overhead of the auto-throttle module. It's a built-in performance check just for this Throttle module. You can set a pe rcentage of page views for your site. For example, if you set the page view percentage to 10%, then the module will only perform extra database queries to update the Throttle module status once for every 10 page views. Drupal tells you that the busier your website, the lower you want to set this value. Leave it set to the default of 10%. Save your auto-throttle configuration.

Throttling your modules

You can also throttle each of your core and contributed modules as long as they have a Throttle checkbox next to their line item on the modules admin page. Load your modules admin page and look for the Throttle checkboxes. This allows you to tell Drupal to throttle a specific module during high traffic periods on your site. This means that when your site reaches a high traffic threshold (based on the auto throttling settings you determined above) your site will temporarily disable the module in question. This will throttle the module until your site returns to a stable status.

You do need to be careful here. You should throttle those modules that are of lesser importance when your site reaches its threshold of user activity. When you throttle, you are temporarily disabling the module, so it will also temporarily disable that module's functionality during high server loads. So, you may want to disable some modules, such as Views, but leave your CCK module enabled so that your users can still see the content that is being filtered into the View. We'll go ahead and throttle the following modules:

  • Administration menu (because this module is only being used by our logged in admins)
  • Chaos tool suite (all submodules here)
  • Comment
  • Contact
  • Database logging
  • Help
  • PHP filter
  • Search
  • Statistics
  • Advanced Help
  • FCKEditor
  • IMCE
  • Lightbox2
  • Poormanscron

You can select more modules to throttle based on your preferences and the usage of your site. Use the above as an example and model to follow. Check the throttle boxes and save your configuration. During the next high server load period, these modules will be disabled temporarily to increase the performance of your site during its high server load period.

Drupal 6 Performance Optimization Using Throttle and Devel Module

Throttling blocks

You can also throttle your blocks. To do this, go to the Blocks admin page here: Administer | Site building | Blocks. You'll notice that there is a new checkbox selection for Throttle. You can choose which blocks to throttle by checking the Throttle checkbox next to each of your enabled blocks. We'll go ahead and throttle all of our blocks except for the User login, as we still want to allow users to login to the site during high traffic periods. The throttle functionality works the same here as it does with modules. These blocks will be temporarily disabled during high site traffic.

Drupal 6 Performance Optimization Using Throttle and Devel Module

Once you check your throttle boxes, save your blocks configuration. The next time you have high site traffic, these blocks will be temporarily disabled.

Drupal 6 Performance Tips Learn how to maximize and optimize your Drupal framework using Drupal 6 best practice performance solutions and tools
Published: February 2010
eBook Price: $23.99
Book Price: $39.99
See more
Select your format and quantity:

Generating test users, categories, and content

Another use of the Devel module is to generate test 'dummy' content, taxonomy categories, and users for your website. This functionality is part of the Devel module and to confirm that you can use this, go to your admin modules list and check to make sure the Devel generate module is enabled.

To generate users, nodes, and taxonomy terms for your site go to the Generate items main page in your site admin. That will launch a page with links to Generate categories, Generate content, and Generate users. As we already have some content on our site (that I originally implemented by using Generate content), we're going to try generating some test users for our website. Follow these steps to generate users:

  1. Click on the Generate users link.
  2. Tell the Devel module how many users to add to the site. The default is 50. We'll add 10 users to our site. Type 10 in the field.
  3. You can also tell Drupal to kill or delete all the other users (if you've already added test users) on your site apart from the super user admin (with User ID 1). This is helpful. You can add some test users and then easily delete them using this module. As we do not have any users on our site besides the super user, we'll leave this box unchecked.
  4. The Devel module will randomly generate a user account history time for each account. You can tell Devel how far back to go in the select box under the How old should user accounts be?. We'll change this to 4 weeks ago.
  5. Click on the Do it! button.
Drupal 6 Performance Optimization Using Throttle and Devel Module

As soon as you click on the Do it! button, the user accounts will be created automatically by the Devel module.

Drupal 6 Performance Optimization Using Throttle and Devel Module

Go to your Users list to see the dummy users that the Devel module created for you. They should all have usernames and be set to active status.

You can also use the Generate items functionality of the Devel module to generate content and categories. Click on each of these links to try out this functionality. When you click on Generate categories, the module will ask you about vocabularies, terms, and the max word length for a term or vocab name. Plug some numbers into these fields and then click on the Do it! button. Let's generate 3 vocabs and 10 terms per vocab. The Max word length of term/vocab names will be set to the default of 12 characters.

Drupal 6 Performance Optimization Using Throttle and Devel Module

Drupal will tell you it created the new vocabs and terms. You can browse to your taxonomy page to view the vocabs and terms.

Drupal 6 Performance Optimization Using Throttle and Devel Module

Once you click on Do it!, browse to your Taxonomy admin list and you should now see the new vocabularies and terms in the site that were generated using the Devel module.

Now that you have added some dummy taxonomy content using the Devel module, you can view your taxonomy vocabs and terms by visiting Content Management | Taxonomy. On this page you'll see the new list of vocabs. If you click on the list terms link, you'll see all of the tags per vocab that were added.

To generate test content go to the Generate content page, fill out the form fields for the types of node content you'd like to create, how many nodes, the maximum number of generated comments, whether you want to add taxonomy terms to each node, and URL aliases per node. This also allows you to delete any previously posted test content that you may have integrated with your site using the Devel module before. Fill out all the fields you need and then click on Do it!. The test content will be generated.

For our next example using the Views module (in the next section on Views caching), I'm going to generate Blog entry test nodes along with the corresponding taxonomy. Generate your own test nodes that you will use in the next section on the Views module. I'm going to go ahead and delete all of my previous test blog content so that I can start afresh with brand new content. I'll generate the default 50 nodes of content. Nodes will be dated as far back as 4 weeks ago. I'll generate a maximum number of 10 comments per blog post. I will add taxonomy terms, upload function ality, and URL aliases to each node. Click on Do it! button.

Drupal 6 Performance Optimization Using Throttle and Devel Module

Drupal will generate the content and you'll see a progress task bar as the content batch is generated. Then, Drupal will show you a confirmation screen showing a list of all the blog entry content that was created.

Drupal 6 Performance Optimization Using Throttle and Devel Module

If you browse to your main content admin list, you will also see all the new blog entries that were created using Devel.

Now that we have test content, categories, and terms generated in our site, we're now ready to build a View using our test content and to start using View caching to increase the performance of our Views. We can also integrate our View with the Panels module and utilize some of the Panels module cache functionality.

Summary

Here, we learned the following performance tips:

  • Used the Throttle module to throttle our blocks and modules.
  • Used the Devel module to generate test content, users, and categories.

If you have read this article you may be interested to view :

Drupal 6 Performance Tips Learn how to maximize and optimize your Drupal framework using Drupal 6 best practice performance solutions and tools
Published: February 2010
eBook Price: $23.99
Book Price: $39.99
See more
Select your format and quantity:

About the Author :


TJ Holowaychuk

TJ Holowaychuk, president of Vision Media is an avid contributor to the Drupal project as well as to other open-source applications. Contributing over 16 Drupal modules, several themes, and having fully designed, developed, and maintained hundreds of Drupal websites he has displayed a wealth of knowledge across different aspects of the industry.

Trevor James

Trevor James is a Drupal developer residing in Middletown, MD, USA. Trevor has been using Drupal intensively since 2007 and designing websites for over 15 years using a combination of HTML, CSS, ColdFusion, PHP, jQuery, and JavaScript.

Trevor's focus is on building Drupal-based web applications and portals for education, non-profit, and medical systems, and small business environments. He is interested in the best methods of integrating web services with Drupal sites, optimizing Drupal sites' performance, and using Drupal content types, Views, Panels, and other contributed modules to develop front-end interfaces that support data intensive websites.

He loves teaching people about Drupal and how to use this excellent open source content management framework. Trevor authored the following Packt books:

Trevor created a 14-hour video tutorial series titled Drupal 7 for Virtual Training Company (VTC) in 2011. The video is available via the VTC website at http://www.vtc.com/products/Drupal-7-Tutorials.htm.

Books From Packt

Drupal 6 Search Engine Optimization
Drupal 6 Search Engine Optimization

Drupal 6 Content Administration
Drupal 6 Content Administration

Drupal 6 Site Builder Solutions
Drupal 6 Site Builder Solutions

Drupal 6 JavaScript and jQuery
Drupal 6 JavaScript and jQuery

Drupal 6 Attachment Views
Drupal 6 Attachment Views

Drupal Multimedia
Drupal Multimedia

Drupal 6 Social Networking
Drupal 6 Social Networking

Drupal E-commerce with Ubercart 2.x
Drupal E-commerce with Ubercart 2.x

Your rating: None Average: 5 (2 votes)

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
H
7
c
a
a
u
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software