PHP high concurrency high load system architecture

Source: Internet
Author: User
Tags apc php script hosting nginx server nginx reverse proxy

PHP high concurrency high load system architecture

1 , why research on high concurrency and high load

1.1, the need for product development

1.2, the needs of the company's development

1.3, the current form of decision

2 , high concurrency, and high load constraints

2.1. Hardware

2.2. Deployment

2.3. Operating system

2.4. Web Server

2.5. PHP

2.6. MySQL

2.7. Testing

3 , the way to solve -- Hardware Chapter

Improvement of processing capacity: Deploy multiple CPUs, choose Multi-core, with higher computing frequency, larger cache CPU;

The most direct response to the improvement of processing power is the efficiency of the processing of Web requests and the execution efficiency of PHP programs.

Memory bandwidth and Capacity: greater memory bandwidth and capacity;

The most direct response to the increase in memory bandwidth and capacity is to deal with large amounts of data exchange in the database.

Disk Search and I/O capability: Select higher rpm, larger HDD cache, component disk array (RAID);

The most direct response to the improvement of disk search and I/O capability is the large number of queries and reads and writes of the database.

The factors that can be taken into account include greater bandwidth, multi-line access, and exclusive bandwidth.

Server in the case of heavy load, the network bandwidth consumption is very considerable.

Strategy: Hardware facilities are the basis for coping with large loads, and the investment in hardware facilities can be based on actual pressure and budget.

4 , the way to solve -- Deployment Chapter

4.1. Server separation

4.2. Database cluster and library table hash

4.3. Mirror

4.4. Load Balancing

Classification:

1), DNS round robin

2) proxy Server load Balancing

3) Address Translation Gateway load Balancing

4) NAT Load Balancer

5) Reverse Proxy load Balancing

6) Hybrid load-balancing

Strategy: According to the hardware investment and business requirements, choose a reasonable deployment plan.

Deployment Scenario 1:

Scope of application: static content as the main web site and application system, high security requirements for the system of Web sites and applications.

Main server: Primary servers

The main body of the hosting program is under pressure to handle dynamic requests in the Web site or application system;

Push a static page to multiple publishers;

Push the attachment file to the file server;

High security requirements, static-based Web site, the server can be placed in the network of external shielding access.

DB Server: Database servers

Load database reading and writing pressure;

Data volume Exchange only with the primary server, shielding extranet access.

File/video server: File/video Server

The data flow which occupies the system resource and the bandwidth resource is larger in the bearer system;

Storage and reading and writing warehouses as large attachments;

As a video server will have the ability to automate video processing.

Publishing Server Group:

Only responsible for the release of static pages, hosting the overwhelming majority of Web requests;

Load balanced deployment via Nginx.

Deployment Scenario 2:

Scope of application: Web site or application system with dynamic interactive content as the main body; a website or application system with large load-pressure and sufficient budget;

Web server Group:

The Web service has no master-slave relationship and is a parallel redundancy design;

Load balancing via front-end load balancing device or nginx reverse proxy;

Partition dedicated file server/video server effective separation of light/heavy bus;

Each Web server can be connected to all databases via Dec, while dividing the master and slave.

Database server Group:

Relatively balanced load-carrying database reading and writing pressure;

The data synchronization of multiple databases is realized through the mapping of database physical files.

Shared disk/disk array

Unified Read and write for data physical files

Storage warehouse for large attachments

Ensure the overall system IO efficiency and data security through the equalization and redundancy of its own physical disk;

Scenario Features:

Through the front-end load balancing, the reasonable distribution of web pressure;

Through the separation of the file/video server and the regular Web server, the reasonable allocation of light and heavy data flow;

Through the database server group, the reasonable allocation database IO pressure;

Each Web server is usually connected to only one database server, through the DEC heartbeat detection, can be automatically switched to redundant database server in a very short period of time;

The introduction of disk array greatly improves the efficiency of system IO, and enhances the data security.

5 , the way to solve -- Environment Chapter

5.1. Operating system

The choice of operating system, the focus is

• Are you adapting to the environmental procedures required to build siteengine?

• The system itself occupies a resource ratio;

• system security;

• Is the system easy to operate?

Strategy: We choose FreeBSD, and it is minimized after the installation of FreeBSD.

5.2. Web server

A large portion of the Web server's resource footprint comes from processing Web requests, which is typically the stress that Apache generates, and Apache is the world's first Web server software to use. It can run on almost all of the widely used computer platforms.

In the case of high concurrent connection, Nginx is a good substitute for Apache server. Nginx ("Engine X") is a high-performance HTTP and reverse proxy server written by the Russians. In China, has Sina, Sohu Pass, NetEase news, NetEase Blog, Jinshan Carefree net, Kimshan word bully, Xiaonei, Yupoo album, Watercress, Thunder look at a number of websites, channels using Nginx server.

The advantages of Nginx:

High concurrent connections: The official test can support 50,000 concurrent connections, running in the actual production environment to the number of concurrent connections.

Low memory consumption: With 30,000 concurrent connections, the 10 nginx processes that are open consume 150M of memory (15m*10=150m).

Built-in Health check function: If a WEB server on the backend of Nginx proxy goes down, it will not affect the front-end access.

Strategy: Compared to the old Apache, we choose lighttpd and Nginx, which have smaller resource occupancy and higher load capacity of the Web server.

5.3. Mysql

MySQL itself has a very strong load capacity, MySQL optimization is a very complex task, because this ultimately requires a good understanding of system optimization. We all know that database work is a large number of short-term query and read and write, in addition to program development needs to pay attention to build indexes, improve query efficiency and other software development skills, from the perspective of hardware facilities to affect the efficiency of MySQL is mainly from the disk search, disk IO level, CPU cycles, memory bandwidth.

Perform MySQL optimizations based on the hardware and software conditions on the server. The core of MySQL optimization is the allocation of system resources, which is not equal to the unlimited allocation of more resources to MySQL. In the MySQL configuration file we introduce several of the most notable parameters:

Changing the index buffer length (key_buffer)

Change the length of the table (read_buffer_size)

Sets the maximum number of open tables (Table_cache)

Set a time limit for slow queries (Long_query_time)

If the conditions allow, the general MySQL server is best installed in the Linux operating system, rather than installed in FreeBSD.

Strategy: MySQL optimization requires different optimization scenarios based on the database read-write characteristics and server hardware configuration of the business system, and can deploy MySQL's master-slave structure as needed.

5.4. PHP

1, loading as few modules as possible;

2, if it is under the Windows platform, as far as possible to use IIS or Nginx to replace our usual Apache;

3, install the accelerator (all by caching the PHP code precompiled results and database results to improve the execution speed of PHP code)

Eaccelerator

Eaccelerator is a free open source PHP accelerator, optimized and dynamic content caching, improving the performance of PHP script cache performance, so that PHP script in the state of compilation, the cost of the server almost completely eliminated.

Apc

Alternative PHP cache (APC) is a free, publicly available, optimized code cache for PHP. It is used to provide free, open and robust architecture to cache and optimize PHP's intermediate code.

Memcache

Memcache is a high-performance, distributed memory object caching system developed by Danga Interactive for reducing database load and increasing access speed in dynamic applications. The main mechanism is to maintain a unified huge hash table in memory, memcache can be used to store data in various formats, including images, videos, files, and database retrieval results.

Xcache

The Chinese developed the cache,

Strategy: Install the Accelerator for PHP.

5.5. Proxy server (cache server)

Squid cache (squid) is a popular free software (GNU General Public License) proxy server and Web cache server. Squid has a wide range of uses, from caching related requests as Web server cache servers to increasing the speed of Web servers, to sharing network resources for a group of people and caching the World Wide Web, domain name systems and other network searches, to help network security by filtering traffic, to LAN through proxy Internet. Squid is primarily designed to operate on Unix-type systems.

Strategy: Install Squid reverse proxy server, can greatly improve server efficiency.

6 , the way to solve --siteengine article

7 , the way to solve -- Test Article

7.1. Test method

7.2. Test Cases

7.3. Pressure test

Stress testing is a basic quality assurance behavior that is part of every important software testing effort. The basic idea of stress testing is simple: not to run manual or automated tests under normal conditions, but to run tests with fewer computers or poor system resources. The resources that are typically used for stress testing include internal memory, CPU availability, disk space, and network bandwidth. Usually use concurrency to do stress testing.

Pressure test tools: webbench,apachebench, etc.

7.4. Vulnerability testing

The vulnerabilities in our system include: SQL injection vulnerability, XSS cross-site scripting attack, etc. Security aspects also include system software, such as operating system vulnerabilities, MySQL, Apache and other vulnerabilities, can generally be resolved through the upgrade.

PHP high concurrency High load system architecture

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.