Hello,
At the time being I use OOP in a few of my PHP4 projects as it
takes more time to design and finish an application with this
method but in big projects I accept the overhead in favour of
easier maintenance and extensions in future.
To be able to decide better
I did a test to see how performance changes if you use OOP
methods with your PHP pages.
Let me insist that results of this test are valid for this specific
application and the OOP model I have used etc. But you may be
able to reach the result that a relatively good designed OOP
application should not have much performance drop in comparison
with a normal application which does the same thing with none
OOP methods.
For this test
I have developed two instances of a very simple login form. One with
normal MySQL codes inside the PHP page and the other with a
complete set of classes etc.
I have used the DAO model of Harry Fuecks from PHPPatterns
(http://phppatterns.com) website which is a very clear and
efficient DAO model.
I should appereciate Harry for his great work. After looking
into his work I have started looking very seriously into
patterns for my PHP applications.
By the way I have used PHP 4.3.6 and Apache 1.3.31 on a Windows
2000 Pro.
Here is the summary of two applications:
Login Page -> Authentication -(redirect to)-> main.php
1- Normal
Application |
index.php (login
form)
login.php (authentication form)
main.php (main internal empty page) |
2- OOP
Application |
index.php :
Login form : index.php using "Login Page" class
Authentication: index.php uses "Login Page" class
Main Page (empty): index.php uses "Main Page" class
-(Uses)-> "Login Page Class" extends "Page Class"
-(Uses)-> "User Class"
-(Uses)-> "UserDAO Class" extends "DAO Class"
-(Uses)-> "DataAccess Class"
-(uses)-> "DataAccessResult Class" |
Then I ran a
stress test on both of them with "Microsoft Application Center
Test". First time with 20 concurrent users (1 Minute) and second
time with 100 concurrent users (2 minutes).
Now
summary of results: |
20 Users:
Normal: 54.58 AVG Requests, 0 Errors
OOP : 41.75 AVG Requests, 0 Errors
---
23.5% Performance Reduction |
100 Users:
Normal: 62.42 AVG Requests, 1995 errors
OOP : 41.81 AVG Requests, 149 errors
---
33% Performance Reduction |
By the way I make no assumptions about the errors as it
is hard to tell the real cause of them.
Anyway for me 23% to 33% performance reduction is OK for
most of applications (except applications like banner
rotation etc which have a very high hit).
Now I think I will use the OOP models in more projects.
Please feel free to discuss the results in forums or
contact me about them at : mac--at--htmsoft.com
Siamak Sarmady
HtmSoft.com
Please look at detailed test results below:
Detailed
test results: (20 users, 1 Minute) |
A1: Normal App ,
20 Users, 1 Minute
Properties
Test type: Dynamic
Simultaneous browser connections: 20
Warm up time (secs): 5
Test duration: 00:00:01:00
Test iterations: 472
Summary
Total number of requests: 3,275
Total number of connections: 3,270
Average requests per second: 54.58
Average time to first byte (msecs): 348.06
Average time to last byte (msecs): 349.79
Average time to last byte per iteration (msecs):
2,427.04
Number of unique requests made in test: 5
Errors Counts
HTTP: 0
DNS: 0
Socket: 0
Additional Network Statistics
Number of connection errors: 0
Number of send errors: 0
Number of receive errors: 0
Number of timeout errors: 0
|
A2: OOP App , 20
Users, 1 Minute
Properties
Test type: Dynamic
Simultaneous browser connections: 20
Warm up time (secs): 5
Test duration: 00:00:01:00
Test iterations: 313
Detailed test results generated: Yes
Summary
Total number of requests: 2,505
Total number of connections: 2,505
Average requests per second: 41.75
Average time to first byte (msecs): 297.56
Average time to last byte (msecs): 298.14
Average time to last byte per iteration (msecs):
2,386.08
Number of unique requests made in test: 6
Errors Counts
HTTP: 0
DNS: 0
Socket: 0
Additional Network Statistics
Number of connection errors: 0
Number of send errors: 0
Number of receive errors: 0
Number of timeout errors: 0
|
Now with 100 users , 2
Minutes of test:
Detailed
test results: (100 users, 2 Minute) |
B1: Normal App ,
100 Users, 2 Minute
Properties
Test type: Dynamic
Simultaneous browser connections: 100
Warm up time (secs): 5
Test duration: 00:00:02:00
Test iterations: 1,365
Detailed test results generated: Yes
Summary
Total number of requests: 7,490
Total number of connections: 9,485
Average requests per second: 62.42
Average time to first byte (msecs): 1,177.83
Average time to last byte (msecs): 1,178.51
Average time to last byte per iteration (msecs):
6,466.71
Number of unique requests made in test: 5
Errors Counts
HTTP: 0
DNS: 0
Socket: 1,995
Additional Network Statistics
Number of connection errors: 0
Number of send errors: 0
Number of receive errors: 1,995
Number of timeout errors: 0
|
B2: OOP App , 100
Users, 2 Minute
Properties
Test type: Dynamic
Simultaneous browser connections: 100
Warm up time (secs): 5
Test duration: 00:00:02:00
Test iterations: 632
Detailed test results generated: Yes
Summary
Total number of requests: 5,017
Total number of connections: 5,149
Average requests per second: 41.81
Average time to first byte (msecs): 2,259.91
Average time to last byte (msecs): 2,275.04
Average time to last byte per iteration (msecs):
18,059.91
Number of unique requests made in test: 6
Errors Counts
HTTP: 0
DNS: 0
Socket: 149
Additional Network Statistics
Number of connection errors: 0
Number of send errors: 16
Number of receive errors: 133
Number of timeout errors: 0
|
Please feel free to discuss
the article in forums:
http://op.htmsoft.com/forums
|