Differences between varnish pipe and pass

Source: Internet
Author: User

When learning varnish these two days and learning VCL, I don't understand the difference between pipe and pass and how to differentiate and apply it. After two days of searching, the concept was finally clarified. Now I will share my record with you on my blog.
When the vcl_recv function receives a request, it determines how to process the request. There are three scenarios:

 
Call the pass function to call data from the backend server. Call the lookup function to search for the response data from the cache and return the data. If no data is found, call the pass function to call the data from the backend server. Call the pipe function to establish a direct connection between the client and the backend server and call data from the backend server.

Here, I have a few questions:

 
What is the difference between pass and pipe when they fetch data from backend servers? Under what circumstances does pass and pipe be used? What data will be cached in varnish?

Before understanding these questions, you need to understand other concepts:
 

 
HTTP connection establishment process HTTP request type: Get post head

First, let's talk about the HTTP connection process (I only write down the rough section, because it is not the focus of this Article. For details, please check it online ):
 

When the browser wants to obtain a webpage content, such as entering www.google.com in the browser. Then, the browser starts to establish a connection with the server. Execute three handshakes to confirm the connection. Then, the browser sends a request. A webpage contains multiple content, parts, body, and HTML.Code, CSS code, and JS Code. In HTML 1.0, If you request a file, you need to establish a connection and request multiple connections. High overhead. In HTML 1.1, the persistent connection feature allows you to maintain connections during the Keep-live period. You can send multiple requests without establishing a connection during this period. When the request is completed or the Keep-live time reaches the limit, the connection is closed.

HTTP request type:
 
There are several types of HTTP requests:

 
Get: Request the specified page information and returns the Object Body. Head: only request the first part of the page. Post: The request Server accepts the specified document as a new subordinate object to the identified Uri.

 
To put it bluntly, a request for a static html page uses the get type. If you send a microblog on Sina Weibo, it is actually the post type.
In summary, get is the request URI and receives the returned data from the server. To receive data.
Post is used to send data to the server. The server must process the data accordingly. To send data.
 
If you understand the above, you can answer these three questions:

 
What is the difference between pass and pipe when they fetch data from backend servers? Under what circumstances does pass and pipe be used? What data will be cached in varnish?

Q: What is the difference between pass and pipe in retrieving data from backend servers? A: When vcl_recv calls the pass function, pass forwards the current request directly to the backend server. Subsequent requests are still processed through varnish. For example, after an HTTP connection is established, the client requests the.css file a.png in sequence. when the request is sent, the first request is sent. That is, a.css and a.css are directly forwarded to the backend server without being cached. The subsequent a.png will be processed by varnish, and how will varnishrefer to a.png. Summary: in addition to the current request in a connection, other requests are still processed by varnish normally. The pipe mode is different. When vcl_recv determines that the pipe function needs to be called, varnish will establish a direct connection between the client and the server, and then all client requests will be sent directly to the server, bypass varnish and do not check the request by varnish until the connection is disconnected.

 
Under what circumstances does pass and pipe be used? A: Pass generally only processes static pages. That is, the pass function is applicable only to get and head requests. In addition, you must note that the pass mode cannot process post requests. Why? Because post requests generally send data to the server, the server needs to receive data, process the data, and feedback the data. It is dynamic and not cached. The sample code is as follows: if (req. Request! = "Get" & Req. Request! = "Head") {return (PIPE);} under what circumstances should pipe be used? It can be seen from the above statement that pipe is used for post, but it may not be clear yet. For example, when a client requests a video file, a large file such as A. Zip. tar file needs to be written in pipe mode. These large files are not cached in varnish.

What data will be cached in varnish? A: varnish only caches static data. The varnish cache policy found on the internet can answer this question: the varnish cache policy defaults to the HTTP status code returned by the backend of the root region to determine whether to cache the cache. The status code that can be cached is as follows: 200 203 300 301 302 410 404 varnish currently does not support ranges requests, so 206 status results are not cached. The administrator can add his/her own Cache Policy to the vcl_fetch section of the VCL configuration file by modifying the beresp. cacheable variable. The following example shows that if a cookie is set in the backend response, the cache is not cached: Sub fetch {If (beresp. http. Set-cookie) {set beresp. cacheable = false ;}}

ReferenceArticle:

1. varnish configuration language-VCL (varnish configuration language-VCL): http://linuxguest.blog.51cto.com/195664/355220

2. varnish Cache Policy and Cache Time Calculation Method Description: http://blog.sina.com.cn/s/blog_5374d6e30100tupo.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.