Skip to content

Instantly share code, notes, and snippets.

@xurizaemon
Created February 13, 2015 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xurizaemon/eb43fe91f5a505700722 to your computer and use it in GitHub Desktop.
Save xurizaemon/eb43fe91f5a505700722 to your computer and use it in GitHub Desktop.
Performance improvements by circumventing CiviCRM's imagefile handler

CiviCRM Image File Handler vs ImageCache External (primed)

TLDR

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 500ms to 3s when served via CiviCRM, and from

CiviCRM Image File Handler

50 requests, no concurrency

Requesting the file from the same server, so minimal network time. Not a production server, please make your own measurements :)

Mean request time: 560ms

$ ab -n 50 "https://example.org/civicrm/contact/imagefile?photo=time_628d3942e69fffc85198e86fc81ace86.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=time_628d3942e69fffc85198e86fc81ace86.jpg
Document Length:        13013 bytes

Concurrency Level:      1
Time taken for tests:   28.018 seconds
Complete requests:      50
Failed requests:        0
Write errors:           0
Total transferred:      674500 bytes
HTML transferred:       650650 bytes
Requests per second:    1.78 [#/sec] (mean)
Time per request:       560.364 [ms] (mean)
Time per request:       560.364 [ms] (mean, across all concurrent requests)
Transfer rate:          23.51 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        4    4   0.5      4       6
Processing:   528  556  38.5    545     703
Waiting:      527  556  38.5    545     703
Total:        532  560  38.5    549     707

Percentage of the requests served within a certain time (ms)
  50%    549
  66%    557
  75%    562
  80%    565
  90%    574
  95%    669
  98%    707
  99%    707
 100%    707 (longest request)

50 requests, concurrency of 10

Mean request time: 3089ms

$ ab -n 50 "https://example.org/civicrm/contact/imagefile?photo=time_628d3942e69fffc85198e86fc81ace86.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=time_628d3942e69fffc85198e86fc81ace86.jpg
Document Length:        13013 bytes

Concurrency Level:      10
Time taken for tests:   15.446 seconds
Complete requests:      50
Failed requests:        0
Write errors:           0
Total transferred:      674500 bytes
HTML transferred:       650650 bytes
Requests per second:    3.24 [#/sec] (mean)
Time per request:       3089.194 [ms] (mean)
Time per request:       308.919 [ms] (mean, across all concurrent requests)
Transfer rate:          42.64 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        4   10  10.3      4      39
Processing:   892 2964 785.2   3124    4254
Waiting:      892 2964 785.2   3124    4254
Total:        920 2974 780.5   3129    4259

Percentage of the requests served within a certain time (ms)
  50%   3129
  66%   3318
  75%   3514
  80%   3596
  90%   3905
  95%   4000
  98%   4259
  99%   4259
 100%   4259 (longest request)

ImageCache External (aka "just the webserver")

50 requests, no concurrency

$ ab -n 50 "https://example.org/sites/example.org/files/styles/no_change/public/externals/74834ed832993a8a370db0f9b2204761.jpg?itok=394Sa0nG"
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/74834ed832993a8a370db0f9b2204761.jpg?itok=394Sa0nG
Document Length:        7518 bytes

Concurrency Level:      1
Time taken for tests:   0.244 seconds
Complete requests:      50
Failed requests:        0
Write errors:           0
Total transferred:      387650 bytes
HTML transferred:       375900 bytes
Requests per second:    204.59 [#/sec] (mean)
Time per request:       4.888 [ms] (mean)
Time per request:       4.888 [ms] (mean, across all concurrent requests)
Transfer rate:          1549.02 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        4    4   0.7      4       8
Processing:     0    0   1.1      0       8
Waiting:        0    0   1.1      0       8
Total:          4    5   1.4      4      13

Percentage of the requests served within a certain time (ms)
  50%      4
  66%      4
  75%      5
  80%      5
  90%      6
  95%      6
  98%     13
  99%     13
 100%     13 (longest request)

50 requests, 10 concurrent

$ ab -c 10 -n 50 "https://example.org/sites/example.org/files/styles/no_change/public/externals/74834ed832993a8a370db0f9b2204761.jpg?itok=394Sa0nG"
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/74834ed832993a8a370db0f9b2204761.jpg?itok=394Sa0nG
Document Length:        7518 bytes

Concurrency Level:      10
Time taken for tests:   0.164 seconds
Complete requests:      50
Failed requests:        0
Write errors:           0
Total transferred:      387650 bytes
HTML transferred:       375900 bytes
Requests per second:    304.37 [#/sec] (mean)
Time per request:       32.855 [ms] (mean)
Time per request:       3.286 [ms] (mean, across all concurrent requests)
Transfer rate:          2304.46 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        8   27   4.9     28      35
Processing:     0    3   0.7      3       5
Waiting:        0    3   0.7      3       5
Total:         11   30   4.8     31      38

Percentage of the requests served within a certain time (ms)
  50%     31
  66%     31
  75%     32
  80%     32
  90%     32
  95%     32
  98%     38
  99%     38
 100%     38 (longest request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment