SQUID CACHE OPTIMIZATION

SQUID ÖNBELLEK VERİMİNİ ARTTIRMA

Mayıs 2003
İlker FIÇICILAR

Squid bandwidth verimi için squid.conf ayarları:


A)
#  TAG: cache_peer
#       To specify other caches in a hierarchy, use the format:
#
#               cache_peer hostname type http_port icp_port

#Türkçesi:
cache_peer venus1.ttnet.net.tr         sibling   8080  3130
cache_peer venus2.ttnet.net.tr         sibling   8080  3130

ya da güçlerinizi birlestirebileceginiz baska proxy'lerle bu ayarları yapın.


B)
#  TAG: maximum_object_size     (bytes)
#       value is specified in kilobytes, and the default is 4MB.  If
#       you wish to get a high BYTES hit ratio, you should probably
#       increase this (one 32 MB object hit counts for 3200 10KB
#
maximum_object_size 16384 KB 


C)
#  TAG: cache_replacement_policy
#       The cache replacement policy parameter determines which
#       objects are evicted (replaced) when disk space is needed.
#
#       The heap GDSF policy optimizes object hit rate by keeping
#       smaller popular objects in cache so it has a better chance of
#       getting a  hit.  It achieves a lower byte hit rate than LFUDA
#       though since  it evicts larger (possibly popular) objects.
#
#       The heap LFUDA policy keeps popular objects in cache regardless
#       of their size and thus optimizes byte hit rate at the expense of
#       hit rate since one large, popular object will prevent many   
#       smaller, slightly less popular objects from being cached.    
#
cache_replacement_policy heap GDSF


D)
#  TAG: refresh_pattern
#       usage: refresh_pattern [-i] regex min percent max [options]
#
#       options: override-expire
#                override-lastmod
#                reload-into-ims 
#                ignore-reload   
#
#               override-expire enforces min age even if the server
#               sent a Expires: header. Doing this VIOLATES the HTTP
#               standard.  Enabling this feature could make you liable
#               for problems which it causes.
#
#               override-lastmod enforces min age even on objects
#               that was modified recently.
#
#               reload-into-ims changes client no-cache or ``reload''
#               to If-Modified-Since requests. Doing this VIOLATES the
#               HTTP standard. Enabling this feature could make you   
#               liable for problems which it causes.
#
#               ignore-reload ignores a client no-cache or ``reload''
#               header. Doing this VIOLATES the HTTP standard. Enabling
#               this feature could make you liable for problems which  
#               it causes.
refresh_pattern         \.gif$          10080   100%  43200 \
override-expire 
refresh_pattern         \.jpg$          10080  100%  43200 \ 
override-expire 
refresh_pattern         cgi-bin         1 20% 2
refresh_pattern         \.asp$          1 20% 2
refresh_pattern         \.acgi$         1 20% 2
refresh_pattern         \.cgi$          1 20% 2
refresh_pattern         \.pl$           1 20% 2
refresh_pattern         \.shtml$        1 20% 2
refresh_pattern         \.php3$         1 20% 2
refresh_pattern         \.php$         1 20% 2 
refresh_pattern         \?              1 20% 2
refresh_pattern .               960     90%     43200   \
reload-into-ims ignore-reload


refresh_pattern ve override-expire seçeneklerinin işlevi:

squid.conf'ta yazdigina gore:

#       override-expire enforces min age even if the server
#       sent a Expires: header. Doing this VIOLATES the HTTP
#       standard.  Enabling this feature could make you liable
#       for problems which it causes.
#

yani, www sunucularin verdikleri "Expires:" bilgisini dikkate almama secenegi. Bu secenegi .gif, .jpg, ve .png gibi uzun bir sure degismeyebilecek nesneler icin kullandik:

refresh_pattern \.gif$  10080 100%  43200 override-expire 
refresh_pattern \.jpg$ 10080 100%  43200 override-expire 

yalniz bu degerler oldukca acimasiz, ama faydali. Ayrintilar gene squid.conf'ta yer aliyor.

Dinamik icerik de onbelleklenebilir. Biz bunda ise cok hafif degerler kullandik, squid'i kullanim durumunuza gore bunlarla oynayabilirsiniz. Burdaki "1 20% 2" seklindeki sayilardan ilki, eger sunucu Expire bilgisi gondermemis ise, o nesnenin dakika cinsinden "en az" kac dakika boyunca "taze" kabul edilecegini belirtiyor. Burada biz Expire bilgisi gelmemis dinamik icerikleri en az 1 dakika boyunca degismemis kabul ettik. ikinci sayi ise (20%) bu nesnenin tam olarak ne kadar bir sure boyunca "taze", "degismemis" kabul edilecegi bilgisi hesabinda kullaniliyor. Bu %20, sunucunun gonderdigi "Last-modified:" basligindan elde edilen "nesne yaSI" bilgisinin %20si hesaba dahil edilsin anlaminda. Son sutun ise, en cok kac dakika boyunca o nesnenin "taze" (cache_hit, gecerli vs.) sayilabilecegini belirliyor. Burdaki ornekte dinamik icerik en cok 2 dakika boyunca cache_hit verebiliyor:


refresh_pattern  cgi-bin   1 20% 2
refresh_pattern  \.asp$   1 20% 2
refresh_pattern  \.acgi$   1 20% 2
refresh_pattern  \.cgi$   1 20% 2
refresh_pattern  \.pl$   1 20% 2
refresh_pattern   \.shtml$  1 20% 2
refresh_pattern  \.php3$  1 20% 2
refresh_pattern  \.php$     1 20% 2 
refresh_pattern  \?   1 20% 2

Bu satir ise geri kalan nesneler (.html, .htm, .txt ... vs.) icin:
(aradaki nokta "." isaretine dikkat)

refresh_pattern . 960 90% 43200 reload-into-ims ignore-reload

Burada en az 960 dakika (16saat) boyunca, Expires bilgisi verilmemis bilgileri degismez kabul ettik. Aslinda bu az sayilabilir, bir gune (1440 dk.) cikarmakta zarar yok sanirim. Ardindan o nesnenin Last-modified bilgisinin hesaptaki agIrlIgInI %90 olarak belirliyoruz. Ve en cok bir ay boyunca (43200 dakika) o veri gecerlidir diyoruz.

reload-into-ims ise sunucunun gonderdigi "Pragma: no-cache" ve "reload" gibi basliklari GET_IMS (Get If_modified_since) cagrilarina donusturuyor. Yani boyle bir nesne ikinci bir kez istendiginde sunucudan yeniden istenmek yerine, sunucuya "Su tarihten beri degismediyse bunu bana bir daha yollayip da kafami sisirme" (GET IMS) cagrisi yollaniyor.

İkincisi, "ignore-reload", ise ise bu "no-cache" basliklarini dikkate almamak icin. Simdi burada ayni satirda bu iki secenegi birden vermek anlamsiz gozukuyor. Dogrusu niye boyle yapmisim hatirlayamadim. Siz isterseniz sadece bunu kullanin simdilik, TTNET arizasi giderilince de daha mantikli olan "reload-into-ims" secenegini kullanirsiniz sadece.

not: "heap gdsf" destegini usenmeyip derlemekte yarar var. Önbellek icin ayirdiginiz disk alanini daha verimli kullanmasini sagliyor. Tabii useniyorsaniz, disk alanini buyutmek veya ek cache_dir 'lar tanimlamak da mantikli.


Mayıs 2003
İlker Fıçıcılar