Giter Site home page Giter Site logo

sergeyklay / php-orm-benchmark Goto Github PK

View Code? Open in Web Editor NEW
81.0 7.0 7.0 272 KB

The benchmark to compare performance of PHP ORM solutions.

License: MIT License

PHP 67.01% Shell 0.34% Dockerfile 0.57% TSQL 32.08%
php7 orm benchmark orm-framework phalcon benchmarking eloquent propel cakephp doctrine

php-orm-benchmark's Introduction

PHP ORM Benchmark Build Status

The benchmark to compare performance of PHP ORM solutions.

Initially this project used Docker to facilitate PHP ORM benchmarks. But after repeated comments we added support to benchmarksing on Travis CI. So everyone can see the results or run them again. Actually I've enabled the daily cron job on Travis CI.

We have noticed, that running benchmarks on Travis CI is a convenient, but not a very precise way to measure the code execution speed. The main reason for that is that Travis was designed to run tests. It shares resources between all re running builds and it means, that Travis cares about build execution, but it doesn't care about the performance, so benchmark results may vary from run to run. We will manually check results before publishing them to make sure they are not seriously affected by random performance of Travis, but you also can run the benchmark yourself using Docker.

ORMs to Benchmark

  • CakePHP ORM 3.5.10
  • Doctrine ORM 2.5.14
  • Eloquent 5.5.28
  • PHP ActiveRecord 1.2.0
  • Phalcon 3.3.1
  • Propel ORM 2.0.0-alpha7
  • Yii ActiveRecord 2.0.13.1
  • DMS 0.8.2
  • Nextras ORM 3.0.0-rc2

What we test

  • Insert a record to the Database
  • Get first record with relation
  • Get first record with relation and metadata caching
  • Insert a record to the Database (10-fold method call)
  • Get first record with relation (10-fold method call)
  • Get first record with relation and metadata caching (10-fold method call)
  • Get a batch of first 20 records with relation
  • Get a batch of first 20 records with relation and metadata caching
  • Get a batch of first 200 records with relation
  • Get a batch of first 200 records with relation and metadata caching

Travis CI Benchmarking Environment

  • Ubuntu 14.04.5 (Trusty) 64bit
  • PHP 7.0, 7.1, 7.2, 7.3
  • Zend OPcache 7.0, 7.1, 7.2, 7.3
  • MySQL 5.6

Getting Started

Requirements

  • Linux, macOS or BDS System
  • Docker CE/EE >= 17.09.0
  • Docker Compose >= 1.17
  • PHP >= 7.0
  • Composer

Build local image

First you have to build the benchmark application. Go to project root and run command as follows:

git clone [email protected]:sergeyklay/php-orm-benchmark.git
cd php-orm-benchmark
docker-compose build --force-rm --no-cache

We advise you to rely on Composer to manage projects’ dependencies. You have to download and install Composer itself in a common location or in project root by executing in a terminal the command like this:

wget http://getcomposer.org/composer.phar
# If you haven't wget on your computer
curl -s http://getcomposer.org/installer | php

Then, to install all project's dependencies, type the following from the project root:

php composer.phar install

Each ORM provider has its own dependencies. So you have to install them:

NOTE: If you have local composer.phar installed you'll need to replace composer install by php ../../composer.phar install

cd provider
for provider in `ls`; do echo $provider; cd $provider; composer install; cd ..; done

NOTE: You may skip Phalcon by running php composer.phar install --ignore-platform-reqs, if you don't have it installed at host system.

Finally, start the benchmark application:

docker-compose run benchmark

Running Benchmark

To run benchmark simple run command as follows:

php run <provider> <test>

Available providers are:

  • phalcon
  • propel
  • eloquent
  • cake
  • yii
  • doctrine
  • activerecord
  • dms
  • nextrasorm

Available tests are:

  • create
  • read

To run benchmark multiple times use:

php run <provider> <test> <times>

Some ORMs rely (depends) on models metadata caching. Thus, to avoid controversy there is an ability to create and run test with metadata caching support. To use models metadata caching (if supports) you can use the 4th command line argument as follows:

php run <provider> <test> <times> 1

Uninstall PHP ORM Benchmark

To destroy the application use the following command from the host system:

docker-compose down
docker volume rm phpormbenchmark_mysql

rm -rf <path_to_cloned_project>

Results

Get first record with relation (10-fold method call). Build #57, PHP 7.0.25.

ORM Elapsed time (ms) Used memory (KiB) Total memory usage (KiB) Method
CakePHP 7.68 98.06 1,610,421.10 find
DMS 7.42 199.06 2,503,541.10 get
Doctrine 4.29 83.99 2,179,349.09 findOneBy
Eloquent 3.24 55.27 1,526,709.09 firstOrFail
Propel 3.57 66.83 1,458,557.10 findPk
Yii 3.20 43.90 1,394,253.10 findOne
Phalcon 1.07 16.10 622,013.10 findFirst
PHP ActiveRecord 0.99 6.18 775,661.09 first

Get first record with relation (10-fold method call) with metadata caching. Build #57, PHP 7.0.25.

ORM Elapsed time (ms) Used memory (KiB) Total memory usage (KiB) Method
CakePHP 5.82 84.56 1,383,373.10 find
Yii 2.55 41.84 1,373,901.07 findOne
Doctrine 2.21 30.31 1,844,677.05 findOneBy
Phalcon 1.04 16.25 611,445.07 findFirst

Get a batch of 200 records with relation. # TBD

Get a batch of 200 records with relation and with metadata caching. # TBD

If you are interested in other resutls, see Travis CI build results.

Contributing

Contributions for new ORMs are more than welcome! If anyone feels that there is something missing or would like to suggest improvements please open a new issue or send a pull request.

References

License

The "PHP ORM Benchmark" is open source software licensed under the MIT License. See the LICENSE file for more.


Copyright © 2018 Serghei Iakovlev

php-orm-benchmark's People

Contributors

beberlei avatar dereuromark avatar harikt avatar jabirchall avatar sergeyklay avatar silverfire avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-orm-benchmark's Issues

Split providers to its own folder

Hi,

Have you thought of splitting the providers to its own folder and having an independent composer.json file ?

Else I wonder whether the memory consumption of different components by composer autoload have some effect.

Amend tests

Select 500 employees from the Employees database, for each of them show all of their salaries and all the departments they belong to.

Lack of Metadata caches for CakePHP and Doctrine

The CakePHP and Doctrine ORMs both recommend that metadata caching be enabled to get better performance in production environments. I noticed that these benchmarks do not enable metadata caching. Would you be open to a pull request adding metadata caching for these ORMs?

$this->read(1) triggers identity map of Doctrine (and others?)

The read scenario always gets entity by id 1, which leads to triggering identity map, and these fast results compared to phalcon:

root@82c267f32816:/app# php run doctrine read 1000
Start Doctrine benchmarking...

Method:                           read
Call times:                       1000
Elapsed time:                     0.23 ms.
Memory usage:                     1.31 KiB.
Memory peak:                  2,318.59 KiB.

Total elapsed time:             245.17 ms.
Total memory usage:       2,028,436.57 KiB.
Total memory peak:            4,096.00 KiB.

root@82c267f32816:/app# php run phalcon read 1000
Start Phalcon benchmarking...

Method:                           read
Call times:                       1000
Elapsed time:                     0.76 ms.
Memory usage:                     0.07 KiB.
Memory peak:                    856.21 KiB.

Total elapsed time:             772.19 ms.
Total memory usage:         754,452.58 KiB.
Total memory peak:            2,048.00 KiB.

I would assume other ORMs also have identity maps, not mamking the query another time, which makes the read benchmarks not comparable.

It can't be changed to $i+1 though, because only id 1 has the fixture data with the comments available.

IN addition compared to my numbers, your seems way too extreme. Why kind of base system do you have for docker? I honestly wouldnt trust any numbers coming out of a docker dev environment.

Add Metrics about database

Normally the issue on big project is the scalping of the database not as much the frontal server where php executed.

What would be interesting (minimally) is the amount of queries made when the orm is properly configure. Mean if I have a relation on another table does it do a join or a extra queries ? If I am reloading a the same entity again by primary key does it load it from a pool of instances (context cache) or hitting the database again ? Etc.

Using blackfire would help.

Cleanup docker image

New docker images already have this logic:

echo exit 101 > /usr/sbin/policy-rc.d
chmod +x /usr/sbin/policy-rc.d
echo "force-unsafe-io" > /etc/dpkg/dpkg.cfg.d/02apt-speedup
echo "Acquire::http {No-Cache=True;};" > /etc/apt/apt.conf.d/no-cache 

Testing : using localhost not docker

Hi,

I am not using docker.

Just testing on the localhost with the changes made to configuration file.

Running

./run activerecord create
./run cake create
./run doctrine create
./run eloquent create
./run eloquent create

Every tests shows results. But only the ./run doctrine create is inserting record to the database.

The assert() doesn't do anything if there is no handler. So may be need to improve the tests?

Did you verified the data is being inserted ?

I agree the benchmark.ini settings are not considered.

Add more than 1 comment to each post

There is a common use case: fetch N posts with their comments.
It will be nice to update MySQL dump and code to test this scenario in read bench

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.