APC and Web Application Performance, take 2
After encountering a few issues while implementing APC into my framework which uses PDO in its ORM system, I have managed to overcome these issues and successfully cache result sets. Previous issues were outlined in the article ‘APC and Web Application Performance‘
The issues arose when attempting to save an object of the type PDOStatement into the cache; which clearly you cannot do. The actual issue there which was graciously pointed out by a commenter was that serialize(), which apc_store() uses internally, cannot serialize system objects. Clearly this was the issue there, but it made me re-think the way I was attempting to cache and I realised that I was actually trying to cache the wrong thing.
My custom ORM returns objects all of which have a number of methods implemented in them to manipulate and handle data on each row, and the actual result columns are present as variables local to the object. Each row is returned as an object from PDO using $pdo->fetchObject(get_class($this)). When the result set is built, the array of objects (rows) is saved into the cache. Each object however did have a (redundant) connection to the PDO object remaining at this point, however because the object was populated with data the connection was no-longer needed on that object, so it was set to NULL.
I’ve changed from the previous (digg/slashdot effect emulating) ab2 benchmark test to a simpler test of 1000 requests:
# ab2 -n1000 http://devwww.(hidden).net/user/1
Test 1, with APC disabled and no query caching or op-code caching:
# ab2 -n1000 http://devwww.(hidden).net/user/1
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
Benchmarking devwww.(hidden).net (be patient)
Server Software: Apache
Server Hostname: devwww.(hidden).net
Server Port: 80
Document Path: /user/1/
Document Length: 16409 bytes
Concurrency Level: 1
Time taken for tests: 32.473304 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 16764000 bytes
HTML transferred: 16409000 bytes
Requests per second: 30.79 [#/sec] (mean)
Time per request: 32.473 [ms] (mean)
Time per request: 32.473 [ms] (mean, across all concurrent requests)
Transfer rate: 504.14 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 28 31 9.5 29 152
Waiting: 18 18 2.8 18 101
Total: 28 31 9.5 29 152
Percentage of the requests served within a certain time (ms)
50% 29
66% 30
75% 30
80% 30
90% 35
95% 41
98% 75
99% 81
100% 152 (longest request)
Test 2, with APC Query Caching and op-code caching:
# ab2 -n1000 http://devwww.(hidden).net/user/1
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
Benchmarking devwww.(hidden).net (be patient)
Server Software: Apache
Server Hostname: devwww.(hidden).net
Server Port: 80
Document Path: /user/1/
Document Length: 16609 bytes
Concurrency Level: 1
Time taken for tests: 22.166954 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 16964000 bytes
HTML transferred: 16609000 bytes
Requests per second: 45.11 [#/sec] (mean)
Time per request: 22.167 [ms] (mean)
Time per request: 22.167 [ms] (mean, across all concurrent requests)
Transfer rate: 747.33 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 18 21 4.4 22 58
Waiting: 13 13 0.6 13 26
Total: 18 21 4.4 22 58
Percentage of the requests served within a certain time (ms)
50% 22
66% 22
75% 22
80% 22
90% 24
95% 28
98% 37
99% 45
100% 58 (longest request)
Wow! From 32 seconds for 1000 requests with no query cache or op-code cache, down to 22 seconds with APC query cache and op-code cache enabled!
I’m incredibly happy with these results, but I feel there is still some more speed to come ![]()
Comments
Comment from Guru
Date: September 21, 2007, 6:36 pm
man it took you that long to do that, give me a yell and ill come over and help you if i must.
Comment from Sohbet
Date: September 21, 2007, 6:01 pm
good work. Thanks