PersistenceObjects for php

Performancetests

Introduction:

I was curious over how managed PersistenceObjects perform compared to traditional dedicated managers. Or should I say I wanted too see how slow they were. So I created these tests.

The tests use SimpleTest to wrap the functionality and Graphpite to visualize the results. Green lines represent PersistenceObjects and red lines represent dedicated managers.

The tests are run on a:
Intel Core 2 duo 6600 @ 2.40GHz
3,12GB ram
ApacheFriends XAMPP (basic package) version 1.6.2
+ Apache 2.2.4
+ MySQL 5.0.41
+ PHP 5.2.2
PersistenceObjects version 0.8.1

Each test sends one request to the server for each cycle of the test. So for example the create test sends 50 "create a user-tree" requests asynchronously to the server. The collected runtimes are gathered by the server and they represent only the time the execution of a single request. Thus, network-lag does not affect the results.

The classdiagram of the entities used in the test is a real-life example:

Create

Create one User, no connected objects

The first test creates a 10 User-entities per request. The entities have connected objects but they are set to null.

managers
total: 0.2156262397599999
avg: 0.002156262397599999
(in microseconds)

persistenceObjectsCreate
total: 0.3999671935499998
avg: 0.003999671935499998
(in microseconds)

Create one User with several connected objects

The test creates a single User-entity with 10 albums which each has 10 pictures. So a single request creates 1 + 10 + 100 = 111 entities in the database.

managersCreate
total: 4.734376430200001
avg: 0.09468752860400002
(in microseconds)

persistenceObjectsCreate
total: 8.260511159999998
avg: 0.16521022319999998
(in microseconds)

Read

Read one User, no connected objects

The test reads a 10 User-entities. The entities have connected objects but they are set to null.

managersRead
total: 0.17367172237
avg: 0.0017367172237
(in microseconds)

persistenceObjectsRead
total: 0.2613704204399999
avg: 0.002613704204399999
(in microseconds)

Read one User with several connected objects

The test reads a single User-entity with 10 albums which each has 10 pictures. So a single request reads 1 + 10 + 100 = 111 entities from the database.

managersRead
total: 4.1491885182
avg: 0.082983770364
(in microseconds)

persistenceObjectsRead
total: 5.58118248
avg: 0.1116236496
(in microseconds)

Update

Update one User, no connected objects

The test updates a 10 User-entities' values. The entities have connected objects but they are set to null.

managersUpdate
total: 0.24379992480999998
avg: 0.0024379992481
(in microseconds)

persistenceObjectsUpdate
total: 0.3572223186300001
avg: 0.003572223186300001
(in microseconds)

Update one User and all its connected objects

The test updates a single User-entity with 10 albums which each has 10 pictures. Each entity's values are edited. So a single request updates 1 + 10 + 100 = 111 entities in the database.

managersUpdate
total: 10.428173063999997
avg: 0.20856346127999995
(in microseconds)

persistenceObjectsUpdate
total: 8.415381676
avg: 0.16830763352000003
(in microseconds)

Edit connections

Add an album's pictures to User's favouritesAlbum

The test adds a single album's pictures to User-entity's favouritesAlbum. The test creates no objects but adds 10 connections to connections-table.

managersEditConnections
total: 4.329427242200002
avg: 0.08658854484400004
(in microseconds)

persistenceObjectsEditConnections
total: 9.261114836000003
avg: 0.18522229672000004
(in microseconds)

Delete

Delete one User, no connected objects

The test deletes a 10 User-entities. The entities have connected objects but they are set to null.

managersDelete
total: 0.3826799392700001
avg: 0.003826799392700001
(in microseconds)

persistenceObjectsDelete
total: 0.33228659633999985
avg: 0.0033228659633999986
(in microseconds)

Delete one User and all its connected objects

The test deletes a single User-entity with 10 albums which each has 10 pictures. every entity is deleted. So a single request deletes 1 + 10 + 100 = 111 entities from the database.

managersDelete
total: 8.149089337000001
avg: 0.16298178674000002
(in microseconds)

persistenceObjectsDelete
total: 5.982427596999999
avg: 0.11964855193999999
(in microseconds)

There's a few cases where PersistenceObjects were faster than dedicated managers (Update one User and all its connected objects, Delete). This can be explained by the cache-feature that PersistenceObjects use. If managers were also to use a cache, they would win these cases too.

As expected, PersistenceObjects are slower then dedicated managers. This will always be true, because dedicated managers can always be optimised more accurately than generalized PersistenceObjects. But why use PersistenceObjects then? Simply because of the development time. Creating dedicated managers for each entity is ALWAYS slower than you'd expect. When starting a project the focus should be given to the application's features rather than database management. Therefore it might be wise to use PersistenceObjects as long as they are needed and finally when it's time to optimise, switch to dedicated managers.