Артем Сильчук - respond in 60ms. extremal optimization with reinventing a wheel
TRANSCRIPT
![Page 1: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/1.jpg)
Respond in 60ms.
Extremal optimization with reinventing a
wheel
![Page 2: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/2.jpg)
About me: Drupal developer since 2010
Artem Sylchuk
![Page 3: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/3.jpg)
How long it takes to load a page?
![Page 4: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/4.jpg)
1,096,471 microsecs
24,824 microsecs
?
![Page 5: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/5.jpg)
XHProf
![Page 6: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/6.jpg)
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?
![Page 7: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/7.jpg)
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).
![Page 8: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/8.jpg)
![Page 9: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/9.jpg)
How does Drupal load pages?
drupal_bootstrap()
3,294 microsecs
48,839 microsecs
65,190 microsecs
63,089 microsecs
66,188 microsecs
73,894 microsecs
687,986 microsecs
![Page 10: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/10.jpg)
menu_execute_active_handler
1,639,028 microsecs
![Page 11: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/11.jpg)
drupal_deliver_page
drupal_deliver_html_page
drupal_render_page
![Page 12: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/12.jpg)
(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
![Page 13: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/13.jpg)
History of Chiq.com
![Page 14: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/14.jpg)
Thin applications idea
![Page 15: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/15.jpg)
start
load bootsrap.inc
bootstrap session //
connect to DB, start
session
home
page?
Load homepage
application
search
page?
Load
Search
application
bootstrap FULL
finish
finish
Load
Drupal
finish
yes
yes
no
no
item
?
load item
application
bootstrap language
bootstrap late page cache
check for canvas page
bootstrap path
yes
no
finish
![Page 16: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/16.jpg)
![Page 17: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/17.jpg)
Result?
![Page 18: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/18.jpg)
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.
![Page 19: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/19.jpg)
Is there a way to make it better?
![Page 20: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/20.jpg)
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)
![Page 21: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/21.jpg)
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.
![Page 22: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/22.jpg)
Views, panels, etc
![Page 23: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/23.jpg)
hook_boot
![Page 24: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/24.jpg)
Profit?
![Page 25: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/25.jpg)
Main myth of Drupal
We do write the code.
A lot of code. “81792 lines” lot of code.
![Page 26: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/26.jpg)
Drupal 8 - brave new world
Page generation time for anonymous user: 353,903 ms …
?
![Page 27: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/27.jpg)
Future?
= ?
![Page 28: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel](https://reader030.vdocument.in/reader030/viewer/2022032419/55a2849d1a28ab391d8b4727/html5/thumbnails/28.jpg)
Questions?