---
# System prepended metadata

title: Approaches for the Tests

---


> [TOC]

Guys, I would like to share with you some metrics that I took from Blackfire using our production environment.

# Approaches for the Tests

- I used ECS tasks to replicate the same infrastructure environment, by creating specific tasks with php  specific image tag.
- Blackfire credentials have been fixed in ParamStore, so all new tasks will be configured for our current account - *Thanks, Igor*.
- For each scenario I ran the blackfire curl with 10 samples for each request, to get an average of the metrics.
- I created 4 scenarios to generate the metrics, each scenario was generated 4 sub-scenarios (API with different filters).
- Each scenario is pointed to a version of the code with some changes I made:

1. PHP 7.4.
1. PHP 8 with JIT disabled by default.
1. PHP 8 with JIT enabled.
1. PHP 8 with JIT enabled and implemented `CacheableSupportsMethodInterface` for the serializers. - *Thanks Matheus.*

- All reports are available on blackfire.
- All tests were run inside the private network.
- I ran the tests looking for invoices for a large TaxPayer and with different `issuedAt` filters (to test the behavior of the database).

> [TOC]

---


# Tests

### PHP 7.4

In this scenario I simulated requests with using our `main` branch, without any changes, just in a separate task with blackfire enabled.

-- Calling Invoice enpoint


|      Filters      |    Value     |
|:-----------------:|:------------:|
|  `itemsPerPage`   |    `1000`    |
| `issuedAt[after]` | `2021-09-01` |
| `order[issuedAt]` |    `DESC`    |



| Report                                                                   |
|:------------------------------------------------------------------------ |
| https://blackfire.io/profiles/9cc9ba6d-755a-4894-8644-543e20315b8e/graph |
| https://blackfire.io/profiles/8def3110-1816-472a-aca9-e0f932cd19be/graph |

|      Filters      |    Value     |
|:-----------------:|:------------:|
|  `itemsPerPage`   |    `1000`    |
| `issuedAt[after]` | `2021-09-01` |
| `order[issuedAt]` |    `ASC`     |



| Report                                                                   |
|:------------------------------------------------------------------------ |
| https://blackfire.io/profiles/2b068d33-164d-4bf8-a490-a16fcd45f7b4/graph |
| https://blackfire.io/profiles/07de3203-7e9d-4ba4-962c-49b97808425b/graph |


### PHP 8.0 Without JIT
[Commit](https://github.com/satws/scarface/pull/876/commits/92b937684a16f045523660354cc8a4edbf2fe099)

|      Filters      |    Value     |
|:-----------------:|:------------:|
|  `itemsPerPage`   |    `1000`    |
| `issuedAt[after]` | `2021-09-01` |
| `order[issuedAt]` |    `DESC`    |



| Report                                                                   |
|:------------------------------------------------------------------------ |
| https://blackfire.io/profiles/0d5f314a-da61-412a-8519-a16875ba7aa7/graph |
| https://blackfire.io/profiles/899e043d-8436-4e59-81d8-820337c6a71e/graph |

|      Filters      |    Value     |
|:-----------------:|:------------:|
|  `itemsPerPage`   |    `1000`    |
| `issuedAt[after]` | `2021-09-01` |
| `order[issuedAt]` |    `ASC`     |



| Report                                                                   |
|:------------------------------------------------------------------------ |
| https://blackfire.io/profiles/00225235-567b-4dd5-9a08-a6955e629463/graph |
| https://blackfire.io/profiles/b88f9bc0-01a9-4c73-bfb1-b46cb6b0208f/graph |

### PHP 8.0 With JIT
[Commit](https://github.com/satws/scarface/pull/876/commits/8172e874cb0de8e0a4054d601eaedcc08585aa56)

|      Filters      |    Value     |
|:-----------------:|:------------:|
|  `itemsPerPage`   |    `1000`    |
| `issuedAt[after]` | `2021-09-01` |
| `order[issuedAt]` |    `DESC`    |



| Report                                                                   |
|:------------------------------------------------------------------------ |
| https://blackfire.io/profiles/5b8e5c15-ea19-422d-9862-0723aa3b3eac/graph |
| https://blackfire.io/profiles/c59ab3cf-a9d2-47f2-8567-dabb8fdf9045/graph |

|      Filters      |    Value     |
|:-----------------:|:------------:|
|  `itemsPerPage`   |    `1000`    |
| `issuedAt[after]` | `2021-09-01` |
| `order[issuedAt]` |    `ASC`     |



| Report                                                                   |
|:------------------------------------------------------------------------ |
| https://blackfire.io/profiles/dddc63c2-7aaa-439f-af3a-dc2488d6db7a/graph |
| https://blackfire.io/profiles/61a6cb47-da83-4cd9-9ddd-a6ed80a059aa/graph |

### PHP 8.0 With JIT and Serializer Cache
[Commit](https://github.com/satws/scarface/pull/876/commits/a8250ccb84371cd7f45657b4b19ec12fa80ebe20)

|      Filters      |    Value     |
|:-----------------:|:------------:|
|  `itemsPerPage`   |    `1000`    |
| `issuedAt[after]` | `2021-09-01` |
| `order[issuedAt]` |    `DESC`    |



| Report                                                                   |
|:------------------------------------------------------------------------ |
| https://blackfire.io/profiles/d19efd5c-23a0-4672-9d50-8ab77fcbedc9/graph |
| https://blackfire.io/profiles/2f56df19-b850-41a7-accc-2058ee2b884b/graph |

|      Filters      |    Value     |
|:-----------------:|:------------:|
|  `itemsPerPage`   |    `1000`    |
| `issuedAt[after]` | `2021-09-01` |
| `order[issuedAt]` |    `ASC`     |



| Report                                                                   |
|:------------------------------------------------------------------------ |
| https://blackfire.io/profiles/f71850f2-b4c7-4046-bd52-90d3cc77874b/graph |
| https://blackfire.io/profiles/40f57219-d4bf-4536-bb56-a86e9fb1aa5d/graph |

## My considerations

- There was a noticeable performance improvement between version 7.4 and PHP 8

![](https://i.imgur.com/DjpUPPR.png)


- I believe PHP 8 and JIT will improve the performance of our extractors much more.
- I noticed that regardless of the scenario, the database queries always maintained a response time pattern, indicating that the problem is probably the code architecture.

![](https://i.imgur.com/SQspaV1.png)
>[Report](https://blackfire.io/profiles/compare/07de3203-7e9d-4ba4-962c-49b97808425b...61a6cb47-da83-4cd9-9ddd-a6ed80a059aa/graph?settings%5Bdimension%5D=cpu&settings%5Bdisplay%5D=landscape&settings%5BtabPane%5D=sql.queries&selected=&callname=main()&constraintDoc=)


- I realized that 80% of the processing time is due to serializers, as some are executed almost 200 thousand times per request.

![](https://i.imgur.com/hD7YvjO.png)

- I noticed that the bigger Bottleneck is due to CPU processing time, maybe due to serializers?

![](https://i.imgur.com/kZLG1CT.png)

- Memory, I/O or database doesn't seem to be hurting code performance.

I created these tests and reports just to get an overview of the possible improvement. This report does not influence the decision to update PHP, as it will already be something we will do.

Furthermore, these reports can help us to detect possible bottlenecks in the API, helping us to improve the code and the processing time of the API.

> [name=Carlos Eduardo Oliveira] 
> [time=Wed, Jan 26, 2022 5:59 PM]