Cache and Eager Loading for Laravel framework [Benchmark of php frameworks v0.0.5]
In Release 0.0.5 :
Add new tests for laravel:
- Use Cache for load posts from DB in 'posts' most heavy page. But it doesn`t solve the problem
- Use Eager Loading for load posts from DB in 'posts'. It is very fast.
More informations about changes.
This release is the next step in my road-map. As you remember, I planned to add query caching to reduce the loading time of the 'posts' page. I decide to start with Laravel framework.
I was very surprised by the results of the tests after adding caching. Time of generation was the same.
I began to dig deeper and found out that in addition to a large amount of data, there is still multiple access to the database for obtaining related data. For each entity from 3 to 10 queries.
- $post->author->name
- $post->postType->name
- $post->categories : $category->name
For our 1000 records, we get about 10,000 requests.
So we need to see what the results will be when using Eager Loading.
And what will the results be if we use the Cache + Eager Loading.
framework | requests per second | relative | peak memory | relative |
---|---|---|---|---|
laravel-index | 9.93 | 248.3 | 6.21 | 14.2 |
laravel-posts-eager_load-cache | 9.10 | 227.5 | 7.37 | 16.9 |
laravel-posts-eager_load | 8.02 | 200.5 | 7.36 | 16.9 |
laravel-authors | 7.20 | 180.0 | 7.34 | 16.8 |
laravel-categories | 6.80 | 170.0 | 7.51 | 17.2 |
laravel-posts | 0.04 | 1.0 | 15.13 | 34.7 |
laravel-posts-cache | 0.04 | 1.0 | 18.46 | 42.3 |
As we can see in the case of laravel-posts
and laravel-posts-cache
, only the peak memory has increased.
But if we use Eager Loading (laravel-posts-eager_load-cache
and laravel-posts-eager_load
in table) then the peak memory
is lower and requests per second
is a lot more
http://php-frameworks.semasping.info/bm/result-releases/0.0.5/
Roadmap:
- Try to use Cache for all frameworks (Done for laravel. Next step: Cache for Phalcon)
- Implementing a test application and running tests on Symfony
- Implementing a test application and running tests on Yii
- Connection with https://blackfire.io/
- Deal with the Docker and wrap it all up in it. To be able to quickly deploy to a more powerful server for comparison.
PS: More information about structure of test application
Part 1. Introduction. - Why i decide to do new bencmark of php frameworks.
Part 2. Database scheme and generating data for testing app. - Description of application, database structure and data.
Posted on Utopian.io - Rewarding Open Source Contributors
@originalworks
The @OriginalWorks bot has determined this post by @semasping to be original material and upvoted it!
To call @OriginalWorks, simply reply to any post with @originalworks or !originalworks in your message!
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Дрyзья, а дaвaйте в поддeржкy вырaзим дружнo наше отношение к этому пoсту...
круто
✔️
great article
поддержал
Cool! Upvote
👍
good article
Ап
отличный пост дружище
cool
@originalworks
Поддержала!