Putting ImageCache External in front of an image can significantly reduce the load time of images which are associated with CiviCRM. In this test, the time to serve the image ranged from 777ms - 7s when served via CiviCRM, and from 4 - 38ms when adding ImageCache External.
Inspired by questions in How to use Drupal image styles with a civicrm custom field (type file)
CiviCRM should be expected to introduce delay - it has to initialise the CiviCRM application and run DB queries to obtain the image and check permissions, which is what CiviCRM should be doing.
For use where performance is a factor (eg public views on CiviCRM.org which show community contributor headshots and partner logos), you might opt to improve response times by caching the results.
In doing so, should take time to consider whether this will permit visitors to bypass CiviCRM's access constraints on other data in your CRM.
- This test ignores the taken to handle the initial ImageCache external request - there is a slight delay when this occurs as we do need to retrieve the image at least once from CiviCRM.
- Test environment is a dev server ... please make your own measurements rather than trusting my numbers.
- My imagecache filter was configured to no changes, but ImageCache reduced the image filesize anyway. I attached the output of the imagecache image to the civicrm contact. There was still a slight filesize reduction on the second round, 7518 vs 7513 bytes.
- If you're testing this yourself, make sure to double-check the "Document size" value in each set of results :)
My main takeaway from this is: sure, cache images to bypass the CRM ... but should CiviCRM handle simultaneous requests better? Because that's a huge dropoff once things get concurrent.
Mean request time: 790ms
$ ab -n 50 "https://example.org/civicrm/contact/imagefile?photo=imagecache_37781e6ec746851a5363e5f374967b5c.jpg"
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking example.org (be patient).....done
Server Software: nginx/1.6.2
Server Hostname: example.org
Server Port: 443
SSL/TLS Protocol: TLSv1/SSLv3,ECDHE-RSA-AES256-GCM-SHA384,2048,256
Document Path: /civicrm/contact/imagefile?photo=imagecache_37781e6ec746851a5363e5f374967b5c.jpg
Document Length: 7518 bytes
Concurrency Level: 1
Time taken for tests: 39.548 seconds
Complete requests: 50
Failed requests: 0
Write errors: 0
Total transferred: 398950 bytes
HTML transferred: 375900 bytes
Requests per second: 1.26 [#/sec] (mean)
Time per request: 790.953 [ms] (mean)
Time per request: 790.953 [ms] (mean, across all concurrent requests)
Transfer rate: 9.85 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 4 4 0.2 4 5
Processing: 777 787 7.9 786 808
Waiting: 777 787 7.9 786 808
Total: 781 791 7.9 790 813
Percentage of the requests served within a certain time (ms)
50% 790
66% 793
75% 794
80% 796
90% 803
95% 812
98% 813
99% 813
100% 813 (longest request)
Mean request time: 4379ms
$ ab -n 50 -c 10 "https://example.org/civicrm/contact/imagefile?photo=imagecache_37781e6ec746851a5363e5f374967b5c.jpg"
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking example.org (be patient).....done
Server Software: nginx/1.6.2
Server Hostname: example.org
Server Port: 443
SSL/TLS Protocol: TLSv1/SSLv3,ECDHE-RSA-AES256-GCM-SHA384,2048,256
Document Path: /civicrm/contact/imagefile?photo=imagecache_37781e6ec746851a5363e5f374967b5c.jpg
Document Length: 7518 bytes
Concurrency Level: 10
Time taken for tests: 21.897 seconds
Complete requests: 50
Failed requests: 0
Write errors: 0
Total transferred: 398950 bytes
HTML transferred: 375900 bytes
Requests per second: 2.28 [#/sec] (mean)
Time per request: 4379.308 [ms] (mean)
Time per request: 437.931 [ms] (mean, across all concurrent requests)
Transfer rate: 17.79 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 4 9 10.7 4 46
Processing: 1260 4192 1155.4 4336 7063
Waiting: 1260 4192 1155.4 4335 7063
Total: 1290 4201 1152.7 4340 7068
Percentage of the requests served within a certain time (ms)
50% 4340
66% 4506
75% 4729
80% 5003
90% 5727
95% 6041
98% 7068
99% 7068
100% 7068 (longest request)
Mean request time: 4ms
$ ab -n 50 "https://example.org/sites/example.org/files/styles/no_change/public/externals/0f2f5c0edd0d93016da0c1a365c97d34.jpg?itok=jWrn_2zQL"
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking example.org (be patient).....done
Server Software: nginx/1.6.2
Server Hostname: example.org
Server Port: 443
SSL/TLS Protocol: TLSv1/SSLv3,ECDHE-RSA-AES256-GCM-SHA384,2048,256
Document Path: /sites/example.org/files/styles/no_change/public/externals/0f2f5c0edd0d93016da0c1a365c97d34.jpg?itok=jWrn_2zQL
Document Length: 7513 bytes
Concurrency Level: 1
Time taken for tests: 0.227 seconds
Complete requests: 50
Failed requests: 0
Write errors: 0
Total transferred: 387400 bytes
HTML transferred: 375650 bytes
Requests per second: 220.74 [#/sec] (mean)
Time per request: 4.530 [ms] (mean)
Time per request: 4.530 [ms] (mean, across all concurrent requests)
Transfer rate: 1670.19 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 4 4 0.3 4 5
Processing: 0 0 0.0 0 0
Waiting: 0 0 0.0 0 0
Total: 4 4 0.3 4 6
Percentage of the requests served within a certain time (ms)
50% 4
66% 4
75% 4
80% 5
90% 5
95% 5
98% 6
99% 6
100% 6 (longest request)
Mean request time: 33ms
$ ab -n 50 -c 10 "https://example.org/sites/example.org/files/styles/no_change/public/externals/0f2f5c0edd0d93016da0c1a365c97d34.jpg?itok=jWrn_2zQL"
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking example.org (be patient).....done
Server Software: nginx/1.6.2
Server Hostname: example.org
Server Port: 443
SSL/TLS Protocol: TLSv1/SSLv3,ECDHE-RSA-AES256-GCM-SHA384,2048,256
Document Path: /sites/example.org/files/styles/no_change/public/externals/0f2f5c0edd0d93016da0c1a365c97d34.jpg?itok=jWrn_2zQL
Document Length: 7513 bytes
Concurrency Level: 10
Time taken for tests: 0.168 seconds
Complete requests: 50
Failed requests: 0
Write errors: 0
Total transferred: 387400 bytes
HTML transferred: 375650 bytes
Requests per second: 297.98 [#/sec] (mean)
Time per request: 33.559 [ms] (mean)
Time per request: 3.356 [ms] (mean, across all concurrent requests)
Transfer rate: 2254.66 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 8 27 5.2 28 35
Processing: 0 3 0.7 3 5
Waiting: 0 3 0.7 3 5
Total: 11 30 5.1 31 38
Percentage of the requests served within a certain time (ms)
50% 31
66% 32
75% 32
80% 33
90% 35
95% 35
98% 38
99% 38
100% 38 (longest request)