28
Respond in 60ms. Extremal optimization with reinventing a wheel

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

Embed Size (px)

Citation preview

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

Respond in 60ms.

Extremal optimization with reinventing a

wheel

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

About me: Drupal developer since 2010

Artem Sylchuk

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

How long it takes to load a page?

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

1,096,471 microsecs

24,824 microsecs

?

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

XHProf

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

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

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
Page 9: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel

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

menu_execute_active_handler

1,639,028 microsecs

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

drupal_deliver_page

drupal_deliver_html_page

drupal_render_page

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

(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

History of Chiq.com

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

Thin applications idea

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

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
Page 17: Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel

Result?

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

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

Is there a way to make it better?

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

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

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

Views, panels, etc

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

hook_boot

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

Profit?

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

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

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

Future?

= ?

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

Questions?