Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Server \ High-performance open-source http accelerator Varnish introduce     - How wifi-linux AP signal strength detection (Linux)

- Windows 8.1 hard drive to install Ubuntu 14.04 dual system reference tutorials and multi-drive Precautions (Linux)

- PHP Performance Analysis and Experiment: Performance Micro Analysis (Programming)

- Zookeeper cluster deployment (Server)

- Use apt-p2p up a local Debian package cache (Server)

- Android development environment to build under Fedora 13 (Linux)

- Android Studio simple setup (Linux)

- SSH without password Definitive Guide (Linux)

- SQL Server 2012 failover looksalive check and is alive check (Database)

- The array of C language (Programming)

- Ubuntu users to install voice switch instructs the applet (Linux)

- CentOS 7.0 local address and configure yum source address priority (Linux)

- Getting Started with Linux system to learn: how to check in a package is installed on Ubuntu (Linux)

- Security implementation of disk data protection under Linux (Linux)

- Getting the Linux shell variable test (Programming)

- Encounter ORA-00600: internal error code, arguments: [4194] ORA-1552 (Database)

- Debian 7.7 Installation and Configuration (Linux)

- How to install the latest version of the Eclipse in Ubuntu 14.04 (Linux)

- Learning and Practice (Linux)

- Linux command -nohup & (Linux)

  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
- How to install and use the Snort in Ubuntu 15.04 (Linux)
- How to remove the files inside the privacy of data on Linux (Linux)
- Sturdy build secure Linux server (Linux)
- Android WebView use layman (Programming)
- Definition Format Oracle basis of various statements (Database)
- jobs command example (Linux)
- Ubuntu 14.04 Boot Repair (Linux)
- Linux scheduling summary (Linux)
- Red Hat Linux security settings document (Linux)
- Sublime Text - Opens the current file in a browser (Linux)
- CentOS 6.4 Telecom ADSL dial-up network configuration (Linux)
- php How to prevent being injected (Linux)
- Python virtual environment: Virtualenv (Linux)
- libreadline.so.6: can not open shared object file problem solution (Linux)
- Linux host dual LAN transceiver package ARP problem (Linux)
- Install Visual Studio Code in Ubuntu (Linux)
- Linux shell scripts bubble sort (Programming)
- Modify grub solve computer startup error: ERROR 17 (Linux)
- DDOS Attacks and Prevention (Linux)
- AngularJS notes --- Scope and controller (Programming)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.