- PeterMoulding.com
- Author
- Trainer
- Speaker
- Business Coach
- How to write a How To book
- PHP Courses
- Speaking
- Web Architect
- Australia
- Books
- Authors
- Akkana Peck
- Alex Berenson
- Andrew Nugent
- Ben Sanders
- Brock Clarke
- Chris Simms
- David Mercer
- Dianna Mullet
- Don Winslow
- Dori Smith
- Harlan Coben
- Jack McDevitt
- James Wines
- Jerry Yudelson
- John Grisham
- Kevin Mullet
- L. E. Modesitt Jr.
- Laurell K. Hamilton
- Marshall Karp
- Martina Cole
- Michael Marshall Smith
- Michel Roux Jr
- Nadia Sawalha
- Philip Pullman
- Raymond Khoury
- Richard North Patterson
- Robert Masello
- Sally Roth
- Sarah Langan
- Stella Rimington
- Stephen King
- Stephen Leather
- T.C. Boyle
- Tom Negrino
- Tony Hillerman
- Urban Waite
- Val McDermid
- Valerio Massimo Manfredi
- Beginning GIMP
- Beginning Visual C++
- Culturalism
- Fiction
- A Drink Before The War
- A Talent for War
- Bag of Bones
- Blood and Ice
- Burn
- Dark Lady
- Dead Line
- Eclipse
- Empress of Eternity
- Exley
- Flipping Out
- Just One Look
- Nightfall
- Pet Sematary
- Savage Moon
- Skinwalkers
- Starvation Lake
- The Fallen
- The Gardens of the Dead
- The Jump
- The Last Templar
- The Mermaids Singing
- The Midnight Mayor
- The Secret Soldier
- The Summons
- The Terror of Living
- The Testament
- The Tower
- Under the Dome
- Virus
- AJAX and PHP
- Aging with Grace
- Food books
- Green Architecture
- Life Is So Good
- SQL: The Complete Reference
- The Backyard Bird Lover's Ultimate How-to Guide
- The Garden Gurus
- Authors
- Sustainability
- -18 hours left to decide the future of Australia
- Campbells vegetable stock or Massel vegetable stock?
- Carbon Sequestration
- Carbon tax for Australia is a fraud
- Copenhagen will fail
- Cost of living in Australia
- Dick Smith jumps on the population bandwagon
- Dry Run: Preventing the Next Urban Water Crisis
- Energy Saving Lights
- Garlic
- How many people can live in Australia?
- Julia Gillard offers 9.9 billion dollars bribe to Rob Oakeshott
- Laundry detergent
- Petrol or Diesel?
- Reflective foil batts kill
- RoHS
- Sea level to rise 3mm due to climate change
- Solar power
- Spring again in Sydney
- Sustainable fuels
- The CRUD Tax is back
- The people who make building regulations do not own houses
- Water efficiency
- Which insulation is safer, foil or wool?
- Will Australia reduce greenhouse gas emissions?
- Technology
- Android or Blackberry or iPhone or a flip phone?
- Apple versus Google 2011
- Cameras
- Cars
- Colour
- Burgundy
- Colour Blindness
- Colour Names
- Dulux colours
- Pantone colours
- Safe Colours
- Seculine ProDisk Mini colour balance card
- What Causes Colour Blindness?
- Hardware
- Batteries for the Digital Age
- Cables
- Cases
- Computer reliability
- Computrace
- Disks
- Astone ISO Gear 481E
- Best SSD for your notebook computer
- Disk block size
- Hitachi disk HDS722020ALA330
- LaCie USB 2.0 250 GB mobile hard drive design by F.A. Porsche
- SMART disk
- Samsung 2 TB HD204UI quiet low power disk for mass storage
- Seagate and Samsung merge disk business
- Select the right disk for your RAID array
- USB disk speed
- Western Digital WD20EARX 2 GB SATA 3 disk
- How long should computer hardware last?
- Keyboards
- Mainframe
- Memory cards
- Monitors
- Netbooks, notebooks, tablets, and xPads
- Network Attached Storage
- OLED Displays
- PC's are a thing of the past
- Printers
- Quiet
- Samsung Galaxy S
- Speed
- Television
- Tools
- USB
- Worst computer movies
- Xserve is dead. What next?
- Your backup will not work
- iPad or Acer Aspire One?
- IQ
- Its obsolete, throw it out!
- LG Intello Washing Machine
- Lack of a challenge
- NBN spends another $12 billion of our tax money on nothing
- Networks
- 802.11n wireless networking
- D-Link DIR-655 wireless router
- D-Link DWA-160 Xtreme N dual band USB adapter
- D-Link DWA-556 Xtreme N PCI Express desktop adapter
- MIMO
- National Broadband Network
- Netgear wireless modem router DGND3300 with 300 Mbps 802.11n
- Refrigerator kills wireless broadband
- Small Wireless Network
- TP-LINK TL-SG10005D 5 port gigabit switch
- TP-Link TL-WR1043N wireless N gigabit router
- Telstra Pre-paid Mobile Wi-Fi
- Where are the router plus proxy server combinations?
- Open Source documentation
- Software
- 7-zip
- Accounting
- Asterisk
- Audacity
- Backup software
- Bloat only in Windows
- CAD
- CDex
- Disk imaging software for copying and backup
- Exact Audio Copy
- Filezilla
- Firefox
- Java
- LibreOffice or OpenOffice?
- Linux
- 1 in 5 servers will ship with Linux
- Android phones outsell iPhone
- Another Move to Linux
- CentOS 5.5 installation on SSD and RAID 5
- Debian
- Debian 5.0.5 AMD64 installation
- Fedora
- Fedora or Ubuntu?
- Gnome or KDE?
- K9copy
- Linux 2.6.38
- Linux Gnome login settings lost
- Linux Mint
- Linux RAID, a rant
- Linux Speed
- Linux Time
- Linux reliability as demonstrated by Ubuntu 10.10
- Linux reliability as demonstrated by Ubuntu 11.4
- Linux still a struggle in 2011
- Linux workstation disk RAID 1
- Linux, NT, Windows, and SETI
- Linux, three years of progress
- London Stock Exchange switches to Linux
- Mandrake Linux 9.2
- The partition is misaligned by 48128 bytes - warning from Linux RAID
- Ubuntu
- How to fix the scroll bars in Ubuntu 11.4 Gnome
- Kubuntu 10.10 alternate installation on desktop with RAID 1
- POWbuntu
- Ubuntu 10.10 after 6 months use
- Ubuntu 10.10 alternate installation
- Ubuntu 10.10 desktop RAID 1
- Ubuntu 10.10 desktop RAID 5
- Ubuntu 10.10 desktop install on a netbook
- Ubuntu 10.10 desktop installation
- Ubuntu 10.10 netbook install on a netbook
- Ubuntu 10.10 server AMD64
- Ubuntu 10.10 upgrade to version 11.4 beta 2
- Ubuntu 10.4
- Ubuntu 11.10
- Ubuntu 11.10 first upgrade
- Ubuntu 11.4 after one month use
- Ubuntu One
- Ubuntu by Microsoft?
- Ubuntu desktop upgrade 10.4 to 10.10 failed because I did not check the media
- Ubuntu strikes again
- Yes, use Linux but not that distribution!
- Nero
- OpenOffice
- OpenOffice is now Apache Office
- Project management
- Scribus
- Software for Windows and Linux
- Time
- Todo applications
- Tomboy notes
- Top text editors
- Version control
- VideoLAN VLC media player
- Visio
- Webmin
- Webmin installation on CentOS for Web development
- Webmin installation on Ubuntu
- What is the most popular open source software today?
- Windows
- Another Windows person goes Linux
- BAD_POOL_CALLER
- Cygwin
- Microsoft Malicious Software Removal Tool cannot find a common virus
- One of the developers of Windows XP is criminally insane
- There are unused icons on your desktop
- W32time
- Which Windows version?
- Windows 7 Home Premium
- Windows XP Stop 0x0000007B during installation
- Windows XP is a disaster
- Windows processes
- XML
- Zip, bzip, gzip, or 7zip?
- configFree
- Technology Succession Planning
- VoIP
- Web Sites
- Drupal
- Do Drupal themes have to use the GPL?
- Drupal 7
- A better search facility for Drupal
- Drupal - performance or flexibility
- Drupal 7 new features
- Drupal 7 ships on January 5
- Drupal 7.4 hits PeterMoulding.com
- Drupal function sequence
- The evolution of a module
- Undefined index: headers in DefaultMailSystem->mail() (line 54 of /modules/system/system.mail.inc).
- Undefined index: to in DefaultMailSystem->mail() (line 83 of /modules/system/system.mail.inc).
- implode(): Invalid arguments passed in DefaultMailSystem->format() (line 23 of /modules/system/system.mail.inc).
- Drupal Code Load Cut
- Drupal How To
- Drupal Modules
- Backup and Migrate
- Browscap
- CKEditor with Drupal WYSIWYG
- Captcha
- Colorbox
- Content Construction Kit
- Content type
- Devel module for Drupal
- Drupal Rules as an automation language
- Drupal Spam add-on module
- IMCE
- IMCE Wysiwyg bridge
- ImageAPI
- Lightbox2
- Node Gallery Access
- Node_Gallery
- Path
- Path redirect
- Pathauto
- Pet
- Search
- Service links
- Session Variable
- Taxonomy
- Token
- Transliteration
- Trigger
- Variable module
- Other modules
- Drupal Training
- Drupal access controls need a major rewrite
- Drupal coding tricks
- Drupal performance
- Drupal themes for the future
- Drupal.org colours
- Import existing data into Drupal
- Multiple Web sites made easy using Drupal multisite and the right start
- drupal_lookup_path()
- Adobe PDF
- Apache
- Apache Mahout
- Audi.com
- Bleet
- CSS Strikes Again
- CSS or xCSS
- Can you believe Facebook or email?
- Content Management Systems
- Databases
- Facebook scam
- Font
- Fonts
- HTML
- Install Apache, MySQL, and PHP 5 in Ubuntu 11.4 using the Ubuntu Software Centre
- Language Codes
- Marketing
- Memcache
- Nginx
- Oscars
- PHP
- SPDY
- Search software
- Techoni.com.au
- Theme themes
- U.S. Patent No. 6,985,875
- Virtual Private Server
- Visible Improvement
- Web 4.0
- Web browser usage
- Web browsers
- Web site development
- Bluefish
- Eclipse and PHP
- Getting a Git client, a story of ancient technology and pain
- HTTrack
- MVC
- Netbeans
- Nvu
- PHP
- PHP or ..., CakePHP/Symfony/ZF versus ...
- Programming
- Superfish
- Web browser emulators for testing your Web site
- Web development frameworks
- Web site books
- Web site development on your own computer
- Webmin or phpMyAdmin or cPanel for creating databases?
- aiki framework
- jQuery
- Views development - Learn Fields first
- Views development - Learn Actions and Rules
- jQuery .each()
- jQuery .has()
- jQuery .is()
- jQuery and Firefox Firebug
- jQuery children
- jQuery for people not using Drupal - Installation and getting started
- jQuery hover
- jQuery hover de-duplication example
- jQuery or CSS?
- jQuery performance
- jQuery tests
- Web site hosting
- Westpac Web site still broken after two years and ten months
- Wordpress wins another CMS survey
- Drupal
Drupal Code Load Cut
Submitted by Peter on Tue, 2007-03-13 01:00
Drupal:
How do you dramatically cut the load of code going into Drupal? Use the code load cut described here.
All content management systems (CMSs) are based on many chucks of code both large and small, as it is the only way of providing the wide variety of functions you need in CMSs. Drupal, like other well designed CMSs, lets you switch on only the chunks you need which reduces the code load.
There are lots of options in Drupal and many are used for Web sites from the largest to the smallest. The resultant code load is based on the options used, not the size of the Web site. If you have a relatively small site and the page load times are slow, it is probably your Web site host not allocating enough resources and you can take steps to reduce your resource usage, including cutting the code load.
PHP Accelerators
Drupal is based on PHP code because PHP is optimised for the Web and PHP can be further optimised by using products commonly known as PHP accelerators. One PHP accelerator is named PHP Accelerator while another is named the Zend Optimiser. The accelerators use a technique used for many years on many languages, which is to compile the code into memory then save a copy of the compiled code before using the code. Subsequent uses of the code can just load the compiled version, not the original.
Accelerators save space by throwing away comments and compressing the remaining code. When you choose to use Drupal modules containing lots of comments, you know the comments will not slow you down.
Administration Overhead
The remaining accelerated code can still be a big load because of all the strings of text and complex code, particularly in the administration area. The strange thing is, Drupal (and most other CMSs), load all the code all the time, even administration code that may be used only for a few minutes per day by one person. In some Drupal modules, the administration code is 80 percent or more of the total module code, which means the module loads five times too much code for every single Web page.
A really nice trick would be to move the administration code out to a separate chunk that is loaded only when needed.
Module Load Code
Modules are managed by code named module.inc in the Drupal includes directory, and loaded by function drupal_load() in bootstrap.inc, also in the includes directory. If we could modify drupal_load() to automatically load administration code then we could separate out the administration code.
*.admin.inc
We need a standard name for the file containing the administration code, one that fits in with current Drupal file names. Drupal modules are named *.module and included files are named *.inc with the *.inc files protected from public view. A module named Example is in a directory named example and contains a code file named example.module. If module Example has an optional include file then the include file is named example.inc. We could simply add a file named *.admin.inc, example.admin.inc in our example module, and look for the *.admin.inc file when we are in the administration area.
drupal_load()
drupal_load() loads the *.module files. We could then add code to load *.admin.inc when needed. Look in includes/bootstrap.inc for drupal_load() and familiarise yourself with the code.
I do not recommend you make any of the changes mentioned here as the changes may destroy your Web site and produce all sorts of related problems that I cannot predict for your site. I am only telling you what I do on my site so that someone can use this idea to improve your site.
I can perform the change on your site for a fee and most other Web developers are cheaper. This minor change to drupal_load() takes very little time and the real effort is improving individual modules.
Look in drupal_load() for the following code. $type contains 'module' and $name contains the module name, such as 'example'. drupal_get_filename() returns the file name for the module named example and the include_once statement brings the module file, example.module, into Drupal.
$filename = drupal_get_filename($type, $name);
if ($filename) {
include_once "./$filename";
$files[$type][$name] = TRUE;
return TRUE;
}
I expanded the code in several ways. First I changed the format of the code to a more modern readable form. The next change expands the include_once to correctly pick up the file no matter how your directory is structured. Finally I added the code to check for admin files.
The if() statement, in the following code, checks for a type of 'module' so we can check for admin code only when loading a module and the second check, of the filename, is there because the first check produced an occasional stray load of the admin code that I did not bother tracking down. $location is extracted from the request path to see if the first part of the path contains 'admin'. We then check if the admin file exists and load the file if it exists.
if($filename)
{
include_once drupal_document_root() . $filename;
if($type == 'module' and substr($filename, -7) == '.module')
{
$location = reset(explode('/', $_GET['q']));
$admin = 'admin';
$admin_file = drupal_document_root() . substr($filename, 0, -7)
. '.' . $admin . '.inc';
if($location == $admin and file_exists($admin_file))
{
include_once $admin_file;
}
}
$files[$type][$name] = TRUE;
return TRUE;
}
Test the change thoroughly before using the change on an important site. If you contribute to Drupal code then you might be able to talk the Drupal developers into making this small change a standard feature.
Change a Module
Analyse the Impact
Some modules have no admin code which means you do not need an admin.inc file. Some modules have such small admin code sections that it is not worth the work to change a module. Focus on the modules with the greatest gains.
For modules with small gains, change them only when you are performing other work on the modules. You will have to maintain the changes until the technique is picked up by Drupal and there is no point chaning a module for a very small gain if you are not otherwise changing a module. Once you make any change to a module, the extra work for the admin split is trivial.
Use the statistics module for your practice run. I divided the 23 KB statistics.module into a 12 KB statistics.module, including some additional documentation, and a 16 KB statistics.admin.inc, including some additional documentation.
Create the Admin File
You can create the statistics.admin.inc file using your favourite editor or just copy another .inc file, rename the copy, and delete all the contents within the opening and closing PHP elements. Note that Drupal follows the weird practice of not using a closing PHP element but PHP accepts the files anyway. I edit PHP files using an editor that understands PHP, highlights some common typing errors, and I add the closing element.
Add some documentation to describe your change. Include the date. You may need to copy the change across several releases of Drupal until Drupal adopts a similar approach.
You can now cut functions out of statistics.module and place them in statistics.admin.inc based on where the functions are used. Function statistics_access_log() is only used from path admin/logs/access which means the function will only be used when statistics.admin.inc is loaded.
The functions in my statistics.admin.inc include statistics_recent_hits(), statistics_top_pages(), statistics_top_visitors(), statistics_get_host_by_address(), statistics_top_referrers(), and statistics_access_logging_settings().
Split the Menu Function
You could split the statistics_menu() function into two parts, one in statistics.module and one in statistics.admin.inc, but the split technique is a little more complicated than just moving functions. I do not recommend this part of the split until you have completely tested the previous changes.
statistics_menu() starts by setting $items to an array. You add code to test for a location of admin and include the function named statistics_menu_admin. You will add statistics_menu_admin() to statistics.admin.inc and the function will return an array populated with menu entries.
$items = array();
if(reset(explode('/', $_REQUEST['q'])) == 'admin')
{
$items = statistics_menu_admin($may_cache);
}
statistics_menu_admin() accepts the $may_cache parameter and sets up menu entries in the same way as statistics_menu(). look at all the menu items with paths starting as 'admin/'. They can all go across to statistics_menu_admin().
I know this part of the explanation is light on detail but you should only tackle this part of the code split when experienced enough to understand the Drupal menu system.
Conclusion
If every Drupal module was analysed for the admin code cut and the biggest gains implemented, Drupal would create less load on our Web servers, particularly the smaller sites on virtual hosting and VPSs where memory can be tight. The code cut is easy to implement and a great long term gain for Drupal. The splitting of large modules into two smaller code chunks also makes module development easier and more organised.









Comments
I've noticed that the main
I've noticed that the main drupal.org site is slow, particularly when searching. Does anyone know if this has to do with scalability issues, and if so, are there other large drupal community websites that have/don't have this problem?
drupal.org trails behind
drupal.org trails behind the work performed on other sites. The Drupal developers are focused on Drupal 7. drupal.org is going through a usability redesign then will probably convert to Drupal 7 then will be performance tuned. Big sites often switch their search from Drupal to Apache Solr which is a little more efficient plus you place the search out onto another server, a BIG performance boost, plus you can search on search results which lets you refine searches without all the overhead of a brand new search. Anyone of those improvements will make the underlying Web site faster.
drupal.org uses Solr but was one of the first Drupal sites to switch and may not have enough resources allocated. The Drupal implementation does not use all the features of Solr that can make Solr fast. One change that happened recently is the ability in some places to specify the relevant release of Drupal in a search. Solr makes selective searches easier because Solr is built for that type of search. drupal.org search should be faster when it uses all the features of Solr.
drupal.org/project/apachesolr