A new tool for measuring
performance in Drupal 8
Luca Lusso
Luca Lusso
• Senior Drupal Developer @ Wellnet - Italy
• Acquia developer and backend developer certification
• Twitter: @lussoluca
• drupal.org/IRC: lussoluca
• Not so fluent in english… sorry
Symfony has a great
profiler tool
symfony.com/doc/current/cookbook/profiler
Symfony profiler
• Performance monitoring
• Huge amount of high-level data about application’s
internals (database query, rendered forms, errors, http
request and response headers, routing, events, services,
…)
• Useful in functional testing (more on this later)
Drupal 8 is built on Symfony so… we have the
profiler too?!
Nope…
But wait… the Symfony profiler classes are declared in
the HttpKernel component, here:
core/vendor/symfony/http-kernel/Symfony/
Component/HttpKernel/Profiler
And the HttpKernel IS in Drupal 8, so what is missing?
Glue code is in
FrameworkBundle
and
WebProfilerBundle
But Symfony bundles doesn't works in Drupal 8 :-(
Two options:
1. make Symfony bundles works in Drupal 8
(www.drupal.org/node/1880196 -> won't fix)
2. move the bundle code to a Drupal module
We choose the Drupal way™
Drupal Webprofiler
Module
www.drupal.org/project/webprofiler

github.com/lussoluca/webprofiler
Implemented DataCollectors
PHP Config
Request
Timeline
Frontend
Database
User
Views
Block
Http
Extensions
Events
State
Config
Assets
Cache
Routing
Service
Forms
Every widget shows data about a metric measured
by a data collector on the current rendered page
How does it work
Instrumented
(collect data and
store profile)
Request Response
<div id="webprofilerefa2f1"></div>
<script>
Webprofiler = (function () {
[…]
}
</script>
Response
• Add HTTP header -> X-Debug-Token: efa2f1
• Inject some javascript in the page:
How does it work
Profiling turned off
Ajax Request Response
/profiler/efa2f1
Returns only the
toolbar DOM (with
embedded
javascript, css and
icons)
Integration with XHProf/UProfiler
Drupal 8 version of XHProf module is compatibile with
Webprofiler (www.drupal.org/project/xhprof)
admin/config/development/profiler/configureadmin/config/development/xhprof
Demo
What you can measure, you can optimize
Integration with Drupal Console project
• Leverages the Symfony Console Component to provide a
powerful CLI
• Started as scaffolding generator now expose an
increasing number of commands to interact with a Drupal
8 installation
• Modules can contribute implementing new commands
drupalconsole.com
Implemented commands
• webprofiler:list -> list stored profiles
• webprofiler:export -> export stored profiles
• webprofiler:benchmark -> benchmark an URL running a
huge number of requests and compute statistics
• webprofiler:analyze -> analyze all stored profiles for a
specific route and compute statistics (not yet available on
drupal.org)
Benchmark an URL
• Anonymous user

console webprofiler:benchmark http://d8 —runs=10
• Logged-in user

console webprofiler:benchmark http://admin:admin@d8/admin/
people —runs=10
• Rebuild cache before benchmark

console webprofiler:benchmark http://d8 --runs=10 —cache-
rebuild
• Store results in a file

console webprofiler:benchmark http://d8 --runs=10 --file=/Users/
lussoluca/Desktop/benchmark.yml
Analyze a route
• Default front page

console webprofiler:analyze view.frontpage.page_1 GET
average
• User profile page

console webprofiler:analyze entity.user.canonical GET
average
Write a new datacollector
Contrib modules can provides new data collectors
• find a service to instrument
• write a new class to wrap/replace the original service
• alter the container to instrument the service
• write a new data collector class
• write a new template class
Functional testing
• We can mock the plugin.manager.mail service or the
http_client service, for example, but if we want to write a
functional test with a real integration?
• Maybe we want to test how much time is spent or how
much memory is consumed
We can use data profiled by Webprofiler in our assertions
symfony.com/doc/current/cookbook/testing/profiling.html
Contributors
• Daniel Wehner (dawehner) - co-mantainer
• Eric Sod (esod)
• willzyx
• Francesco Caspani (fcaspani)
• Jesus Manuel Olivas (jmolivas)
We need a huge help on
• UX
• Javascript (Backbone) - www.drupal.org/node/2468007
• Statistical analysis
• Documentation
So please contact us!
Thanks!

A new tool for measuring performance in Drupal 8 - Drupal Dev Days Montpellier

  • 1.
    A new toolfor measuring performance in Drupal 8 Luca Lusso
  • 2.
    Luca Lusso • SeniorDrupal Developer @ Wellnet - Italy • Acquia developer and backend developer certification • Twitter: @lussoluca • drupal.org/IRC: lussoluca • Not so fluent in english… sorry
  • 3.
    Symfony has agreat profiler tool symfony.com/doc/current/cookbook/profiler
  • 4.
    Symfony profiler • Performancemonitoring • Huge amount of high-level data about application’s internals (database query, rendered forms, errors, http request and response headers, routing, events, services, …) • Useful in functional testing (more on this later)
  • 5.
    Drupal 8 isbuilt on Symfony so… we have the profiler too?!
  • 6.
  • 7.
    But wait… theSymfony profiler classes are declared in the HttpKernel component, here: core/vendor/symfony/http-kernel/Symfony/ Component/HttpKernel/Profiler And the HttpKernel IS in Drupal 8, so what is missing?
  • 8.
    Glue code isin FrameworkBundle and WebProfilerBundle But Symfony bundles doesn't works in Drupal 8 :-(
  • 9.
    Two options: 1. makeSymfony bundles works in Drupal 8 (www.drupal.org/node/1880196 -> won't fix) 2. move the bundle code to a Drupal module We choose the Drupal way™
  • 10.
  • 11.
  • 12.
    How does itwork Instrumented (collect data and store profile) Request Response <div id="webprofilerefa2f1"></div> <script> Webprofiler = (function () { […] } </script> Response • Add HTTP header -> X-Debug-Token: efa2f1 • Inject some javascript in the page:
  • 13.
    How does itwork Profiling turned off Ajax Request Response /profiler/efa2f1 Returns only the toolbar DOM (with embedded javascript, css and icons)
  • 14.
    Integration with XHProf/UProfiler Drupal8 version of XHProf module is compatibile with Webprofiler (www.drupal.org/project/xhprof) admin/config/development/profiler/configureadmin/config/development/xhprof
  • 15.
  • 16.
    What you canmeasure, you can optimize
  • 17.
    Integration with DrupalConsole project • Leverages the Symfony Console Component to provide a powerful CLI • Started as scaffolding generator now expose an increasing number of commands to interact with a Drupal 8 installation • Modules can contribute implementing new commands drupalconsole.com
  • 18.
    Implemented commands • webprofiler:list-> list stored profiles • webprofiler:export -> export stored profiles • webprofiler:benchmark -> benchmark an URL running a huge number of requests and compute statistics • webprofiler:analyze -> analyze all stored profiles for a specific route and compute statistics (not yet available on drupal.org)
  • 19.
    Benchmark an URL •Anonymous user
 console webprofiler:benchmark http://d8 —runs=10 • Logged-in user
 console webprofiler:benchmark http://admin:admin@d8/admin/ people —runs=10 • Rebuild cache before benchmark
 console webprofiler:benchmark http://d8 --runs=10 —cache- rebuild • Store results in a file
 console webprofiler:benchmark http://d8 --runs=10 --file=/Users/ lussoluca/Desktop/benchmark.yml
  • 20.
    Analyze a route •Default front page
 console webprofiler:analyze view.frontpage.page_1 GET average • User profile page
 console webprofiler:analyze entity.user.canonical GET average
  • 21.
    Write a newdatacollector Contrib modules can provides new data collectors • find a service to instrument • write a new class to wrap/replace the original service • alter the container to instrument the service • write a new data collector class • write a new template class
  • 22.
    Functional testing • Wecan mock the plugin.manager.mail service or the http_client service, for example, but if we want to write a functional test with a real integration? • Maybe we want to test how much time is spent or how much memory is consumed We can use data profiled by Webprofiler in our assertions symfony.com/doc/current/cookbook/testing/profiling.html
  • 23.
    Contributors • Daniel Wehner(dawehner) - co-mantainer • Eric Sod (esod) • willzyx • Francesco Caspani (fcaspani) • Jesus Manuel Olivas (jmolivas)
  • 24.
    We need ahuge help on • UX • Javascript (Backbone) - www.drupal.org/node/2468007 • Statistical analysis • Documentation So please contact us!
  • 25.