Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Server \ High-performance open-source http accelerator Varnish introduce     - MySQL5.6.17 compiler installation under CentOS (Database)

- Ubuntu 14.04 Trusty Tahr User How to install Banshee 2.9.1 (Linux)

- Gitlab installation under CentOS 7 (Linux)

- Spring use Cache (Programming)

- Upgrading from Fedora 20 to 21 (Linux)

- AngularJS asynchronous service testing and Mocking (Programming)

- Three binary tree traversal (recursive, non-recursive traversal and Morris) (Programming)

- Linux System Getting Started Learning: The Linux log (Linux)

- Python cause yum upgrade error (Linux)

- Linux, how to filter, split, and merge pcap file (Linux)

- Spring Data JPA call a stored procedure examples (Programming)

- The difference between equals and == in Java (Programming)

- Android Studio Installation and Configuration Guide tutorial (Linux)

- SSH without password (Linux)

- How SSHfs mount a remote file system on Linux (Linux)

- Linux / Unix: chroot command examples to explain (Linux)

- Construction CA certificate using OpenSSL command line (Server)

- Linux based serial programming (Programming)

- Spring Boot + Nginx + Tomcat + SSL configuration notes (Server)

- Hadoop configuration ssh automation of automation (Server)

  High-performance open-source http accelerator Varnish introduce
  Add Date : 2018-11-21      
1, varnish profile
Varnish is a high-performance open source HTTP accelerator, it is more stable than Squid, and more efficient, less resource consumption. I believe in the reverse proxy, web acceleration, varnish has sufficient capacity to replace squid. Norway's largest online newspaper Verdens Gang uses three Varnish instead of the original 12 Squid, better performance than before.
Second, Varnish structure and characteristics
Varnish is a lightweight Cache and reverse proxy software, advanced design concepts and mature design framework is the main features of Varnish, Varnish is not a total amount of code, although the function of continuous improvement, but also need to continue to enrich And strengthening. The following summarizes some of Varnish's features:
(1) is based on the memory cache, after the restart the data will disappear.
(2) the use of virtual memory, io performance.
(3) Support to set the precise caching time in 0 ~ 60 seconds.
(4) VCL configuration management more flexible.
(5) 32-bit machine cache file size is the largest 2G.
(6) has a strong management capabilities, such as top, stat, admin, list and so on.
(7) state machine design clever, clear structure.
(8) the use of binary heap management cache files, to achieve the purpose of active deletion.

Third, varnish system architecture
Varnish mainly run two processes: Management process and Child process (also called Cache process).
Management process is mainly to achieve the application of the new configuration, compile VCL, monitor varnish, initialization varnish and provide a command line interface. The Management process will probe the Child process every few seconds to see if it is working properly. If the child process does not respond within a specified amount of time, Management will restart the Child process.
Child process contains multiple types of threads, common such as:
Cache-main thread: there is only one global, used to start the cache;
Acceptor thread: receive a new connection request and response;
Worker thread: The child process starts a worker thread for each session, so there may be hundreds of worker threads or even more in a high-concurrency scenario;
Expiry thread: from the cache to clean up the expired content;
Backend poll thread: one for each back-end server, used to detect the health of the back-end server;
Epoll / kqueue Thread: the number of configurable, the default is 2, for the management of thread pool
In the configuration of varnish, generally only concerned about the cache-worker thread, and can only configure the number of its thread pool, while the other non-configurable parameters. At the same time, the number of thread pool can only be in the flow of large scenes only need to increase, and experience shows that more than two to enhance performance and no benefit.

IV, Varnish installation
Since I use the system RHEL5.8, so before installing varnish, you need to install the following packages:
Automake, autoconf, libtool, ncurses-devel, libxslt, groff, pcre-devel, pkgconfig
# Yum -y install * .rpm
Compile and install varnish
# Tar xf varnish-2.1.3.tar.gz
# Cd varnish-2.1.3
# ./configure --prefix = / usr / loca / varnish

# Make && make install

Provide a configuration file for varnish
Copy varnish's default configuration file to / etc / sysconfig / varnish
# Cp /usr/local/varnish/etc/varnish/default.vcl / etc / sysconfig / varnish
Create a working directory for Varnish users and Varnish
# Useradd -s / sbin / nologin varnish
#mkdir / web / cache
#chown -R varnish: varnish / web / cache

In the case of varnish version 2.0, it is necessary to specify the back-end server address for varnish before starting varnish, so we need to edit the varnish configuration file to specify the back-end server address.
# Vim / etc / sysconfig / varnish
Add the following information:
Backend default {
    .host = "";
    .port = "80";
V., varnish start and stop
# / Usr / local / varnish / sbin / varnishd -f / etc / sysconfig / varnish -s malloc, 200M -T -a
-f: Specifies the configuration file for varnish
-s: Specifies the storage type and storage capacity of varnish
-T: Specifies a management interface based on this article, can be used to stop the case of varnish to manage varnish
-a: Specifies the socket to listen on
Check whether varnish is started successfully
# Netstat -tunlp | grep varnish
Tcp 0 0* LISTEN 18684 / varnishd
Tcp 0 0* LISTEN 18683 / varnishd
8080 for Varnish listening port, 2000 for the Varnish telnet-based management port.

To stop Varnish, use the following command
# Killall varnishd
VI, Varnish binary program files
After the installation of Varnish, will generate a number of binary program files, common commands are:
/ Usr / local / varnish / sbin / varnishd: This Varnish startup command, the most important
/ Usr / local / varnish / bin / varnishadm: can be used to control the management of Varnish examples. Such as deleting a cache object
/ Usr / local / varnish / bin / varnishlog: Display Varnish log information
/ Usr / local / varnish / bin / varnishncsa: This command can also display Varnish log information, but this command shows the log information format is somewhat similar to the apache combine format output log.
/ Usr / local / varnish / bin / varnishstat: Displays Varnish's cache information
VII, varnishd instruction
The startup command for varnishd is the / usr / local / varnishd / sbin / varnisd command. This command has a number of parameters. You can use / usr / local / varnish / sbin / varnishd -h to view detailed information about the parameters. Commonly used parameters are:
-a address: port: Specifies the socket that Varnish listens on
-b address: port: Specifies the back-end server address and its listening port
-d: Debug debug mode
-f file: Specifies the Varnish configuration file
-P file: Specifies the Varnish pid file
-p param = value: Specifies the server parameters used to optimize Varnish performance
-n dir: Specifies the working directory of Varnish
-s kind [, storageoptions]: Specifies the way Varnish backends are stored. Common back-end storage methods are:
        -s malloc, -s file, < dir_or_file>, < size>. Note that 32-bit operating system, Varnish maximum support only 2G capacity storage.
-t: Specifies the default value of ttl
-T address: port: Set Varnish's telnet-based management address and its port
-V: Specifies the Varnish version number
-w int [, int [, int]]: Specifies the number of worker threads for Varnish. The configuration is as follows:
                  -w < fixed_count>
        -w min, max
        -w min, max, timeout [default: -w2,500,300]

How does Varnish record data?
Varnish a more notable feature is how it records data, varnish all the data will be all recorded to memory, when all the memory after use, and start from scratch, covering the oldest records. As a result, you can record data quickly and do not take up disk space. However, once the server down, then the memory of all the data will be released.
Nine, varnishlog instruction
Varnish provides a number of tools to view the data in memory, where I only say varnishlog application
Execute the varnishlog command on the command line, and the result is as follows:
  17 RxHeader c Accept-Encoding: gzip, deflate
  17 RxHeader c Host:
  17 RxHeader c Connection: Keep-Alive
  17 VCL_call c recv
  17 VCL_return c lookup
  17 VCL_call c hash
  17 VCL_return c hash
Where the first column is an arbitrary number, which is used to define the request, and the same number represents the same HTTP transport.
The second column is the information tag, all the logs with a tag (tag), marking the relative operation of the corresponding. Rx said varnish received data, Tx said varnish send data.
The third column represents where the data came from or passed in, whether from c (client) or b (backend).
The fourth column is the data to be recorded.
Varnishlog also has a number of sub-options:
-b: only show the log between varnish and backend server, when you want to optimize the hit rate when you can use this parameter.
-c: and-b almost, but it represents the client and the French-language communication.
-i tag: Displays only information about a tag. For example, "varnishlog -iSessionOpen" will only show the new session. Note that the tag name is not case-sensitive.
-I: filter through the regular expression data, such as "varnishlog-c-i RxHeader-I Cookie" will display all received from the client, including the Cookie word header information.

Ten, varnishstat instruction
The binary program for varnishstat is / usr / local / varnish / bin / varnishstat. Cache hit rate directly illustrates the running state and effect of varnish, a higher cache hit rate shows the good running state of varnish, web server performance will increase a lot, on the contrary, low cache hit rate that varnish configuration may There is a problem, then need to be adjusted, so the overall understanding of varnish hit rate and cache status, for the optimization and adjustment varnish is essential.
Use the / usr / local / varnish / bin / varnishstat command to view Varnish's cache status information. Such as:
# / Usr / local / varnish / bin / varnishstat
Hitrate ratio: 1 1 1
Hitrate avg: 0.5294 0.5294 0.5294
          18 0.00 0.01 Client connections accepted
          17 0.00 0.01 Client requests received
          9 0.00 0.00 Cache hits
          8 0.00 0.00 Cache misses
          8 0.00 0.00 Backend conn. Success
          8 0.00 0.00 Fetch with Length
          11. N struct sess_mem
          1. N struct objectcore
          1. N struct objecthead
          1. N struct smf
          1. N large free smf
          10. N worker threads
          10 0.00 0.00 N worker threads created
          N backends
          8. N expired objects
          8. N LRU moved objects
          10 0.00 0.00 Objects sent with write
          18 0.00 0.01 Total Sessions
          17 0.00 0.01 Total Requests
Among the more important parameters are:
Client connections accepted: Indicates the number of connections accepted
Client requests received: indicates the total number of requests received. If a long connection is used, the value is generally greater than the Client connections accepted value
Cache hits: Indicates the number of hits
Cache misses: Indicates the number of misses
N struct objectcore: indicates the number of objects to be cached
N expired objects: Indicates the number of expired cache objects
N LRU moved objects: Indicates the number of cached objects to be discarded
- Kibana use installation (Linux)
- Linux RPM (Linux)
- Common Linux system performance monitoring command (Linux)
- Use regular expressions to check whether the input box to enter a URL (Programming)
- How to set IonCube Loaders in Ubuntu (Linux)
- Process safety monitoring and protection under the Linux operating system (Linux)
- SQLite (Database)
- The wrong in Linux: too many open files (Linux)
- How to install Hadoop on CentOS7 (Server)
- To batch create users under Linux (Linux)
- SSH configuration under Linux (Linux)
- LVS + Keepalived the DR mode (Server)
- RHEL 5.7 Yum configure local source [Errno 2] No such file or directory (Linux)
- Linux Task Scheduler (at, crontab) (Linux)
- MySQL master recovery from failure using binlog (Database)
- Oracle create user authorization and in PLSQL (Database)
- Oracle 11g 10g induced into error (Database)
- Lenovo E431 notebook CentOS system is installed wireless network card driver (Linux)
- How to Install Sticky Notes on Ubuntu and Derivatives (Linux)
- Vim custom color (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.