Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Performance] API Platform v3.0 is much slower than V2.6 by orders of magnitude #5236

Closed
gnito-org opened this issue Nov 27, 2022 · 9 comments

Comments

@gnito-org
Copy link

API Platform version(s) affected: 3.0.x

Description

Has anyone done performance testing on V3.0?

I'm getting truly worrying results.

I have a Symfony Command that creates and deletes an API resource in a loop that iterates 10 times. In other words, 10 POST and 10 DELETE API operations.

When run under V2.6, the command has a duration of +- 3.48 seconds, for an average of 0.348 seconds per iteration (one POST and one DELETE).

When run under V3.0, the command has a duration of +- 55.54 seconds, for an average of 5.55 seconds per iteration (one POST and one DELETE).

That is a huge performance difference.

I have a v2.6 branch of my app, and a v3.0 branch of the app, and here are the steps when running the tests:

  • checkout the v2.6 branch of the app
  • run composer update to install API Platform 2.6
  • run the test command (takes 3.48 seconds)
  • checkout the v3.0 branch of the app
  • run composer update to install API Platform 3.0
  • run the test command (takes 55.54 seconds)

Each time that composer update runs, it only says Upgrading api-platform/core (v2.6.8 => v3.0.5) and Downgrading api-platform/core (v3.0.5 => v2.6.8), and it removes and installs fig/link-util. No other packages are modified.

I've repeated this several times with exactly the same results. I've also reversed the order, running V3.0 first and then V2.6, with exactly the same results.

The database is exactly the same, the app is exactly the same, except for having StateProcessors and StateProviders instead of DataPersisters and DataProviders. The state processors and state providers contain the same code that was in the data persisters and data providers. The only other difference between the two branches of the app is the new ApiResource attribute format on the entities in the V3 branch.

The test command calls the same API endpoints with exactly the same parameters and data, and the state of the database is exactly the same.

In the current state I cannot run API Platform V3 in production. It will completely kill my app's performance.

@gnito-org
Copy link
Author

gnito-org commented Nov 27, 2022

As an additional test, I changed the API endpoint that is called in the Command.

In the previous test, the API endpoint uses a StateProcessor that decorates the built-in Doctrine processor, as per the documentation.

The API endpoint in the second test does not use a decorated state processor, and the resource has fewer resource (Doctrine) relations.

V2.6 results: duration 2.8 seconds, average 0.28 seconds per iteration.

V3.0 results: duration 6.0 seconds, average 0.6 seconds per iteration.

I've tried other endpoints as well, but this is the best performance I was able to get for V3.0.

As an aside, I discovered this performance issue when I noticed that the PHPUnit test suite was running much longer with V3.0 than what I was used to with V2.6.

@Aerendir
Copy link
Contributor

Just to say the obvious: may the problem be related to the generation of cache?

To exclude it, I would:

  1. Delete the cache folder in var
  2. Run the command the first time (to generate the cache)
  3. Run the command the cons time to actually get the measurement

I would not use the console cache:clear command, but physically delete the folder.

@gnito-org
Copy link
Author

I've run the command many times. It definitely is not caused by the cache.

@gnito-org
Copy link
Author

gnito-org commented Nov 27, 2022

Here are the Symfony Profiler Performance tab screenshots for both versions. This is for exactly the same API POST call to the same API endpoint with the same data fields and values.

Version 2.6

V2_6_POST

Version 3.0

V3_0_POST

@acirulis
Copy link
Contributor

Hi, please try following this comment/thread: #4975 (comment)

@soyuka
Copy link
Member

soyuka commented Nov 28, 2022

Hi, yes we did performances tests, on the last versions this is the diff 2.6 vs 3.0 for a READ operation:

https://blackfire.io/profiles/compare/6bec923c-521f-426c-b7f1-1ab2fb962b80/graph

The only PR we found that impacted the performances was #4999 then fixed by #5100.

What version are you exactly on? @acirulis wasn't that corrected?

Careful about the metadata cache, if you change between 2.6 and 3.0 definitely remove that directory or use clear:cache command.

@gnito-org
Copy link
Author

@acirulis Thank you, the cache config resolved the issue. Much appreciated. 🙏

@soyuka I have already supplied the version numbers.

V3.0 POST With Caching Config

V3_0_POST_CACHE

@gnito-org
Copy link
Author

FWIW, it is this cache setting that makes all the difference:

    api_platform.cache.metadata.resource_collection:
        parent: cache.system
        tags: [ cache.pool ]

@soyuka soyuka closed this as completed Nov 28, 2022
@soyuka
Copy link
Member

soyuka commented Nov 28, 2022

Following: #4975 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants