Respond in 60ms. 
Extremal optimization with reinventing a 
wheel
Artem Sylchuk 
About me: Drupal developer since 2010
How long it takes to load a page?
1,096,471 microsecs 
24,824 microsecs 
?
XHProf
Optimize it! 
1. Disable and uninstall unused modules. 
2. Switch to non-database cache backend. 
3. Enable page caching, CSS and JS aggregation. 
4. CDN 
5. Install “caching” modules. 
6. Investigate page load time using XHProf and/or NewRelic, etc. 
7. Configure cron jobs and other background processes. 
8. Optimize slow queries. 
9. Authcache?
Do more caching... 
The Authcache module offers page caching for both anonymous users and 
logged-in authenticated users. This allows Drupal/PHP to only spend 1-2 
milliseconds serving pages, greatly reducing server resources. 
How does it work? 
Authcache saves the final rendered HTML of a page to serve visitors. A separate cache is created for each user role as defined by the 
administrator, so some roles can be excluded if necessary. 
Authcache places priority on serving pages to the visitor as fast as possible. After a page is loaded by the browser, a second HTTP request may 
be performed via Ajax. This initiates a lightweight DRUPAL_BOOTSTRAP_SESSION that allows SQL queries to be executed (such as updating 
the user "history" table or node "statistics" table), and returns any user-customized data to the page (such as form tokens or default values on a 
contact form).
How does Drupal load pages? 
drupal_bootstrap() 
3,294 microsecs 
48,839 microsecs 
63,089 microsecs 
65,190 microsecs 
66,188 microsecs 
73,894 microsecs 
687,986 microsecs
menu_execute_active_handler 
1,639,028 microsecs
drupal_deliver_page 
drupal_deliver_html_page 
drupal_render_page
(Un)Real tasks? 
● Less than 10 database requests 
● Less than 100ms for the page generation 
● More than 10 000 users per minute 
● Page must be dynamic
History of Chiq.com
Thin applications idea
start 
load bootsrap.inc 
bootstrap session // 
connect to DB, start 
session 
home 
page? 
Load homepage 
application 
search 
page? 
Load 
Search 
application 
bootstrap language 
bootstrap late page cache 
check for canvas page 
bootstrap path 
yes 
bootstrap FULL 
finish 
finish 
Load 
Drupal 
finish 
yes 
yes 
no 
no 
item 
? 
load item 
application 
no 
finish
Result?
Cons 
1. It is custom. Too custom. 
● Maintainability. 
● Security. 
● Documentation. 
● Complexity. 
● Bicyclelity. 
● Development speed. 
● All other things why we prefer Drupal over a custom solution.
Is there a way to make it better?
Page delivery callbacks 
Add headers, print content. They deliver. 
● drupal_deliver_html_page 
● ajax_deliver 
● drupal_json_output (Media browser plus) 
● admin_menu_deliver (Admin menu)
Renderable arrays https://www.drupal.org/node/930760 
"Render Arrays" or 
"Renderable Arrays" are the 
building blocks of a Drupal 
page, starting with Drupal 7. 
A render array is an 
associative array which 
conforms to the standards 
and data structures used in Drupal's theme rendering system. 
In many cases, the data used to build a page (and all parts of it) is kept as 
structured arrays until the rendering stage in the theming system. This allows 
enormous flexibility in changing the layout or content of a page, and provides future 
performance enhancements as well.
Views, panels, etc
hook_boot
Profit?
Main myth of Drupal 
We do write the code. 
A lot of code. “81792 lines” lot of code.
Drupal 8 - brave new world 
Page generation time for anonymous user: 353,903 ms … 
?
Future? 
= ?
Questions?

Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel

  • 1.
    Respond in 60ms. Extremal optimization with reinventing a wheel
  • 2.
    Artem Sylchuk Aboutme: Drupal developer since 2010
  • 3.
    How long ittakes to load a page?
  • 4.
  • 5.
  • 6.
    Optimize it! 1.Disable and uninstall unused modules. 2. Switch to non-database cache backend. 3. Enable page caching, CSS and JS aggregation. 4. CDN 5. Install “caching” modules. 6. Investigate page load time using XHProf and/or NewRelic, etc. 7. Configure cron jobs and other background processes. 8. Optimize slow queries. 9. Authcache?
  • 7.
    Do more caching... The Authcache module offers page caching for both anonymous users and logged-in authenticated users. This allows Drupal/PHP to only spend 1-2 milliseconds serving pages, greatly reducing server resources. How does it work? Authcache saves the final rendered HTML of a page to serve visitors. A separate cache is created for each user role as defined by the administrator, so some roles can be excluded if necessary. Authcache places priority on serving pages to the visitor as fast as possible. After a page is loaded by the browser, a second HTTP request may be performed via Ajax. This initiates a lightweight DRUPAL_BOOTSTRAP_SESSION that allows SQL queries to be executed (such as updating the user "history" table or node "statistics" table), and returns any user-customized data to the page (such as form tokens or default values on a contact form).
  • 9.
    How does Drupalload pages? drupal_bootstrap() 3,294 microsecs 48,839 microsecs 63,089 microsecs 65,190 microsecs 66,188 microsecs 73,894 microsecs 687,986 microsecs
  • 10.
  • 11.
  • 12.
    (Un)Real tasks? ●Less than 10 database requests ● Less than 100ms for the page generation ● More than 10 000 users per minute ● Page must be dynamic
  • 13.
  • 14.
  • 15.
    start load bootsrap.inc bootstrap session // connect to DB, start session home page? Load homepage application search page? Load Search application bootstrap language bootstrap late page cache check for canvas page bootstrap path yes bootstrap FULL finish finish Load Drupal finish yes yes no no item ? load item application no finish
  • 17.
  • 18.
    Cons 1. Itis custom. Too custom. ● Maintainability. ● Security. ● Documentation. ● Complexity. ● Bicyclelity. ● Development speed. ● All other things why we prefer Drupal over a custom solution.
  • 19.
    Is there away to make it better?
  • 20.
    Page delivery callbacks Add headers, print content. They deliver. ● drupal_deliver_html_page ● ajax_deliver ● drupal_json_output (Media browser plus) ● admin_menu_deliver (Admin menu)
  • 21.
    Renderable arrays https://www.drupal.org/node/930760 "Render Arrays" or "Renderable Arrays" are the building blocks of a Drupal page, starting with Drupal 7. A render array is an associative array which conforms to the standards and data structures used in Drupal's theme rendering system. In many cases, the data used to build a page (and all parts of it) is kept as structured arrays until the rendering stage in the theming system. This allows enormous flexibility in changing the layout or content of a page, and provides future performance enhancements as well.
  • 22.
  • 23.
  • 24.
  • 25.
    Main myth ofDrupal We do write the code. A lot of code. “81792 lines” lot of code.
  • 26.
    Drupal 8 -brave new world Page generation time for anonymous user: 353,903 ms … ?
  • 27.
  • 28.