SlideShare a Scribd company logo
A new tool for measuring
performance in Drupal 8
Luca Lusso
Senior Drupal Developer @ Wellnet
• www.drupal.org/u/lussoluca
• @lussoluca
Agenda
• Overview of existing profilers
• Introducing Webprofiler
• Drupal Console integration
• Future developments
Overview of existing
profilers
How to measure
performance
• Hardware/OS profilers
• Function-level profilers
• Application profilers
we focus on these
Overview of function-level profilers
Open source
• xDebug
• XHProf / uprofiler
• …
Commercial
• NewRelic
• Blackfire.io (free for open source projects)
• Zend z-ray (available in Zend Server 8)
• …
Strengths
• Very detailed analysis
• Useful to find out which functions spends a lot of time or
memory
• can be used on production (sampling)
Weakness
• Difficult to install / commercial
• Difficult to analyze data (too much and too low level)
Overview of function-level profilers
Overview of application profilers
In Drupal we have the great Devel module
Query logger / Time and memory logger
The problem with Drupal (8)
• A simple page with a couple of views can do some expensive queries
• Requesting a service causes the loading of all dependent services (if
not declared as lazy)
• We can trigger of a lot of events
• Poorly implemented cache can cause heavy operations to be
executed for every request
• A lot of css and js can slows down the page render
• Builded but not rendered blocks
• …
All of those problems are difficult to discover at PHP
level, we need to profile the internals of Drupal.
Introducing
Webprofiler
Symfony2 Webprofiler
Built-in in Symfony2 full stack distribution
Code available in Drupal 8 and
missing pieces
A lot of code was already available into the core. All the
infrastructure for collecting and storing profiles were in place
and there was an initial set of data collectors available.
• SymfonyComponentHttpKernelProfiler (in Drupal 8)
• SymfonyComponentHttpKernelDataCollector (in Drupal 8)
Code available in Drupal 8 and
missing pieces
The missing piece was the WebProfilerBundle. In a
Symfony full stack application a bundle is the equivalent
of a Drupal module, the problem here is that Drupal 8 isn’t
a Symfony full stack application. Drupal has its own
structures and internals and uses some of the Symfony
components to replace legacy code. Unfortunately a
bundle doesn’t work on Drupal, we need a module.
• SymfonyBundleWebProfilerBundle (not in Drupal 8)
Drupal 8 Webprofiler
Available as contrib module
http://www.drupal.org/project/webprofiler
https://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
Workflow
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:
Workflow
Profiling turned off
Ajax Request Response
/profiler/efa2f1
Returns only the
toolbar DOM (with
embedded
javascript, css and
icons)
Instrumentation
• To profile our application we need to inject some
instrumentation code
• We have to replace the original code with a version
that do the same thing but, at the same time, saves
runtime data. In Drupal 8 this is fairly simple
because we have services and a Dependency
Injection Container
• These data must be saved somewhere to be used
later for toolbar rendering and for further analysis
• We need to find the service that is in charge of manage the structure we
want to profile (configurations reads from the Configuration Management
in this case)
• All core services are defined in core/core.services.yml, contrib services
are in modulename.services.yml
• In this example we instrument the “config.factory” service
config.factory:

class: DrupalCoreConfigConfigFactory

tags:

- { name: event_subscriber }

- { name: service_collector, tag: 'config.factory.override', call: addOverride }
Instrumenting the config.factory service
core/core.services.yml
Instrumenting the config.factory service
$container->setDefinition('config.factory.default', $container->getDefinition('config.factory'));

$container->register('config.factory', 'DrupalwebprofilerConfigConfigFactoryWrapper')

->addArgument(new Reference('webprofiler.config'))

->addArgument(new Reference('config.factory.default'));
• Rename the original service
• Register a new service with the original name
(config.factory) but with a different class
(ConfigFactoryWrapper) and inject both the specific
data collector service and the renamed service
DrupalwebprofilerWebprofilerServiceProvider.php
Instrumenting the config.factory service
class ConfigFactoryWrapper implements ConfigFactoryInterface {



protected $configFactory;

protected $configDataCollector;



public function __construct(ConfigDataCollector $configDataCollector,
ConfigFactoryInterface $configFactory) {

$this->configFactory = $configFactory;

$this->configDataCollector = $configDataCollector;

}



public function get($name) {

$result = $this->configFactory->get($name);

$this->configDataCollector->addConfigName($name);

return $result;

}

[..]

}
Forward to the original method
Collect datas
DrupalwebprofilerConfigConfigFactoryWrapper.php
Instrumentation
Note that instrumenting a program can cause performance
issues, and may in some cases lead to inaccurate results.

Webprofiler should not be used in a production environment.
Demo time
Integration with XHProf/UProfiler
Drupal 8 version of XHProf module is compatibile with
Webprofiler (http://www.drupal.org/project/xhprof)
admin/config/development/profiler/configureadmin/config/development/xhprof
Storage backends
• Database (done)
• Filesystem (done)
• Elasticsearch (work in progess https://
www.drupal.org/node/2356123)
Drupal Console
integration
Drupal Console
• 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
Implemented commands
• webprofiler:list -> list stored profiles
• webprofiler:export -> export stored profiles
• webprofiler:benchmark -> benchmark a site
running a huge number of request and computing
statistics:
$> console webprofiler:benchmark http://d8 --runs=10
Future developments
Open issues
• Collect initializer time/amount of dependencies for container services
(#2353253)
• Collect performance metrics for services over time (#2349935)
• Show database performance metrics commonly found in MySQL-Tuner.pl
(#2349923)
• Collect slow queries and report them over time (#2349911)
• Collect rebuilding time of important caches (e.g. menu router, container,
etc.) (#2349867)
• Collect cache / DB services timing metrics (#2349845)
• …
Better UI/UX
• ajax
• backbone
Profiles Diff
Compute and show diff of two different profiles
More offline statistics via
Drupal Console
• Queries
• Cache hit/miss
• Events
• …
Thanks!

More Related Content

PDF
Drupal Webinar: Ignite and Accelerate Your Drupal 7 to Drupal 9 Migration
PDF
Upgrades and migrations
PPTX
Drupal 8 Modules
PDF
5 essential tools for the PHP Developer on Windows
PDF
Adapting to a Responsive Design at Untangle the Web on 29th July 2013
PDF
PPTX
Understanding the DevOps Tooling Landscape
PPTX
Our encounter with d8
Drupal Webinar: Ignite and Accelerate Your Drupal 7 to Drupal 9 Migration
Upgrades and migrations
Drupal 8 Modules
5 essential tools for the PHP Developer on Windows
Adapting to a Responsive Design at Untangle the Web on 29th July 2013
Understanding the DevOps Tooling Landscape
Our encounter with d8

What's hot (20)

PPTX
Reliable Drupal Partner
PDF
Grails At Linked
PDF
Grails patterns and practices
PDF
Continuous integration and delivery for java based web applications
PDF
Upgrading to Drupal 8: Benefits and Gotchas
PDF
Drupal Migrations in 2018
PDF
Everything You Need to Know About the Top Changes in Drupal 8
PPTX
Drupal 8 Vocabulary Lesson
PDF
Introducing Workspace Preview System: Solve Your Content Preview Problems
PDF
Cloud Foundry and Microservices: A Mutualistic Symbiotic Relationship
ODP
Upgrading your site from Drupal 6 to Drupal 7
PPTX
DevOps and the DBA- 24 Hours of Pass
PPTX
Resources for Navigating Drupal Upgrades: Versions 6 Through 8 And What It Me...
PPTX
Lightning Distribution for Drupal: Build Advanced Authoring Experiences in Dr...
PPTX
DevOps and DBA- Delphix
PDF
Speedrun: Build a Website with Panels, Media, and More in 45 Minutes
PPTX
Version Control, Writers, and Workflows
PDF
5 Reasons not to use Dita from a CCMS Perspective
PDF
Atlassian Jira Brochure
PDF
DevOps - A Gentle Introduction
Reliable Drupal Partner
Grails At Linked
Grails patterns and practices
Continuous integration and delivery for java based web applications
Upgrading to Drupal 8: Benefits and Gotchas
Drupal Migrations in 2018
Everything You Need to Know About the Top Changes in Drupal 8
Drupal 8 Vocabulary Lesson
Introducing Workspace Preview System: Solve Your Content Preview Problems
Cloud Foundry and Microservices: A Mutualistic Symbiotic Relationship
Upgrading your site from Drupal 6 to Drupal 7
DevOps and the DBA- 24 Hours of Pass
Resources for Navigating Drupal Upgrades: Versions 6 Through 8 And What It Me...
Lightning Distribution for Drupal: Build Advanced Authoring Experiences in Dr...
DevOps and DBA- Delphix
Speedrun: Build a Website with Panels, Media, and More in 45 Minutes
Version Control, Writers, and Workflows
5 Reasons not to use Dita from a CCMS Perspective
Atlassian Jira Brochure
DevOps - A Gentle Introduction
Ad

Viewers also liked (8)

KEY
Drupal Day 2011 - Drupal per la ricerca, il caso EAI
PDF
Drupal Day 2011 - Node.js e Drupal
PDF
DDAY2014 - Performance in Drupal 8
PDF
Tooling, theming, made easy
PDF
Ineditus
PDF
Drupal per la ricerca
PDF
Wireframe, mockup e visual: quali strumenti per le prime fasi di un design?
PDF
Codemotion 2012 : Accesso e analisi di Open Data: come gestire l'anarchia dei...
Drupal Day 2011 - Drupal per la ricerca, il caso EAI
Drupal Day 2011 - Node.js e Drupal
DDAY2014 - Performance in Drupal 8
Tooling, theming, made easy
Ineditus
Drupal per la ricerca
Wireframe, mockup e visual: quali strumenti per le prime fasi di un design?
Codemotion 2012 : Accesso e analisi di Open Data: come gestire l'anarchia dei...
Ad

Similar to A new tool for measuring performance in Drupal 8 - DrupalCamp London (20)

PDF
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
PDF
Drupal8 for Symfony Developers (PHP Day Verona 2017)
PDF
A new tool for measuring performance in Drupal 8 - Drupal Dev Days Montpellier
PDF
Intro to drupal_7_architecture
PPTX
Top 8 Improvements in Drupal 8
PDF
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
PDF
Drupal 8 improvements for developer productivity php symfony and more
PPT
Into to drupal8
PPTX
BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems...
PDF
Drupal 8 - Core and API Changes
PPTX
Dolibarr - What's new in 20.0 - DevCamp Montpellier 2024.pptx
PDF
Docker containers & the Future of Drupal testing
PDF
Drupal 8 Configuration Management with Features
PPTX
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
PDF
MuleSoft Surat Virtual Meetup#6 - MuleSoft Project Template Using Maven Arche...
PDF
Apache Cayenne for WO Devs
PDF
Google App Engine
KEY
DrupalCon 2011 Highlight
PPT
Edp bootstrapping a-software_company
PPTX
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Drupal8 for Symfony Developers (PHP Day Verona 2017)
A new tool for measuring performance in Drupal 8 - Drupal Dev Days Montpellier
Intro to drupal_7_architecture
Top 8 Improvements in Drupal 8
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
Drupal 8 improvements for developer productivity php symfony and more
Into to drupal8
BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems...
Drupal 8 - Core and API Changes
Dolibarr - What's new in 20.0 - DevCamp Montpellier 2024.pptx
Docker containers & the Future of Drupal testing
Drupal 8 Configuration Management with Features
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
MuleSoft Surat Virtual Meetup#6 - MuleSoft Project Template Using Maven Arche...
Apache Cayenne for WO Devs
Google App Engine
DrupalCon 2011 Highlight
Edp bootstrapping a-software_company
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)

More from Luca Lusso (6)

PDF
Searching on Drupal with search API and Typesense
PDF
Leveraging the Command Pattern: Enhancing Drupal with Symfony Messenger.pdf
PDF
Drupalcon 2023 - How Drupal builds your pages.pdf
PDF
Do you know what your drupal is doing? Observe it!
PDF
Devel for Drupal 8
PDF
Come portare il profiler di symfony2 in drupal8
Searching on Drupal with search API and Typesense
Leveraging the Command Pattern: Enhancing Drupal with Symfony Messenger.pdf
Drupalcon 2023 - How Drupal builds your pages.pdf
Do you know what your drupal is doing? Observe it!
Devel for Drupal 8
Come portare il profiler di symfony2 in drupal8

Recently uploaded (20)

PPTX
Introuction about WHO-FIC in ICD-10.pptx
PPT
tcp ip networks nd ip layering assotred slides
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PPTX
artificial intelligence overview of it and more
PPTX
presentation_pfe-universite-molay-seltan.pptx
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPTX
Power Point - Lesson 3_2.pptx grad school presentation
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PPTX
SAP Ariba Sourcing PPT for learning material
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PDF
Testing WebRTC applications at scale.pdf
PPTX
Digital Literacy And Online Safety on internet
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PPTX
Funds Management Learning Material for Beg
PDF
The Internet -By the Numbers, Sri Lanka Edition
Introuction about WHO-FIC in ICD-10.pptx
tcp ip networks nd ip layering assotred slides
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
Introuction about ICD -10 and ICD-11 PPT.pptx
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
artificial intelligence overview of it and more
presentation_pfe-universite-molay-seltan.pptx
Tenda Login Guide: Access Your Router in 5 Easy Steps
Module 1 - Cyber Law and Ethics 101.pptx
Power Point - Lesson 3_2.pptx grad school presentation
WebRTC in SignalWire - troubleshooting media negotiation
SAP Ariba Sourcing PPT for learning material
The New Creative Director: How AI Tools for Social Media Content Creation Are...
Testing WebRTC applications at scale.pdf
Digital Literacy And Online Safety on internet
RPKI Status Update, presented by Makito Lay at IDNOG 10
introduction about ICD -10 & ICD-11 ppt.pptx
Slides PDF The World Game (s) Eco Economic Epochs.pdf
Funds Management Learning Material for Beg
The Internet -By the Numbers, Sri Lanka Edition

A new tool for measuring performance in Drupal 8 - DrupalCamp London

  • 1. A new tool for measuring performance in Drupal 8
  • 2. Luca Lusso Senior Drupal Developer @ Wellnet • www.drupal.org/u/lussoluca • @lussoluca
  • 3. Agenda • Overview of existing profilers • Introducing Webprofiler • Drupal Console integration • Future developments
  • 5. How to measure performance • Hardware/OS profilers • Function-level profilers • Application profilers we focus on these
  • 6. Overview of function-level profilers Open source • xDebug • XHProf / uprofiler • … Commercial • NewRelic • Blackfire.io (free for open source projects) • Zend z-ray (available in Zend Server 8) • …
  • 7. Strengths • Very detailed analysis • Useful to find out which functions spends a lot of time or memory • can be used on production (sampling) Weakness • Difficult to install / commercial • Difficult to analyze data (too much and too low level) Overview of function-level profilers
  • 8. Overview of application profilers In Drupal we have the great Devel module Query logger / Time and memory logger
  • 9. The problem with Drupal (8) • A simple page with a couple of views can do some expensive queries • Requesting a service causes the loading of all dependent services (if not declared as lazy) • We can trigger of a lot of events • Poorly implemented cache can cause heavy operations to be executed for every request • A lot of css and js can slows down the page render • Builded but not rendered blocks • … All of those problems are difficult to discover at PHP level, we need to profile the internals of Drupal.
  • 11. Symfony2 Webprofiler Built-in in Symfony2 full stack distribution
  • 12. Code available in Drupal 8 and missing pieces A lot of code was already available into the core. All the infrastructure for collecting and storing profiles were in place and there was an initial set of data collectors available. • SymfonyComponentHttpKernelProfiler (in Drupal 8) • SymfonyComponentHttpKernelDataCollector (in Drupal 8)
  • 13. Code available in Drupal 8 and missing pieces The missing piece was the WebProfilerBundle. In a Symfony full stack application a bundle is the equivalent of a Drupal module, the problem here is that Drupal 8 isn’t a Symfony full stack application. Drupal has its own structures and internals and uses some of the Symfony components to replace legacy code. Unfortunately a bundle doesn’t work on Drupal, we need a module. • SymfonyBundleWebProfilerBundle (not in Drupal 8)
  • 14. Drupal 8 Webprofiler Available as contrib module http://www.drupal.org/project/webprofiler https://github.com/lussoluca/webprofiler
  • 16. Workflow 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:
  • 17. Workflow Profiling turned off Ajax Request Response /profiler/efa2f1 Returns only the toolbar DOM (with embedded javascript, css and icons)
  • 18. Instrumentation • To profile our application we need to inject some instrumentation code • We have to replace the original code with a version that do the same thing but, at the same time, saves runtime data. In Drupal 8 this is fairly simple because we have services and a Dependency Injection Container • These data must be saved somewhere to be used later for toolbar rendering and for further analysis
  • 19. • We need to find the service that is in charge of manage the structure we want to profile (configurations reads from the Configuration Management in this case) • All core services are defined in core/core.services.yml, contrib services are in modulename.services.yml • In this example we instrument the “config.factory” service config.factory:
 class: DrupalCoreConfigConfigFactory
 tags:
 - { name: event_subscriber }
 - { name: service_collector, tag: 'config.factory.override', call: addOverride } Instrumenting the config.factory service core/core.services.yml
  • 20. Instrumenting the config.factory service $container->setDefinition('config.factory.default', $container->getDefinition('config.factory'));
 $container->register('config.factory', 'DrupalwebprofilerConfigConfigFactoryWrapper')
 ->addArgument(new Reference('webprofiler.config'))
 ->addArgument(new Reference('config.factory.default')); • Rename the original service • Register a new service with the original name (config.factory) but with a different class (ConfigFactoryWrapper) and inject both the specific data collector service and the renamed service DrupalwebprofilerWebprofilerServiceProvider.php
  • 21. Instrumenting the config.factory service class ConfigFactoryWrapper implements ConfigFactoryInterface {
 
 protected $configFactory;
 protected $configDataCollector;
 
 public function __construct(ConfigDataCollector $configDataCollector, ConfigFactoryInterface $configFactory) {
 $this->configFactory = $configFactory;
 $this->configDataCollector = $configDataCollector;
 }
 
 public function get($name) {
 $result = $this->configFactory->get($name);
 $this->configDataCollector->addConfigName($name);
 return $result;
 }
 [..]
 } Forward to the original method Collect datas DrupalwebprofilerConfigConfigFactoryWrapper.php
  • 22. Instrumentation Note that instrumenting a program can cause performance issues, and may in some cases lead to inaccurate results. Webprofiler should not be used in a production environment.
  • 24. Integration with XHProf/UProfiler Drupal 8 version of XHProf module is compatibile with Webprofiler (http://www.drupal.org/project/xhprof) admin/config/development/profiler/configureadmin/config/development/xhprof
  • 25. Storage backends • Database (done) • Filesystem (done) • Elasticsearch (work in progess https:// www.drupal.org/node/2356123)
  • 27. Drupal Console • 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
  • 28. Implemented commands • webprofiler:list -> list stored profiles • webprofiler:export -> export stored profiles • webprofiler:benchmark -> benchmark a site running a huge number of request and computing statistics: $> console webprofiler:benchmark http://d8 --runs=10
  • 30. Open issues • Collect initializer time/amount of dependencies for container services (#2353253) • Collect performance metrics for services over time (#2349935) • Show database performance metrics commonly found in MySQL-Tuner.pl (#2349923) • Collect slow queries and report them over time (#2349911) • Collect rebuilding time of important caches (e.g. menu router, container, etc.) (#2349867) • Collect cache / DB services timing metrics (#2349845) • …
  • 32. Profiles Diff Compute and show diff of two different profiles
  • 33. More offline statistics via Drupal Console • Queries • Cache hit/miss • Events • …