Squid untuk mempercepat akses website
Sebagai akselerator akses website, maka squid berada antara klien dan satu atau lebih website.

Keuntungan yang diperoleh yaitu :
Keuntungan yang diperoleh yaitu :
- Caching
- Fleksibilitas
File yang sering diakses akan disimpan dalam cache memory ataupun disk. Squid akan sangat efisien apabila web server menggunakan proses yang besar dalam menghasilkan data atau jika file berada dalam media file yang lambat.
Caching akan tidak berjalan apabila web server tidak menghasilkan header yang dibutuhkan squid, misalnya script CGI dan aplikasi sejenis, dan URL yang tidak cocok untuk caching seperti halnya URL yang hasilnya tergantung dari permintaan client, dimana seharusnya setiap URL menghasilkan hasil yang sama.
Caching akan tidak berjalan apabila web server tidak menghasilkan header yang dibutuhkan squid, misalnya script CGI dan aplikasi sejenis, dan URL yang tidak cocok untuk caching seperti halnya URL yang hasilnya tergantung dari permintaan client, dimana seharusnya setiap URL menghasilkan hasil yang sama.
Web server dibelakang squid bias secara fleksibel dipindah/diupgrade ke system lain dengan cukup merubah squid.conf nya saja. Misalnya jika sebuah website mati, maka bias diarahkan ke server lain, sehingga cepat on-line kembali.
Kapan melakukan Cache
Caching tidak akan efektif bila permintaan data klien lebih besar dibandingkan kemampuan squid menyimpan data, baik itu di memori maupun disk. Pada kebanyakan kasus yang terjadi yaitu squid akan menulis cache dalam swap dan mengeluarkannya kembali terlalu sering (lihat file store_log log).
Berikut beberapa analisa untuk melihat kesesuaian konfigurasi squid.
Berikut beberapa analisa untuk melihat kesesuaian konfigurasi squid.
- Prosentasi Permintaan Ganda
- Besar kebutuhan storage untuk cache
- Rata-rata besar obyek
Prosentasi ini menunjukkan seberapa sering URL diminta dalam jangka waktu tertentu.
( 1 – unik URL / total URL) * 100
- 100% berarti hanya 1 URL yang diminta
- 0 % berarti tidak ada URL ganda
- Prosentasi kecil berarti tidak memberi untung pada caching squid
- 0 % berarti tidak ada URL ganda
- Prosentasi kecil berarti tidak memberi untung pada caching squid
Untuk cara menghitung prosentasenya dapat dilakukan sebagai berikut :
(Linux)
(Linux)
$ perl -lane ‘$t += $F[4]; $u += $F[4] unless \
$seen{$F[6]}++;’ -e ‘END { print “unique=$u total=$t” }’ \
/var/log/squid/access.log
unique=9145670 total=75352325
$ perl -e ‘printf “%.1f%%\n”, (1 - (shift)/(shift))*100′ \ 9145670 75352325
87.9%
Untuk prosentasi yang dihitung otomatis oleh squid dapat dilihat dengan cara :
$ squidclient -p 80 cache_object://localhost/info | grep Ratio
Request Hit Ratios: 5min: 91.3%, 60min: 83.4%
Byte Hit Ratios: 5min: 92.8%, 60min: 88.3%
Request Memory Hit Ratios: 5min: 85.7%, 60min: 85.5%
Request Disk Hit Ratios: 5min: 0.0%, 60min: 3.0%
Byte Hit Ratios: 5min: 92.8%, 60min: 88.3%
Request Memory Hit Ratios: 5min: 85.7%, 60min: 85.5%
Request Disk Hit Ratios: 5min: 0.0%, 60min: 3.0%
Squid harus mempu menampung lebih besar dari kebutuhan / permintaan data website, misalnya kapasitas disk Squid 10 G dan permintaan mencapai 20G setiap harinya, maka penggunaan squid akan menghabiskan waktu saja, karena harus melakukan swap data di cache dan penggunaan I/O yang tinggi.
Besarnya cache di direktori cache_dir harus cukup besar untuk mengantisipasi pertumbuhan permintaan data.
Besarnya cache di direktori cache_dir harus cukup besar untuk mengantisipasi pertumbuhan permintaan data.
Squid melakukan pengelolaan cache dalam batasan/ukuran tertentu, sehingga untuk obyek yang besar dan kecil dibutuhkan konfigurasi yang berbeda, atau ektremnya file yang sangat besar tidak perlu disimpan dalam cache.
Studi Kasus
Proxy kantor:
$ squidclient -p 800 cache_object://localhost/info
$ squidclient -p 800 cache_object://localhost/info
Squid Object Cache: Version 2.6.STABLE6
Start Time: Wed, 29 Jul 2009 02:18:30 GMT
Current Time: Mon, 03 Aug 2009 04:24:59 GMT
Connection information for squid:
Number of clients accessing cache: 7
Number of HTTP requests received: 42683
Number of ICP messages received: 0
Number of ICP messages sent: 0
Number of queued ICP replies: 0
Request failure ratio: 0.00
Average HTTP requests per minute since start: 5.8
Average ICP messages per minute since start: 0.0
Select loop called: 104699610 times, 4.199 ms avg
Cache information for squid:
Request Hit Ratios: 5min: 20.9%, 60min: 37.3%
Byte Hit Ratios: 5min: 14.6%, 60min: 16.6%
Request Memory Hit Ratios: 5min: 5.6%, 60min: 2.5%
Request Disk Hit Ratios: 5min: 83.3%, 60min: 10.3%
Storage Swap size: 5045948 KB
Storage Mem size: 20804 KB
Mean Object Size: 14.88 KB
Requests given to unlinkd: 1176
Median Service Times (seconds) 5 min 60 min:
HTTP Requests (All): 0.61549 0.55240
Cache Misses: 1.31166 1.17732
Cache Hits: 0.00405 0.00865
Near Hits: 0.76407 0.39928
Not-Modified Replies: 0.00000 0.00463
DNS Lookups: 0.00000 0.00000
ICP Queries: 0.00000 0.00000
Resource usage for squid:
UP Time: 439588.573 seconds
CPU Time: 154.097 seconds
CPU Usage: 0.04%
CPU Usage, 5 minute avg: 0.06%
CPU Usage, 60 minute avg: 0.10%
Process Data Segment Size via sbrk(): 63388 KB
Maximum Resident Size: 0 KB
Page faults with physical i/o: 3
Memory usage for squid via mallinfo():
Total space in arena: 63388 KB
Ordinary blocks: 62893 KB 23 blks
Small blocks: 0 KB 0 blks
Holding blocks: 504 KB 2 blks
Free Small blocks: 0 KB
Free Ordinary blocks: 494 KB
Total in use: 63397 KB 99%
Total free: 494 KB 1%
Total size: 63892 KB
Memory accounted for:
Total accounted: 51487 KB
memPoolAlloc calls: 8753571
memPoolFree calls: 7594980
File descriptor usage for squid:
Maximum number of file descriptors: 1024
Largest file desc currently in use: 23
Number of file desc currently in use: 21
Files queued for open: 0
Available number of file descriptors: 1003
Reserved number of file descriptors: 100
Store Disk files open: 0
IO loop method: epoll
Internal Data Structures:
339338 StoreEntries
4193 StoreEntries with MemObjects
4189 Hot Object Cache Items
339221 on-disk objects
Kalau dilihat Rationya maka :
Start Time: Wed, 29 Jul 2009 02:18:30 GMT
Current Time: Mon, 03 Aug 2009 04:24:59 GMT
Connection information for squid:
Number of clients accessing cache: 7
Number of HTTP requests received: 42683
Number of ICP messages received: 0
Number of ICP messages sent: 0
Number of queued ICP replies: 0
Request failure ratio: 0.00
Average HTTP requests per minute since start: 5.8
Average ICP messages per minute since start: 0.0
Select loop called: 104699610 times, 4.199 ms avg
Cache information for squid:
Request Hit Ratios: 5min: 20.9%, 60min: 37.3%
Byte Hit Ratios: 5min: 14.6%, 60min: 16.6%
Request Memory Hit Ratios: 5min: 5.6%, 60min: 2.5%
Request Disk Hit Ratios: 5min: 83.3%, 60min: 10.3%
Storage Swap size: 5045948 KB
Storage Mem size: 20804 KB
Mean Object Size: 14.88 KB
Requests given to unlinkd: 1176
Median Service Times (seconds) 5 min 60 min:
HTTP Requests (All): 0.61549 0.55240
Cache Misses: 1.31166 1.17732
Cache Hits: 0.00405 0.00865
Near Hits: 0.76407 0.39928
Not-Modified Replies: 0.00000 0.00463
DNS Lookups: 0.00000 0.00000
ICP Queries: 0.00000 0.00000
Resource usage for squid:
UP Time: 439588.573 seconds
CPU Time: 154.097 seconds
CPU Usage: 0.04%
CPU Usage, 5 minute avg: 0.06%
CPU Usage, 60 minute avg: 0.10%
Process Data Segment Size via sbrk(): 63388 KB
Maximum Resident Size: 0 KB
Page faults with physical i/o: 3
Memory usage for squid via mallinfo():
Total space in arena: 63388 KB
Ordinary blocks: 62893 KB 23 blks
Small blocks: 0 KB 0 blks
Holding blocks: 504 KB 2 blks
Free Small blocks: 0 KB
Free Ordinary blocks: 494 KB
Total in use: 63397 KB 99%
Total free: 494 KB 1%
Total size: 63892 KB
Memory accounted for:
Total accounted: 51487 KB
memPoolAlloc calls: 8753571
memPoolFree calls: 7594980
File descriptor usage for squid:
Maximum number of file descriptors: 1024
Largest file desc currently in use: 23
Number of file desc currently in use: 21
Files queued for open: 0
Available number of file descriptors: 1003
Reserved number of file descriptors: 100
Store Disk files open: 0
IO loop method: epoll
Internal Data Structures:
339338 StoreEntries
4193 StoreEntries with MemObjects
4189 Hot Object Cache Items
339221 on-disk objects
Kalau dilihat Rationya maka :
Cache information for squid:
Request Hit Ratios: 5min: 20.9%, 60min: 37.3%
Byte Hit Ratios: 5min: 14.6%, 60min: 16.6%
Request Memory Hit Ratios: 5min: 5.6%, 60min: 2.5%
Request Disk Hit Ratios: 5min: 83.3%, 60min: 10.3%
Storage Swap size: 5045948 KB
Storage Mem size: 20804 KB
Mean Object Size: 14.88 KB
Requests given to unlinkd: 1176
Request Hit Ratios: 5min: 20.9%, 60min: 37.3%
Byte Hit Ratios: 5min: 14.6%, 60min: 16.6%
Request Memory Hit Ratios: 5min: 5.6%, 60min: 2.5%
Request Disk Hit Ratios: 5min: 83.3%, 60min: 10.3%
Storage Swap size: 5045948 KB
Storage Mem size: 20804 KB
Mean Object Size: 14.88 KB
Requests given to unlinkd: 1176
Mengapa prosentase rationya rendah ?
- Kalau dilihat contoh kasus diatas, maka dapat dilakukan evaluasi sebagai berikut :
Website mana yang sering diakses, coba lihat di access_log?
Ternyata setelah diamati banyak yang akses mail.google.com, facebook.com, meebo.com, dimana website tersebut setiap URLnya bersifat spesifik untuk setiap user yang artinya tidak akan bermanfaat banyak untuk caching squid. - perl -lane ‘$t += $F[4]; $u += $F[4] unless $seen{$F[6]}++;’ -e ‘END { print “unique=$u total=$t” }’ /var/log/squid/access.log
unique=31224384 total=69307469
Ratio = (1 – 31224384/69307469) * 100% = 54,95%
Artinya memang URL yang diminta hanya 54,95% saja yang ganda - Perhitungan dilakukan jam berapa? Yaitu jam 10 pagi. Ini berbeda dengan statistik Ratio jika dipanggil jam 8 Pagi dan jam 3 Sore, sebab aktifitas pemakai Squid juga berbeda, kalau pagi baca berita dimana ini akan baik baik caching squid.
Kesimpulan ?
- Squid di kantor kalau hanya dimanfaatkan untuk caching saja maka dapat dikatakan belum/tidak optimal
- Proxy internet dan cache internet dapat dipisahkan.






