Implementing High Performance Drupal Sites


Published on

UniMity's substantial presence in Drupal Camp Deccan 11-11-11 in HYD. Audience were just applauding with gusto at the end of our presentation (How to build and maintain high performance websites)

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Performance of a website is the Speed at which the website can be accessed by the end user. - how fast the website can handle a single request. Scalability - how many requests your application can handle at the same time, or the amount of information it can store and process. - capability of a system to increase total throughput under an increased load when resources are added
  • Three Layers of performance are Users(Browser), Server side and Application (i.e Drupal) We will be concentrating on Application. Here I will brief you on User end. Size of page components plays a major part in perfromance - HTML Dom elements - Js files - CSS files - images To reduce the size of the components - Write simple code with good planning. - Minfy the js and CSS files - compress page components using GZIP of Apache No of request ( less no of request faster the page load ) To reduce the request compress many files into single files for js and css ( if you have many css or js files ) use sprite images for CSS background image Browser Cache Assign Expires header for long period, so that browser woouln’t request the page components for every page request Enable ETags which assist to load the files that is changed.
  • Drupal in Core has a dedicated page for configuring the cache and page compression In Settings page Drupal allow us to configure the cache by enabling and assigning the lifetime for the cache There a option to enable the block cache – which will be useful for authenticated users , as page cache won’t available for authenticated user, but one thing we have to keep in our mind is that block module won’t cache the block if the user access is defined. Enable the page compression Optimise the CSS files – which will compress many files to single file Optimise the Javascript file - which will compress many file to single file. Other than the Drupal core, the module we use frequently like views and panels will also provides us feature to manage the cache on there own. Views provide us two options to cache, i.e cache query and cache rendered html which is time based. For Logging Error’s Drupal provides two option one is Dblog and Syslog, Dblog is used to log the activities in DB, whereas Syslog user file system to log. In high traffic sites it is recommended to use syslog and DBlog frequent writing will cause the mysql to slow. And if your db engine is Myisam it will be more slow as Myisam has table lock. Use Developer tools, to assist in fine tuning the performance for example use Devel module to analyse the SQL query executed while a page renders. - Check the repetition of SQL queries, if so try to reduce the duplication, if the same function getting called more than once and executing same query then use static variable to return the result set. - Check the execution time of the SQL query if it takes more than 3 ms then analyse the query with Explain command in mysql, with the help of this analyses try to index the columns of the table used in “where” condition. Makesure all tables using index. Use DB tuner a module suggest to fine the MYSQL database - it will suggest to index the some CCK table columns - it will suggest some changes to MYSQL configuration ( Get the help of the system Admin to implement this. Don’t go by all suggest, take decision on your own by analyzing other parameters )
  • Always it is recommended to follow the Coding standards defined in Split the module file as possible if the line of code goes more than 300 Get the clue from other drupal contributed module, it is familiar to see,, in the module folder Resuse Drupal functions – before writing a function make sure, Drupal doesn’t have the same. Use Static Variables to cache the content inside a function, you can refer the node_load for example , node_load will store the node objects in the static variable and it will render the a node object singe time, next time it will return the object from the cache. This cache will be retained for single page render. Query VS use of views Views always use left Join which will have some impact on execution time. View is heavy compare to Query as we have freedom to construct the query as we required. views allow us to build a block or page with minimal efforts. So if we use views don’t think that all queries wrote by views are optimized, Analyse each query and make required changes to the views query using appropriate hook’s hook_views_query_alter(&$view, &$query) { If required you may also write your own cache using cache api CACHE_SET, CACHE_GET
  • Advacned Caching systems are available instead of Drupal’s DB cache. Like, BOOST, MEMCache, Varnish. Boost is the module which saves all pages as static html files and serve static files to the anonymous user. MemCache is the module which uses the memcache to store the caches in the memory instead of DB Varnish is also a like memcache which caches the pages in memory.
  • The Event Based Caching is one of powerfull way of handling our cache in drupal, We must have a through cache management, usually the cache is managed time based. But this time based cache is having downside that is if the time expires, though the content changed or not it will re-generate cache content, as this is as unneccesary load to server and So cache the content for long life term and clear cache only required region or block every event triggered. This will help us to reduce the load to server and serve the content more from cache.
  • This is the template used to manage cache for time based.
  • This is the template used to manage cache for event based.
  • Less SQL Path round trips Maintains a list of white listed paths that need url Alias, eg user/ doesnot use path alias, then no query sent to path table Per page cache of Pathalias On Cache miss only a particular tables caches get rebuilt and on Cache hit with just a couple of queries the pages are built. The down side is the storage need per page & how this increases with no of pages in a site - memcache. entity load vs node load functions - array of entities at a time, the concept of multiple load Per CCK storage no longer there -> could be a load, write storage backends raw Drupal 7 is still bad then Drupal 6, but can easily plugin external caching systems & storage engines to improve perforamcne.
  • Question ?
  • Implementing High Performance Drupal Sites

    1. 1. Presentation Title w w w . u n i m i t y . c o m DEC 2010 Implementing High Performance Drupal Sites Unimity Solutions. 3, 5th Floor, "Kasi Arcade" 116, Thyagaraya Road, T.Nagar, Chennai 600017 India, Phone: (91- 44) 43923800 By Kamalakanan & Shyamala
    2. 2. Presentation Path <ul><li>What is “Performance”? </li></ul><ul><li>Different Layers of Performance </li></ul><ul><li>How to configure Drupal for Performance </li></ul><ul><li>Writing Drupal Modules for High Performance </li></ul><ul><li>Some Advanced Techniques & Caching Systems </li></ul><ul><li>Event Based Caching </li></ul><ul><li>Drupal 6 vs Drupal 7 </li></ul><ul><li>Performance in Drupal 8 </li></ul>
    3. 3. What is “Performance”? <ul><li>The performance of a website is the speed at which the website can be accessed by the end user. </li></ul>Response Time Availability Scalability
    4. 4. Different Layers of Performance <ul><li>User end </li></ul><ul><ul><li>Size of Page </li></ul></ul><ul><ul><li>No of request </li></ul></ul><ul><ul><li>Browser Cache </li></ul></ul><ul><li>Server side </li></ul><ul><ul><li>PHP </li></ul></ul><ul><ul><li>MySql </li></ul></ul><ul><ul><li>Apache </li></ul></ul><ul><li>Application End </li></ul><ul><ul><li>Drupal </li></ul></ul>
    5. 5. How to configure Drupal for Performance <ul><li>Using Drupal Cache </li></ul><ul><ul><li>CSS JS Aggregation </li></ul></ul><ul><ul><li>Page Cache </li></ul></ul><ul><ul><li>Views, Block, Menu, Panel, Form Cache </li></ul></ul><ul><li>Number of Modules </li></ul><ul><li>Sys Log vs DB log </li></ul><ul><li>Developer Tools </li></ul><ul><ul><li>Devel </li></ul></ul><ul><ul><li>DB tuner </li></ul></ul>
    6. 6. Writing Drupal Modules for High Performance <ul><li>Coding Standards </li></ul><ul><li>Size of files </li></ul><ul><li>Appropriate use of inc files </li></ul><ul><li>Reuse Drupal functions as much as possible </li></ul><ul><li>Use of Static Variables </li></ul><ul><li>Efficient code </li></ul><ul><li>Query vs use of Views </li></ul><ul><li>Writing Custom Cache </li></ul>
    7. 7. Some Advanced Techniques & Caching Systems <ul><li>Event Based Caching </li></ul><ul><li>Boost </li></ul><ul><li>MemCache </li></ul><ul><li>Varnish </li></ul>
    8. 8. Event Based Caching
    9. 9. Event Based Caching vs Time Based Caching twice a day (Separate cron ) No Tag cloud   All  Once a Day (Separate cron) No Birthday Wishes   Home Once a day (separate cron) No Active members   Home   yes Display Name--> Did You Know Home Home   yes Display Name --> Spotlight Home Home   yes Display Name --> Home Slide Home Home           Time Based - update Frequency Event based Display Name View Name Page
    10. 10. Importance of planning for Cache Sheet   yes Display Name --> Announcement news_page Announcements             yes Display Name -->Buzz Zone       yes Display Name --> Recent topics,       No Display Name -->Popular in corporate zone,       yes Display Name --> Corporate Zone, rightside_blocks               yes Display Name --> News news_page           News Time Based - update Frequency Event based Display Name View Name Content Type
    11. 11. Performance in Drupal 6 vs Drupal 7 <ul><ul><li>Less SQL </li></ul></ul><ul><ul><li>Path round trips </li></ul></ul><ul><ul><li>Entity Load vs Node Load </li></ul></ul><ul><ul><li>CCK Storage vs Entities </li></ul></ul>
    12. 12. Performance in Drupal 8 <ul><li>Performance Gates </li></ul><ul><ul><li>SQL queries </li></ul></ul><ul><ul><li>Memory usage </li></ul></ul><ul><ul><li>CPU </li></ul></ul><ul><ul><li>System calls </li></ul></ul><ul><ul><li>Front end </li></ul></ul>
    13. 13. Expert Knowledge Groups – Groups.Drupal.Org
    14. 14. <ul><li>Thank You! </li></ul>