Drupal 6 Performance Tips — Save 50%
Learn how to maximize and optimize your Drupal framework using Drupal 6 best practice performance solutions and tools
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.
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.
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)
- Database logging
- PHP filter
- Advanced Help
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.
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.
Once you check your throttle boxes, save your blocks configuration. The next time you have high site traffic, these blocks will be temporarily disabled.
eBook Price: $23.99
Book Price: $39.99
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:
- Click on the Generate users link.
- 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.
- 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.
- 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.
- Click on the Do it! button.
As soon as you click on the Do it! button, the user accounts will be created automatically by the 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 will tell you it created the new vocabs and terms. You can browse to your taxonomy page to view the vocabs and terms.
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 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.
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.
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 :
eBook Price: $23.99
Book Price: $39.99
About the Author :
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'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:
- Drupal 7 Business Solutions (http://www.packtpub.com/drupal-7- business-solutions-to-build-powerful-web-site/book), published in early 2012
- Drupal Web Services (http://www.packtpub.com/drupal-web-services/book), published in November 2010
- Drupal 6 Performance Tips (https://www.packtpub.com/drupal-6-performance-tips-to-maximize-and-optim...), published in February 2010
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.