Кешируем с помощью апача часто запрашиваемый контент mod_cache

  •  
DateFebruary 08, 2010 17:49 Comment4 коммент.

Кеширование на уровне mod_disc_cache (apache)


  CacheRoot "/var/cache/mod_disk_cache"
  CacheEnable disk /
  MCacheSize 64000
  MCacheMaxObjectCount 1000
  MCacheMinObjectSize 1
  MCacheMaxObjectSize 65536
  CacheMaxExpire 604800
  CacheMaxFileSize 512000
  CacheDirLevels 2
  CacheDirLength 2
  CacheIgnoreCacheControl On
  CacheStorePrivate On
  CacheIgnoreNoLastMod On


Есть вариант ипользования в настрокйках апачаmod_mem_cached


  CacheEnable mem /signup_service/check_license
  MCacheSize 40960
  MCacheMaxObjectCount 1000
  MCacheMinObjectSize 1
  MCacheMaxObjectSize 4048
  CacheIgnoreCacheControl On
  CacheMaxExpire 604800
  CacheStorePrivate On
 


Что тает тоже  очень хорошие показатели

 

Кеширование на уровне екшина в приложении caches_action

class SignupServiceController < ApplicationController

  caches_action :check_license, :cache_path => Proc.new { |controller| controller.params[:subscription] }, :expires_in => 1.hour
  caches_action :get_product_list, :cache_path => Proc.new { |controller| controller.params[:Fingerprint] }, :expires_in => 1.hour

Пост запросы   с выключенным caches_action

ab -c 50 -C _comodo_sasp_session=219b7398381e5e03cbaaa51f15ceed22 -n 10000 -t 60 -p /home/wr/comodo/comodo_sasp/tmp/listproducts.xml -H "Content-Type: application/xml" http://sasp/signup_service/get_product_list

Server Software:        Apache/2.2.9
Server Hostname:        sasp
Server Port:            80

Document Path:          /signup_service/get_product_list
Document Length:        369 bytes

Concurrency Level:      50
Time taken for tests:   60.007 seconds
Complete requests:      2266
Failed requests:        0
Write errors:           0
Total transferred:      1835469 bytes
Total POSTed:           1166760
HTML transferred:       836154 bytes
Requests per second:    37.76 [#/sec] (mean)
Time per request:       1324.070 [ms] (mean)
Time per request:       26.481 [ms] (mean, across all concurrent requests)
Transfer rate:          29.87 [Kbytes/sec] received
                        18.99 kb/s sent
                        48.86 kb/s total

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   2.9      0      22
Processing:   164 1308 504.8   1162    4248
Waiting:      164 1308 504.8   1162    4248
Total:        171 1308 504.7   1162    4248

Percentage of the requests served within a certain time (ms)
  50%   1162
  66%   1344
  75%   1484
  80%   1599
  90%   1997
  95%   2477
  98%   2795
  99%   2940
 100%   4248 (longest request)
=========================================================================

Кеширование XML POST запросов на уровне контролера caches_action

ab -c 10 -n 10000 -t 60 -p /home/wr/comodo/comodo_sasp/tmp/listproducts.xml -T "application/xml" http://sasp1:8001/signup_service/get_product_list
(При этом грузится машина  очень прилично до 77% и запущено 10 руби процессов с использование по 128 метрой памяти)

Server Software:        Apache/2.2.9
Server Hostname:        sasp1
Server Port:            8001

Document Path:          /signup_service/get_product_list
Document Length:        369 bytes

Concurrency Level:      10
Time taken for tests:   60.010 seconds
Complete requests:      3059
Failed requests:        0
Write errors:           0
Total transferred:      2456771 bytes
Total POSTed:           1291628
HTML transferred:       1128771 bytes
Requests per second:    50.97 [#/sec] (mean)
Time per request:       196.175 [ms] (mean)
Time per request:       19.618 [ms] (mean, across all concurrent requests)
Transfer rate:          39.98 [Kbytes/sec] received
                        21.02 kb/s sent
                        61.00 kb/s total

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.8      0      58
Processing:    25  195 267.5    132    2400
Waiting:       25  194 267.2    131    2400
Total:         25  195 267.9    132    2400
 

=======================================================================

Если делать GET запросы тогда получается всего 2 реквества в секунду елси отключить все кегирование на уровне апача mod_disk_cache и екшина в приложении caches_action.

ab -c 10 -n 10000 -t 60 -p /home/wr/comodo/comodo_sasp/tmp/listproducts.xml -T "application/xml" 'http://sasp1:8001/signup_service/get_product_list.xml?web_api_login=system_admin&area=livepcsupport&code=randomcode&fingerprint=49115AC2E622733A457CCCC1D889FF819B953346'
 

Document Path:          /signup_service/get_product_list.xml?web_api_login=system_admin&area=livepcsupport&code=randomcode&fingerprint=49115AC2E622733A457CCCC1D889FF819B953346

Document Length:        3044 bytes

Concurrency Level:      10

Time taken for tests:   60.036 seconds

Complete requests:      131

Failed requests:        0

Write errors:           0

Total transferred:      454876 bytes

Total POSTed:           75600

HTML transferred:       398764 bytes

Requests per second:    2.18 [#/sec] (mean)

Time per request:       4582.929 [ms] (mean)

Time per request:       458.293 [ms] (mean, across all concurrent requests)

Transfer rate:          7.40 [Kbytes/sec] received

В данном случае ответы были по 15кб

=============================================================================

Теперь включаю диск кеш и провожу тоже колличество запросов (mod_disk_cache)

ab -c 10 -n 10000 -t 60  -T "application/xml" 'http://sasp1:8001/signup_service/get_product_list.xml?web_api_login=system_admin&area=livepcsupport&code=randomcode&fingerprint=49115AC2E622733A457CCCC1D889FF819B953346'

Document Path:          /signup_service/get_product_list.xml?web_api_login=system_admin&area=livepcsupport&code=randomcode&fingerprint=49115AC2E622733A457CCCC1D889FF819B953346
Document Length:        15936 bytes

Concurrency Level:      10
Time taken for tests:   57.857 seconds
Complete requests:      50000
Failed requests:        0
Write errors:           0
Total transferred:      818823838 bytes
HTML transferred:       796879680 bytes
Requests per second:    864.21 [#/sec] (mean)
Time per request:       11.571 [ms] (mean)
Time per request:       1.157 [ms] (mean, across all concurrent requests)
Transfer rate:          13820.93 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   1.9      1      86
Processing:     0   10  87.0      2    4100
Waiting:        0    9  87.1      1    4100
Total:          0   11  87.2      4    4137
 

Убрал xml хедер и делаю обычные get запросы

Concurrency Level:      10
Time taken for tests:   54.485 seconds
Complete requests:      50000
Failed requests:        0
Write errors:           0
Total transferred:      818931885 bytes
HTML transferred:       796879680 bytes
Requests per second:    917.69 [#/sec] (mean)
Time per request:       10.897 [ms] (mean)
Time per request:       1.090 [ms] (mean, across all concurrent requests)
Transfer rate:          14678.22 [Kbytes/sec] received
 

Тестирование нагрузки проводилось с помощтю ApacheBench/2.3
http://marc.info/?l=apache-modproxy-dev&m=104961128808904&w=2
http://api.rubyonrails.org/classes/ActionController/Caching/Actions.html
Дальше надо еще запустить демон для очистки кеша каждые 5 минут с лимитом использования дискового пространтсва в 100 МБ

htcacheclean -t -d 5 -l 100M -i -p /var/cache/mod_disk_cache/
пару неправильных постов случилось, из за включеннного кеша в апаче, сейчас вроде все пофиксил, елси найдете странности на форуме пишите
Зарегистрируйтесь для добавления сообщений