ข่าว: ข่าวประกาศ

  • 26 เมษายน 2024, 13:27:55

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ผู้เขียน หัวข้อ: refresh_pattern  (อ่าน 9429 ครั้ง)

admin

  • Administrator
  • Hero Member
  • *****
  • กระทู้: 3820
    • ดูรายละเอียด
    • อีเมล์
refresh_pattern
« เมื่อ: 05 พฤษภาคม 2010, 17:04:52 »
พอดีไปเจอมา เลยนำมาฝากให้อ่านกัน อาจจะทำให้เข้าใจ refresh_pattern กันมากขึ้น

ปรับ refresh pattern เพิ่มอัตรา hit ของ squid

Submitted by thep on 10 February, 2009 - 19:41. gatewayinternet servernetworkingproxysquid

squid เป็นหนึ่งในซอฟต์แวร์ที่มีค่าคอนฟิกเยอะมาก และมีเกร็ดการ fine-tune เยอะแยะไปหมด เพื่อนสมาชิกที่มีประสบการณ์ก็สามารถมาแชร์เป็นวิทยาทานกันได้นะครับ

ผมเองไม่มีประสบการณ์การ fine-tune squid มากนัก แต่เร็ว ๆ นี้ ได้ไปเจอ เคล็ดวิชา refresh pattern มา และใช้ได้ผลพอประมาณ เลยเอามาเล่าสู่กันฟัง

refresh pattern เป็นตัวกำหนดว่าจะให้อะไรเก่าอะไรใหม่สำหรับแคชและการตอบกลับ ซึ่งโดยหลักการแล้ว คุณควรจะให้ squid เชื่อตาม HTTP header ต่าง ๆ ที่เว็บเซิร์ฟเวอร์ตอบกลับมา ว่าอะไรเก่าอะไรใหม่ขนาดไหน แต่โชคไม่ดีที่ค่าต่าง ๆ เหล่านี้มักตอบมาตามค่า default ของเว็บเซิร์ฟเวอร์ ซึ่งไม่ช่วยอะไรนักสำหรับการทำแคช ดังนั้น การปรับ refresh pattern จึงช่วยได้ในเรื่องนี้

refresh pattern ใน squid.conf จะอยู่ในรูปแบบ:

refresh_pattern [-i] regex min percent max [options]

โดยที่

•regex คือนิพจน์เรกิวลาร์แทน URL ที่จะเข้ากฎ โดยปกติจะ case sensitive ยกเว้นเมื่อมีตัวเลือก -i
•min คืออายุที่ต่ำที่สุด (เป็นนาที) ของอ็อบเจกต์ที่จะเริ่มพิจารณาความเก่าใหม่ โดยถ้าต่ำกว่านี้จะถือว่าใหม่เสมอ (ยกเว้นว่ามีการกำหนดเวลาหมดอายุมาใน HTTP header)
•max คืออายุที่สูงที่สุด (เป็นนาที) ของอ็อบเจกต์ที่จะยังคงพิจารณาความเก่าใหม่อยู่ โดยถ้าสูงกว่านี้จะถือว่าเก่าเสมอ
•percent คือเปอร์เซ็นต์ของอายุในแคชของอ็อบเจกต์นับตั้งแต่ refresh ครั้งล่าสุด เทียบกับอายุจริงของอ็อบเจกต์ตามที่เว็บเซิร์ฟเวอร์รายงาน ที่จะยังคงถือว่าอ็อบเจกต์นั้นยังใหม่อยู่
•options คือตัวเลือกเพิ่มเติม ซึ่งจะกล่าวถึงในภายหลัง

ตัวอย่างเช่น

refresh_pattern -i \.gif$ 1440 20% 10080

หมายความว่า:

•ถ้าอ็อบเจกต์ *.gif มี header ระบุเวลาหมดอายุ ก็เชื่อถือตาม header นั้น จบ ถ้าไม่มี จึงพิจารณาต่อไป
•ถ้าอ็อบเจกต์อยู่ในแคชต่ำกว่า 1440 นาที (1 วัน) ถือว่ายังใหม่อยู่ ใช้ค่าในแคชตอบกลับได้ทันที
•ถ้าอ็อบเจกต์อยู่ในแคชมานานเกิน 10080 นาที (7 วัน) ถือว่าเก่าแล้ว ให้ดึงอ็อบเจกต์มาใหม่จากเว็บเซิร์ฟเวอร์
•ถ้าอายุในแคชของอ็อบเจกต์อยู่ระหว่าง 1440-10080 นาที ให้พิจารณาอายุในแคช ว่าถึง 20% ของอายุจริงหรือไม่ เช่น ถ้าเว็บเซิร์ฟเวอร์รายงานมาว่าอ็อบเจกต์นี้สร้างขึ้นเมื่อ 10,000 นาทีที่แล้ว ก็พิจารณาว่าอ็อบเจกต์อยู่ในแคชมานานถึง 20% ของ 10,000 คือ 2,000 นาทีหรือไม่ ถ้ายังไม่ถึง ก็ถือว่ายังใหม่ ถ้าถึง ก็ถือว่าเก่าแล้ว

ส่วน options หรือตัวเลือกเพิ่มเติม ส่วนใหญ่จะเป็นการพยายามละเมิดมาตรฐาน HTML เพื่อเพิ่มอัตราการแคช จึงควรระมัด
ระวังในการใช้งาน ตัวเลือกมีดังนี้:

•override-expire -- ไม่ต้องสนใจ header ระบุเวลาหมดอายุที่เว็บเซิร์ฟเวอร์บอกมา (พิจารณาตามกฎเสมอ)
•override-lastmod -- ไม่สนใจ header ระบุเวลาเปลี่ยนแปลงล่าสุดที่เว็บเซิร์ฟเวอร์บอกมา (ถือว่าอ็อบเจกต์มีอายุจริงเท่ากับ min แม้จะเพิ่งเปลี่ยนแปลงใหม่)
•reload-into-ims -- เปลี่ยน request "no-cache" จากลูกข่ายให้เป็น If-Modified-Since
•ignore-reload -- ไม่สนใจ header "no-cache" จากลูกข่าย และจะใช้ข้อมูลในแคชถ้าทำได้
•ignore-no-cache -- ไม่สนใจ header "Pragma: no-cache" และ "Cache-control: no-cache" ที่ส่งมาจากเว็บเซิร์ฟเวอร์ ซึ่ง HTTP RFC ไม่ได้อนุญาตให้เว็บเซิร์ฟเวอร์ทำ แต่ก็มักจะทำกัน
•ignore-no-store -- ไม่สนใจ header "Cache-control: no-store" ที่ส่งมาจากเว็บเซิร์ฟเวอร์
•ignore-private -- ไม่สนใจ header "Cache-control: private" ที่ส่งมาจากเว็บเซิร์ฟเวอร์
•ignore-auth -- เก็บอ็อบเจกต์ที่ต้องผ่านการยืนยันตัวบุคคลของผู้อ่านลงแคชด้วย
•refresh-ims -- ส่ง request If-Modified-Since ไปที่เว็บเซิร์ฟเวอร์เมื่อผู้ใช้ refresh หน้าเว็บ
คุณสามารถปรับ refresh pattern ให้เก็บอ็อบเจกต์ที่มักไม่มีการเปลี่ยนแปลง เช่น รูปภาพ เสียง วีดิทัศน์ แฟ้มโปรแกรม แฟ้มบีบอัด ฯลฯ ให้อยู่ในแคชนานขึ้นได้ เพื่อเพิ่มอัตราการ hit เช่น (คัดลอกมาจากบทความต้นตอ):

refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i \.(gif|png|jpg|jpeg|ico)$ \
  10080 90% 43200 override-expire ignore-no-cache ignore-no-store ignore-private
refresh_pattern -i \.(iso|avi|wav|mp3|mp4|mpeg|swf|flv|x-flv)$ \
  43200 90% 432000 override-expire ignore-no-cache ignore-no-store ignore-private
refresh_pattern -i \.(deb|rpm|exe|zip|tar|tgz|ram|rar|bin|ppt|doc|tiff)$  \
  10080 90% 43200 override-expire ignore-no-cache ignore-no-store ignore-private
refresh_pattern -i \.index.(html|htm)$ 0 40% 10080
refresh_pattern -i \.(html|htm|css|js)$ 1440 40% 40320
refresh_pattern . 0 40% 40320

กฎจะถูกนำมาตรวจสอบเรียงทีละกฎจากบนลงล่าง จนกว่าจะพบกฎแรกที่ตรง ก็จะใช้กฎนั้นและหยุดตรวจสอบต่อ ดังนั้น กฎสุดท้ายจึงเป็นกฎที่เอาไว้รองรับแพตเทิร์นที่เหลือโดยทั่วไป และมักจะแยกกฎสำหรับโพรโทคอลอื่นอย่างเช่น FTP และ gopher เอาไว้บนสุด เพื่อกันไม่ให้มาใช้กฎด้านล่าง

ในบทความต้นตอ ยังมีเกร็ดการควบคุมแคชสำหรับเว็บที่เนื้อหาเป็น dynamic บางเว็บที่อาจทำแคชบางส่วนได้ รวมทั้งจัดการกับ windowsupdate ที่มักจะมากินแบนด์วิดท์บ่อย ๆ ด้วย

ที่มา: Speed up your Internet access using Squid's refresh patterns, comment ใน squid.conf

ที่มา: http://debianclub.org/node/413
<a href="http://www.hadyaiinternet.com/images/inetcafe.swf" target="_blank" rel="noopener noreferrer" class="bbc_link bbc_flash_disabled new_win">http://www.hadyaiinternet.com/images/inetcafe.swf</a>

admin

  • Administrator
  • Hero Member
  • *****
  • กระทู้: 3820
    • ดูรายละเอียด
    • อีเมล์
Re: refresh_pattern
« ตอบกลับ #1 เมื่อ: 05 พฤษภาคม 2010, 23:58:11 »
Squid store.log 

Information and status of [not] stored objects

Format:

Timestamp Tag Code Date LM Expire Content Expect/Length Methode Key

with:

Timestamp
 The time this entry was logged. (millisecond resolution since 00:00:00 UTC, January 1, 1970) 

Tag
 SWAPIN (swapped into memory from disk), SWAPOUT (saved to disk) or RELEASE (removed from cache) 

Code
 The HTTP reply code when available. For ICP requests this is always "0". If the reply code was not given, it will be logged as "555." 

The following three fields are timestamps parsed from the HTTP reply headers. All are expressed in Unix time (i.e.(seconds since 00:00:00 UTC, January 1, 1970). A missing header is represented with -2 and an unparsable header is represented as -1. 

Date
 Time from the HTTP Date reply header. If the Date header is missing or invalid, the time of the request is used instead. 

LM
 The value of the HTTP Last-Modified: reply header. 

Expires
 The value of the HTTP Expires: reply header. 

Content
 The HTTP Content-Type reply header. 

Expect
 The value of the HTTP Content-Length reply header. Zero if Content-Length was missing. 

/Length
 The number of bytes of content actually read. If the Expect is non-zero, and not equal to the Length, the object will be released from the cache. 

Method
 The request method (GET, POST, etc). 

Key
 The cache key. Often this is simply the URL. Cache objects which never become public will have cache keys that include a unique integer sequence number, the request method, and then the URL.
( /[post|put|head|connect]/URI ) 
<a href="http://www.hadyaiinternet.com/images/inetcafe.swf" target="_blank" rel="noopener noreferrer" class="bbc_link bbc_flash_disabled new_win">http://www.hadyaiinternet.com/images/inetcafe.swf</a>