Profiling Dancer apps with Dancer::Plugin::NYTProf

Profiling is a good way to find bottlenecks in your code - if you find your app isn't as fast as you would like, it's good to be able to see where the time is being spent, so you know what areas of your code you should try to optmise to speed thing (although do be wary that premature optimisation is the root of all evil).

There are various profilers available, but Devel::NYTProf from Tim Bunce is very popular and provides useful, detailed, readable output.

But how can you easily profile a Dancer app?

Dancer::Plugin::NYTProf provides easy profiling - by simply loading the plugin, you'll have the detailed, helpful profiling provided by Devel::NYTProf. Each individual request is profiled, and going to the URL /nytprof will present a list of profile results; selecting one will serve up the pretty HTML report generated by Devel::NYTProf.

Using the plugin

The plugin will work by default without any configuration required - it will default to writing profiling data into a dir named profdir within your Dancer application's appdir, present profiling output at /nytprof (not yet configurable), and profile all requests.

To start using it, simply load it in your app as you would any other plugin:

use Dancer::Plugin::DevelNYTProf;

Start your app, make some requests to it, then go to /nytprof (e.g. http://localhost:3000/nytprof) and you should receive a list of profile runs.

Clicking one should bring up the usual pretty Devel::NYTProf output.

Security warning

At this time, I would not recommend loading this plugin in your public-facing production environment, as it hasn't been extensively checked for vulnerabilities, particularly in the code which executes nytprofhtml to generate the HTML reports. I would recommend using this in your development environment only.

AUTHOR

David Precious

This article was a little rushed, as it's pub time; I will try to extend it a little soon and add screenshots, but in the meantime it should be a taster on getting started profiling.