LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Cache in Squid Server (https://www.linuxquestions.org/questions/linux-newbie-8/cache-in-squid-server-947953/)

uk.engr 06-01-2012 06:14 AM

Cache in Squid Server
 
Assalam o Alaikum!

I am facing problem in squid caching. In squid.conf:

cache_dir ufs /var/spool/squid 100 16 256
[root@test1 /]# squid -z
2012/06/01 07:23:05| WARNING cache_mem is larger than total disk cache space!
Or
[root@test1 /]# service squid restart
Stopping squid: 2012/06/01 07:23:39| WARNING cache_mem is larger than total disk cache space!
................ [ OK ]
Starting squid: . [ OK ]

[root@test1 /]# cat /proc/meminfo
MemTotal: 767248 kB
MemFree: 27172 kB
Buffers: 99604 kB
Cached: 343260 kB
SwapCached: 8 kB
Active: 322416 kB
Inactive: 342244 kB
Active(anon): 103316 kB
Inactive(anon): 122236 kB
Active(file): 219100 kB
Inactive(file): 220008 kB
Unevictable: 0 kB
Mlocked: 0 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 767248 kB
LowFree: 27172 kB
SwapTotal: 1507324 kB
SwapFree: 1507316 kB
Dirty: 1008 kB
Writeback: 0 kB
AnonPages: 221788 kB
Mapped: 73324 kB
Shmem: 3756 kB
Slab: 61592 kB
SReclaimable: 52992 kB
SUnreclaim: 8600 kB
KernelStack: 1760 kB
PageTables: 5688 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 1890948 kB
Committed_AS: 1067352 kB
VmallocTotal: 237624 kB
VmallocUsed: 5916 kB
VmallocChunk: 223032 kB
HardwareCorrupted: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 4096 kB
DirectMap4k: 16320 kB
DirectMap4M: 770048 kB







Wht shud I do?

Many thanks!

bathory 06-01-2012 03:29 PM

Hi,

It looks like you have defined a cache_mem bigger than the cache_dir (that is 100MB in your case).
You can either ignore it (it's just a warning), or set cache_mem lower than 100MB

Regards

uk.engr 06-02-2012 01:09 AM

Thanks for your reply. where i can find cache_mem? I mean how can I change this parameter? I have one more question how can I verify cache webs? I mean whether it is taking web from my cache or from internet?

[root@Zohaib zohaib_shaikh]# tail -f /var/log/squid/access.log
1338567636.688 763 192.168.1.111 TCP_MISS/200 1138 GET http://us.mg5.mail.yahoo.com/ws/mail/v2.0/formrpc? - DIRECT/183.177.93.20 application/json
1338567656.143 28770 192.168.1.111 TCP_MISS/200 399 GET http://prod1.rest-notify.msg.yahoo.c...annel/uk.engr? - DIRECT/67.195.186.237 application/json
1338567677.176 312770 192.168.1.111 TCP_MISS/200 1535 CONNECT mail.google.com:443 - DIRECT/74.125.232.117 -

Its look like it is taking webs from internet not from cache??

bathory 06-02-2012 02:08 AM

Hi,

Quote:

where i can find cache_mem? I mean how can I change this parameter?
There should be a "cache_mem" option in squid.conf


Quote:

I have one more question how can I verify cache webs? I mean whether it is taking web from my cache or from internet?
Looking at access_log:
When you see a TCP_MISS it means that the object was not cached.
A TCP_HIT means that the object was fetched from cache. For a better explanation see this

Regards

uk.engr 06-02-2012 02:43 AM

1 Attachment(s)
Thanks. I am unable to find cache_mem option in squid.conf. I have attached my squid.conf in txt format. Kindly see this. How can I trouble shoot the problem of TCP_MISS? When I repeatedly open same webs it gives same message of TCP_MISS.

bathory 06-02-2012 03:45 AM

Quote:

I am unable to find cache_mem option in squid.conf. I have attached my squid.conf in txt format.
Indeed there is no cache_mem option. Doh, add it and use something like:
Code:

cache_mem 32 MB
so it stops complaining.


Quote:

How can I trouble shoot the problem of TCP_MISS? When I repeatedly open same webs it gives same message of TCP_MISS.
If it's a first time squid installation, you should have run:
Code:

squid -z
prior anything else, so squid could create it's cache directory structure (under /var/spool/squid in your case).
Note that this is done only once, before squid starts for the 1st time. Maybe you don't have a correct cache_dir and that's the reason for squid complaining about cache_mem.

uk.engr 06-05-2012 09:09 AM

Thanks. Dear, I tried cache_mem 32 MB, it works, now warning does not appears. This problem is resolved.

Now I am unable to resolve TCP_MISS problem. I have also used squid -z its output is:

[root@Zohaib zohaib_shaikh]# service squid stop
Stopping squid: ................ [ OK ]
[root@Zohaib zohaib_shaikh]# squid -z
2012/06/05 18:32:52| Creating Swap Directories
2012/06/05 18:32:52| /var/spool/squid exists
2012/06/05 18:32:52| /var/spool/squid/00 exists
2012/06/05 18:32:52| Making directories in /var/spool/squid/00
2012/06/05 18:32:52| /var/spool/squid/01 exists
2012/06/05 18:32:52| Making directories in /var/spool/squid/01
2012/06/05 18:32:52| /var/spool/squid/02 exists
2012/06/05 18:32:52| Making directories in /var/spool/squid/02
2012/06/05 18:32:52| /var/spool/squid/03 exists
2012/06/05 18:32:52| Making directories in /var/spool/squid/03
2012/06/05 18:32:52| /var/spool/squid/04 exists
2012/06/05 18:32:52| Making directories in /var/spool/squid/04
2012/06/05 18:32:52| /var/spool/squid/05 exists
2012/06/05 18:32:52| Making directories in /var/spool/squid/05
2012/06/05 18:32:52| /var/spool/squid/06 exists
2012/06/05 18:32:52| Making directories in /var/spool/squid/06
2012/06/05 18:32:52| /var/spool/squid/07 exists
2012/06/05 18:32:52| Making directories in /var/spool/squid/07
2012/06/05 18:32:52| /var/spool/squid/08 exists
2012/06/05 18:32:52| Making directories in /var/spool/squid/08
2012/06/05 18:32:52| /var/spool/squid/09 exists
2012/06/05 18:32:52| Making directories in /var/spool/squid/09
2012/06/05 18:32:52| /var/spool/squid/0A exists
2012/06/05 18:32:52| Making directories in /var/spool/squid/0A
2012/06/05 18:32:52| /var/spool/squid/0B exists
2012/06/05 18:32:52| Making directories in /var/spool/squid/0B
2012/06/05 18:32:52| /var/spool/squid/0C exists
2012/06/05 18:32:52| Making directories in /var/spool/squid/0C

After restarting squid's service and accessing webs we have following log:


[root@Zohaib zohaib_shaikh]# tail -f /var/log/squid/access.log
1338901168.271 1864 192.168.1.109 TCP_MISS/200 1137 GET http://us.mg5.mail.yahoo.com/ws/mail/v2.0/formrpc? - DIRECT/183.177.93.20 application/json
1338901178.432 274105 192.168.1.109 TCP_MISS/200 2570 CONNECT mail.google.com:443 - DIRECT/173.194.35.117 -
1338901285.974 120000 192.168.1.109 TCP_MISS/000 0 GET http://prod2.rest-notify.msg.yahoo.c...annel/uk.engr? - DIRECT/216.155.195.253 -
1338901318.098 310000 192.168.1.109 TCP_MISS/200 2026 CONNECT mail.google.com:443 - DIRECT/173.194.35.117 -

Means no cacheing? How can we fix this problem?

bathory 06-05-2012 03:09 PM

Hi,

If you want to test squid caching, you should visit the same URL several times and from the same or different systems/browsers and see what you get.
The 1st time you'll get a TCP_MISS, but after that you should start getting get TCP_HITs

Regards

uk.engr 06-19-2012 02:01 AM

Quote:

Originally Posted by bathory (Post 4696260)
If you want to test squid caching, you should visit the same URL several times and from the same or different systems/browsers and see what you get.
The 1st time you'll get a TCP_MISS, but after that you should start getting get TCP_HITs


Yes I tried the same but every time I got TCP_MISS so please any solution?

bathory 06-19-2012 04:39 AM

Quote:

Originally Posted by uk.engr (Post 4706701)
Yes I tried the same but every time I got TCP_MISS so please any solution?

Are you visiting dynamic pages? Try to visit a static page, like http://www.squid-cache.org for example and see what you get

uk.engr 06-19-2012 04:56 AM

Now I get following logs

First time:

1340100083.871 499 192.168.1.117 TCP_MISS/200 1870 GET http://www.squid-cache.org/favicon.ico - DIRECT/198.186.193.234 image/x-icon
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2nd and 3rd time
1340100099.589 1054 192.168.1.117 TCP_REFRESH_UNMODIFIED/304 531 GET http://www.squid-cache.org/ - DIRECT/198.186.193.234 -


Still not cacheing.

bathory 06-19-2012 06:14 AM

The above 2 lines mean nothing. You should hit the site and watch squid access.log for the whole time. There should be many objects (like images etc) logged.
Then use another browser, hit the same site again and watch what happens with these objects. See for example the following snippets for another site:
Quote:

1st browser
19/Jun/2012:13:58:26 +0300 24 192.168.0.77 TCP_MISS/200 1187 GET http://www.linuxtoday.com/icom_inclu...login-itbe.png - HIER_DIRECT/www.linuxtoday.com image/png
19/Jun/2012:13:58:26 +0300 31 192.168.0.77 TCP_MISS/200 3113 GET http://www.linuxtoday.com/icom_inclu.../logo-itbe.png - HIER_DIRECT/www.linuxtoday.com image/png
19/Jun/2012:13:58:26 +0300 12 192.168.0.77 TCP_MISS/200 2295 GET http://www.linuxtoday.com/icom_inclu...randingcode.js - HIER_DIRECT/www.linuxtoday.com
application/java$
19/Jun/2012:13:58:26 +0300 16 192.168.0.77 TCP_MISS/200 1456 GET http://www.linuxtoday.com/icom_inclu...ister-itbe.png - HIER_DIRECT/www.linuxtoday.com image/png
19/Jun/2012:13:58:26 +0300 11 192.168.0.77 TCP_MISS/200 1046 GET http://www.linuxtoday.com/icom_inclu...ogout-itbe.png - HIER_DIRECT/www.linuxtoday.com image/png
19/Jun/2012:13:58:26 +0300 13 192.168.0.77 TCP_MISS/200 2240 GET http://www.linuxtoday.com/icom_inclu...-developer.png - HIER_DIRECT/www.linuxtoday.com image/png
19/Jun/2012:13:58:26 +0300 12 192.168.0.77 TCP_MISS/200 1261 GET http://www.linuxtoday.com/icom_inclu.../login-dev.png - HIER_DIRECT/www.linuxtoday.com image/png
19/Jun/2012:13:58:26 +0300 13 192.168.0.77 TCP_MISS/200 1552 GET http://www.linuxtoday.com/icom_inclu...gister-dev.png - HIER_DIRECT/www.linuxtoday.com image/png
19/Jun/2012:13:58:26 +0300 12 192.168.0.77 TCP_MISS/200 1153 GET http://www.linuxtoday.com/icom_inclu...logout-dev.png - HIER_DIRECT/www.linuxtoday.com image/png
19/Jun/2012:13:58:26 +0300 12 192.168.0.77 TCP_MISS/200 2249 GET http://www.linuxtoday.com/icom_inclu...-developer.png - HIER_DIRECT/www.linuxtoday.com image/png
19/Jun/2012:13:58:26 +0300 2927 192.168.0.77 TCP_MISS/200 16060 GET http://www.linuxtoday.com/ - HIER_DIRECT/www.linuxtoday.com text/html
<snip>
2nd browser:
19/Jun/2012:13:59:21 +0300 0 192.168.0.77 TCP_MEM_HIT/200 3120 GET http://www.linuxtoday.com/icom_inclu.../logo-itbe.png - HIER_NONE/- image/png
19/Jun/2012:13:59:21 +0300 0 192.168.0.77 TCP_MEM_HIT/200 1194 GET http://www.linuxtoday.com/icom_inclu...login-itbe.png - HIER_NONE/- image/png
19/Jun/2012:13:59:21 +0300 1 192.168.0.77 TCP_MEM_HIT/200 1463 GET http://www.linuxtoday.com/icom_inclu...ister-itbe.png - HIER_NONE/- image/png
19/Jun/2012:13:59:21 +0300 0 192.168.0.77 TCP_MEM_HIT/200 1053 GET http://www.linuxtoday.com/icom_inclu...ogout-itbe.png - HIER_NONE/- image/png
19/Jun/2012:13:59:21 +0300 0 192.168.0.77 TCP_MEM_HIT/200 2247 GET http://www.linuxtoday.com/icom_inclu...-developer.png - HIER_NONE/- image/png
19/Jun/2012:13:59:21 +0300 0 192.168.0.77 TCP_MEM_HIT/200 1268 GET http://www.linuxtoday.com/icom_inclu.../login-dev.png - HIER_NONE/- image/png
19/Jun/2012:13:59:21 +0300 0 192.168.0.77 TCP_MEM_HIT/200 1559 GET http://www.linuxtoday.com/icom_inclu...gister-dev.png - HIER_NONE/- image/png
19/Jun/2012:13:59:21 +0300 0 192.168.0.77 TCP_MEM_HIT/200 1160 GET http://www.linuxtoday.com/icom_inclu...logout-dev.png - HIER_NONE/- image/png
19/Jun/2012:13:59:21 +0300 1 192.168.0.77 TCP_MEM_HIT/200 2256 GET http://www.linuxtoday.com/icom_inclu...-developer.png - HIER_NONE/- image/png
19/Jun/2012:13:59:21 +0300 1 192.168.0.77 TCP_MEM_HIT/200 3280 GET http://www.linuxtoday.com/img/linuxtd_logo.png - HIER_NONE/- image/png
19/Jun/2012:13:59:21 +0300 650 192.168.0.77 TCP_MISS/200 16060 GET http://www.linuxtoday.com/ - HIER_DIRECT/www.linuxtoday.com text/html
19/Jun/2012:13:59:21 +0300 0 192.168.0.77 TCP_MEM_HIT/200 1626 GET http://www.linuxtoday.com/icom_inclu.../jw_netsol.gif - HIER_NONE/- image/gif
19/Jun/2012:13:59:21 +0300 13 192.168.0.77 TCP_MISS/200 2148 GET http://www.linuxtoday.com/icom_inclu...randingcode.js - HIER_DIRECT/www.linuxtoday.com application/javascript
19/Jun/2012:13:59:21 +0300 31 192.168.0.77 TCP_MISS/200 10553 GET http://www.linuxtoday.com/icom_inclu.../scripts/ga.js - HIER_DIRECT/www.linuxtoday.com application/javascript
<snip>
As you see static content like images is cached, while other objects are not

uk.engr 06-19-2012 06:51 AM

Yes dear, i understand now. It cacheing only static things. I got TCP_HIT. thanks dear.


All times are GMT -5. The time now is 07:31 AM.