Varnish acceleration website Image Display

Source: Internet
Author: User
Tags riak varnish

Since the dynamic generation of thumbnails went live, NFS client logs often reported an error that could not be responded. I suspect that the NFS machine Io is too large, so I wanted to use varnish to decompress the NFS machine and store the thumbnails in the memory, reduce the read pressure, and then there will be a blog post. Summary: varnish is a high-performance open-source HTTP accelerator. It is rated more powerful than squid on the Internet, and the installation and configuration are fast and convenient.
1. installation:

# Wget http://repo.varnish-cache.org/source/varnish-2.1.5.tar.gz
# Tar zxvf varnish-2.1.5.tar.gz CD Varnish-2.1.5
#./Configure-Prefix =/usr/local/Varnish
# Make & make install

Ii. configuration file:

# Cp/usr/local/Varnish/etc/Varnish/Default. VCL/usr/local/Varnish/etc/Varnish/Default. VCL. Bak
# Vi/usr/local/Varnish/etc/Varnish/Default. VCL

# Backend Web Server IP address and port of the reverse proxy request
Backend default {
. Host = "192.168.1.1 ";
. Port = "80 ";
}

Sub vcl_recv {
If (req. Request! = "Get" & Req. Request! = "Head "){
Return (PIPE );
} Elseif (req. url ~ "\. (JPG | GIF | PNG) $ "){
Return (lookup );
} Else {
Return (PASS );
}
}

Sub vcl_pipe {
Return (PIPE );
}

Sub vcl_pass {
Return (PASS );
}

Sub vcl_hash {
Set Req. Hash + = Req. url;
If (req. http. HOST ){
Set Req. Hash + = Req. http. Host;
} Else {
Set Req. Hash + = server. IP;
}
Return (hash );
}

Sub vcl_hit {
If (! OBJ. cacheable ){
Return (PASS );
}
Return (deliver );
}

Sub vcl_miss {
Return (FETCH );
}

Sub vcl_fetch {
If (beresp. http. Pragma ~ "No-Cache" |
Beresp. http. cache-control ~ "No-Cache" |
Beresp. http. cache-control ~ "Private "){
Return (PASS );
}
# Clear the cookie and set the expiration time to 30 days
If (req. Request = "get" & Req. url ~ "\. (JPG | GIF | PNG) $ "){
Unset Req. http. Cookie;
Set beresp. TTL = 30d;
}
Return (deliver );
}

Sub vcl_deliver {
# Add an identifier (which can be viewed using firebug) x-hits to indicate whether it is hit
Set resp. http. X-hits = obj. Hits;
If (obj. Hits> 0 ){
Set resp. http. X-Cache = "H ";
} Else {
Set resp. http. X-Cache = "M ";
}
}

Iii. startup:

#/Usr/local/Varnish/sbin/varnishd-F/usr/local/Varnish/etc/Varnish/default. VCL-N/var/log/Varnish-s malloc, 15g-W 2000, 51200, 20-T 127.0.0.1: 8080-A 0.0.0.0:

Note:
-F configuration file path
-N main directory
-S allocates 15 GB of memory
-Minimum and Maximum number of W threads
-T manages IP addresses and ports. You can use Telnet 127.0.0.1 2000 to manage varnish.
-A listens to port 8080

4. Write log files:

#/Usr/local/Varnish/bin/varnishncsa-N/var/log/Varnish-W/var/log/Varnish/varnish. Log

5. View zookeeper:

#/Usr/local/Varnish/bin/varnishstat-N/var/log/Varnish

Vi. About varnish:

# Pkill varnishd

7. Clear the inventory:

1. Clear the specified domain name:

/Usr/local/Varnish/bin/varnishadm-T 127.0.0.1: 2000 purge "Req. http. Host ~ Statics.xxx.com.tw"

2. Clear all the caches in the image directory:

/Usr/local/Varnish/bin/varnishadm-T 127.0.0.1: 2000 URL. Purge/image/

3. Clear all caches:

/Usr/local/Varnish/bin/varnishadm-T 127.0.0.1: 2000 URL. Purge * $

8. test:
AB test:
AB-C 100-N 1000 http://x.x.x.x/129974432673506402_128x92.jpg
Before varnish is used:

Server Software: nginx
Server Hostname: x. x
Server port: 8000

Document path: 129974432673506402_128x92.jpg
Document length: 2443 bytes

Concurrency level: 100
Time taken for tests: 0.667390 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 2730000 bytes
HTML transferred: 2443000 bytes
Requests per secondd: 1498.37 [#/sec] (mean)
Time per request: 66.739 [MS] (mean)
Time per request: 0.667 [MS] (mean, internal SS all concurrent requests)
Transfer Rate: 3994.67 [Kbytes/sec] canceled ed

Connection times (MS)
Min mean [+/-SD] median Max
Connect: 0 0 0.6 0 4
Processing: 2 61 23.2 57 248
Waiting: 1 60 23.2 57 247
Total: 2 61 23.1 58 248

Percentage of the requests served within a certain time (MS)
50% 58
66% 65
75% 73
80% 77
90% 89
95% 100
98% 116
99% 139
100% 248 (longest request)

After varnish is used:

Server Software: nginx
Server Hostname: p2.591.com.tw
Server port: 8000

Document path: 129974432673506402_128x92.jpg
Document length: 2443 bytes

Concurrency level: 100
Time taken for tests: 0.271769 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 2795675 bytes
HTML transferred: 2445443 bytes
Requests per secondd: 3679.60 [#/sec] (mean)
Time per request: 27.177 [MS] (mean)
Time per request: 0.272 [MS] (mean, internal SS all concurrent requests)
Transfer Rate: 10045.30 [Kbytes/sec] canceled ed

Connection times (MS)
Min mean [+/-SD] median Max
Connect: 0 6 2.3 6 12
Processing: 1 7 2.3 7 17
Waiting: 1 6 2.1 7 15
Total: 3 13 1.7 14 23

Percentage of the requests served within a certain time (MS)
50% 14
66% 14
75% 14
80% 14
90% 15
95% 15
98% 16
99% 17
100% 23 (longest request)

Summary:
After varnish went online, after observing for a while, we found that the NFS error cause has not been improved. Now we have switched the generated image part to NFS, and fewer NFS errors are reported. Next, switch to a Gigabit Switch.

Exam:
Varnish cache + Riak
Http://blog.dloh.org/2011/01/varnish-cache-riak.html)
Installation and configuration of varnish cache reverse proxy server and HTTP accelerator
Http://blog.51yip.com/cache/618.html)
Varnish hands
Http://www.varnish-cache.org/docs/2.1/tutorial/vcl.html)
Varnish installation process details
(Http://thinkgroupon.com/redirect.php? Tid = 3872 & goto = lastpost)
Use varnish to replace squid for detailed solution of website cache accelerator [original]
Http://blog.s135.com/post/313)
Summary of varnish usage
Http://iyubo.blogbus.com/logs/35085709.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.