Taming the beast: performance optimization of unfamiliar applications with Blackfire – part 1 of 2

By Thomas di Luccio, on Sep 13, 2023

“You can’t optimize what you can’t measure”, that’s the ethos of Blackfire–highlighting the vital role of knowledge and understanding in the performance optimization journey. 

Developers often face barriers in performance optimization due to gaps in their understanding of both the macro and micro aspects of their applications. In-depth knowledge of an application’s internal behavior and scaffolding is required, alongside understanding its inherent business value and global dynamics.

You may be part of an agency that has just signed a new deal, or your team has inherited some legacy application, the original developers of which have long moved on. This means that foundational knowledge of an application is missing, making performance optimization much trickier.

Blackfire, a lighthouse allowing you to find your way

In these daunting scenarios, you may lack insights into the application’s overall dynamics, internals, coding practices, service execution, and even its business value. Recognizing the most used parts of such an application may also prove challenging.

What to expect? What to fear? What to hope for? What to prioritize?

But fear not, we’ve got your back. With the right approach and the assistance of Blackfire, navigating application discovery becomes significantly more straightforward.

Monitoring your production environment

First, we recommend activating Blackfire monitoring in the production environment to assess an application’s performance. As a reminder, Blackfire is designed to be safe for all environments.

Blackfire Monitoring provides a birds-eye view of your application to help you understand your application’s dynamics. What parts of the application are heavily solicited? How is the traffic? What are the peaks?

Blackfire monitoring also provides a comprehensive list of the most impactful transactions and spans. A transaction being an identified request, usually in the form of a Controller/Method combo. Whereas spans are the representation of function calls over time. The impact is calculated as the percentage of time processing one transaction or span versus all the other ones.

Effortless identification of the most impactful components

Blackfire allows you to identify the resource-intensive components of the application so you can prioritize your efforts effectively. Blackfire Monitoring allows you to target and optimize the key areas that will significantly enhance the user experience.

It’s about turning limited knowledge into actionable insight, ensuring that your next steps are driven by data, and ultimately maximizing your impact on your end users. Even if you didn’t know a thing about the application a few days ago.

At this stage, you have two options: you can either start optimizing one of the most impactful components of your application or start securing it to ensure its performance won’t degrade.

Attack or defense?

You should do both in the upcoming days or weeks. The question is to pick a strategy for your next move. I favor securing the application first, but I’d love to hear your take on this one. You will find links to our online communities at the end of this post to share your thoughts with our users.

The best way to ensure your application’s performance won’t degrade is to write performance tests. Then, you will have those tests evaluated periodically at first, then you could integrate them into your CI/CD pipeline for even tighter control.

For more detailed information, we published articles on test writing on this blog, from your first test to the integration with your pipelines. Let’s explore the basics to have you get started.

Secure the critical user journeys

Let’s say the top transactions table informed you that the most critical endpoints of your application were the homepage /, a product page /my-product, and the checkout page /checkout.

Our mission is to secure at least those 3 endpoints. We could also go beyond and secure the entire user journeys that include those endpoints. At the end of the day, we are looking to improve the overall user experience and, consequently, the application growth. 

As a first step toward this objective, our mission is to add a basic test boilerplate for those 3 endpoints. Remember all matching assertions are evaluated every time a profile is made. 

Ready for that challenge?

We need to create a .blackfire.yaml file at the root of your application. Note the command blackfire client:bootstrap-tests can do that for you. We also have an online validator to help you craft your test files: https://blackfire.io/validatorLet’s add one entry for each endpoint in the tests section of the .blackfire.yaml file. Note you could do the same for your CLI scripts as well.

  "homepage boilerplate test":
	path: "/"
 	    - # insert boilerplate assertions here
	description: |
  	    TODO: improve those default assertions

  "product page boilerplate test":
	path: "/my-product"
 	    - # insert boilerplate assertions here
	description: |
  	    TODO: improve those default assertions

  "checkout page boilerplate test":
	path: "/checkout"
 	    - # insert boilerplate assertions here
	description: |
  	    TODO: improve those default assertions

This concludes the first part of this two-part series. In the next installment, we’ll delve into the nuts and bolts of defining a test boilerplate and see our options to secure the application’s critical user journeys.

By the end of this series, we hope you’ll be confident in your ability to turn observability data into action for better application performance, even for applications you are discovering.

Meanwhile, we would be thrilled to hear your stories about using Blackfire for the first time. We understand that every experience is unique, and we’re excited to know your take on these topics.

Don’t hesitate to join the conversation on Dev.to, Slack, Reddit, or Twitter. Share your thoughts, insights, or even questions – we’re all here to learn and grow together in our collective journey toward better application performance. 

Happy performance optimization!

Thomas di Luccio

Thomas is a Developer Relations Engineer at Platform.sh for Blackfire.io. He likes nothing more than understanding the users' needs and helping them find practical and empowering solutions. He’ll support you as a day-to-day user.