|
 |
|
Keep-Alive มันคือ อะไรหรอครับ หลังจากผม Check จาก Chrome |
|
 |
|
|
 |
 |
|
อ่านแล้วครับ แต่ยังไม่เข้า ใจ แหนะครับ
เป็นการเปิดใช้งาน ของตัว Host เพื่อให้ ลดอัตราการโหลดข้อมูลซ้ำ
ทำให้เว็บเร็วขึ้น (ใช่หรือเปล่าไม่แน่ใจนะครับ)
แล้วผมจะ เปิดใช้งานได้ อย่างไรครับ
วิธีสอน หรือ มีเว็บแนะนำ วิธีใช้ keep-alive ไหมครับ
|
 |
 |
 |
 |
Date :
2012-01-10 01:49:21 |
By :
nuznee |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
keep-live หรือ persistent connection เป็นการบอกให้ server ทำการเปิด Connection ค้างไว้ เพื่อป้องกันการเปิด Connection ทุกๆครั้งที่มีการ Request/Response ซึ่งมันจะทำให้ช้านั่นเอง
โดยปกติใน HTTP 1.1 จะทำการ keep-alive ไว้อยู่แล้ว
แต่ถ้าเป็น HTTP 1.0 ยังไม่มีใครระบุไว้นะครับว่าเราจะสั่งงานมันได้ยังไง อันนี้ขึ้นอยู่กับ browser ที่ใช้
แต่อย่างไรก็ตามมันก็ขึ้นอยู่กับ Server ด้วยว่ารองรับการ keep-alive หรือไม่ ถ้ายังก็ไปเปิดที่ server ให้ KeepAlive on
วิธีดู header ก็ให้ใช้ Firefox ง่ายสุดครับ แล้วไปโหลด firebug plugin มาลง จากนั้นก็เปิดมันแล้วคลิกที่ Net tab
อยากจะรู้ว่า header ที่ถูกต้องเป็นไง ก็ต้องเช็คจาก http://www.google.co.th/ แหละครับมันคิด page speed มา มันต้องถูกอยู่แล้ว
การ keep-alive จะเกิดกับไฟล์ image/css/javascript พวกนี้ครับที่มีการเรียกใช้งานบ่อยๆ และจะเกิดกับ Response status 200 เท่านั้น status 304 ไม่มีมีแน่นอนเพราะมันเรียกจากเครื่องเราเอง
อยากแรกที่ต้องดูคือเมื่อมีการ request ดูว่ามี Connection: keep-alive หรือไม่ ถ้ามีแสดงว่าฝั่ง client ถูกต้องแล้ว ก็เหลือแต่ฝั่ง server ไปดูพวกไฟล์ image/css/javascript ว่ามีการตอบกลับ หรือไม่
ตัวอย่าง header google หน้าแรก จะเห็นว่ามีแต่การ keep-alive ที่ request เท่านั้นเพราะไม่เข้าข่ายไฟล์ที่ผมบอก
Code
Response Headersview source
Date Tue, 10 Jan 2012 01:42:09 GMT
Expires -1
Cache-Control private, max-age=0
Content-Type text/html; charset=UTF-8
Content-Encoding gzip
Server gws
Content-Length 15945
X-XSS-Protection 1; mode=block
X-Frame-Options SAMEORIGIN
Request Headersview source
Host www.google.co.th
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language th-th,th;q=0.8,en-us;q=0.6,en-gb;q=0.4,en;q=0.2
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection keep-alive
Cookie PREF=ID=f15fb5ffd5b1416b:U=3b88794bbbf91f3c:FF=0:TM=1326158418:LM=1326158435:S=lVSLAmqvoEFZPtUT; NID=55=dofJa35LOrV2CRUXU459240ZII0a1BnugtLjLzxKctGLs44Esbm5ufViQsUJf0ulRIHk4ySHSS9L8WcuELPD3lKYZhmMiX4oOjoJs12aSmgV_gMwV_O1bh7rTn4wrGl3
ตัวอย่าง header google ไฟล์ภาพ png แต่เป็น status 304 (Not Modified)
status 304 (Not Modified) ก็คือ ประมาณว่ามันไม่ได้มีอะไรเปลี่ยนแปลงก็ไม่จำเป็นต้องไปเรียก server ให้เรียกที่ตัวเอง หรือแค่ proxy server ก็พอ แบบนี้เรียกว่าการเก็บ cache นั่นเอง
Code
Response Headersview source
X-Content-Type-Options nosniff
Date Tue, 10 Jan 2012 01:50:26 GMT
Server sffe
X-XSS-Protection 1; mode=block
Request Headersview source
Host www.google.co.th
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1
Accept image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language th-th,th;q=0.8,en-us;q=0.6,en-gb;q=0.4,en;q=0.2
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection keep-alive
Referer http://www.google.co.th/
Cookie PREF=ID=f15fb5ffd5b1416b:U=3b88794bbbf91f3c:FF=0:TM=1326158418:LM=1326158435:S=lVSLAmqvoEFZPtUT; NID=55=dofJa35LOrV2CRUXU459240ZII0a1BnugtLjLzxKctGLs44Esbm5ufViQsUJf0ulRIHk4ySHSS9L8WcuELPD3lKYZhmMiX4oOjoJs12aSmgV_gMwV_O1bh7rTn4wrGl3
If-Modified-Since Mon, 05 Dec 2011 05:39:58 GMT
Cache-Control max-age=0
สุดท้ายคือ ไฟล์ภาพ png status 200 คือมีการเรียกไปยัง server แล้ว success จะเห็นว่า มี keep-alive ทั้งขาไปและกลับ
Code
Response Headersview source
Content-Type image/png
Last-Modified Wed, 28 Sep 2011 03:00:23 GMT
Date Sun, 08 Jan 2012 11:21:29 GMT
Expires Mon, 07 Jan 2013 11:21:29 GMT
X-Content-Type-Options nosniff
Server sffe
Content-Length 9760
X-XSS-Protection 1; mode=block
Cache-Control public, max-age=31536000
Age 138537
Connection keep-alive
Request Headersview source
Host ssl.gstatic.com
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1
Accept image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language th-th,th;q=0.8,en-us;q=0.6,en-gb;q=0.4,en;q=0.2
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection keep-alive
Referer http://www.google.co.th/
If-Modified-Since Wed, 28 Sep 2011 03:00:23 GMT
Cache-Control max-age=0
ผมแนะนำให้ไปหาอ่านกระบวนการทำงานของเว็บไซต์ตั้งแต่ มีการ request เกิดจาก client ไปจนถึงการ response กลับจาก server
ให้ศึกษา header แต่ละตัวว่ามีความหมายอย่างไร จะทำให้เราเข้าใจมันมากขึ้นครับ
|
 |
 |
 |
 |
Date :
2012-01-10 08:55:20 |
By :
kerb |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|