PHP high concurrency and high load system architecture

Source: Internet
Author: User
Tags apc nginx reverse proxy
Applicability: websites or application systems with dynamic interaction content as the subject; websites or application systems with high load pressure and sufficient budget;

Why do we need to study high concurrency and high load?

2. high concurrency and high load constraints

3. Solution-hardware

4. Solution-deployment

5. Solution-Environment

6. Solution-SiteEngine

7. Solution-test

1. why high concurrency and high load?

1.1. product development needs

1.2. company development needs

1.3 determined by the current form

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 test

3. Solution-hardware

Improvement in processing capability: deploy multiple CPUs, and select multiple cores and CPUs with higher computing frequency and greater cache speed;

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

Memory bandwidth and capacity: larger memory bandwidth and capacity;

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

Disk search and I/O capabilities: select a higher speed, a larger hard disk cache, and a component disk array (RAID );

The most direct response to the improvement of disk search and I/O capabilities lies in the massive query and read/write of databases and the reading and writing of files.

Factors to consider for increasing network bandwidth include greater bandwidth, multi-line access, and exclusive bandwidth;

When the server is under heavy load, the network bandwidth usage is considerable.

Policy: hardware is the basis for dealing with large loads. the input of hardware can be based on actual pressure and budget.

4. Solution-deployment

4.1 server separation

4.2 Database Cluster and database table hash

4.3. images

4.4. server load balancer

Category:

1) DNS round robin

2) server load balancer for proxy servers

3) address translation gateway server load balancer

4) NAT server load balancer

5) reverse proxy server load balancer

6) hybrid load balancing

Policy: Select a reasonable deployment scheme based on hardware input and business needs.

Deployment Solution 1:

Applicability: websites and application systems with static content as the subject; websites and application systems with high system security requirements.

Main Server: Master Server

Processes dynamic requests from websites or application systems;

Push static pages to multiple publishing servers;

Push the attachment file to the file server;

Websites with high security requirements and static websites can place servers on the intranet to shield Internet access.

DB Server: database Server

Carry the database read/write pressure;

Only data volumes are exchanged with the master server to block Internet access.

File/Video Server: File/Video Server

Data streams that occupy a large amount of system resources and bandwidth resources in the system;

As a storage and read/write warehouse for large attachments;

As a video server, you can automatically process videos.

Release server group:

Only responsible for publishing static pages and carrying the vast majority of Web requests;

Deploy server load balancer using Nginx.

Deployment Solution 2:

Applicability: websites or application systems with dynamic interaction content as the subject; websites or application systems with high load pressure and sufficient budget;

Web server group:

The Web service has no master-slave relationship and belongs to the parallel redundancy design;

Server load balancer is achieved through the front-end server load balancer device or Nginx Reverse proxy;

Divides dedicated file servers/video servers to effectively separate light and heavy buses;

Each Web server can connect to all databases through DEC and divide the master and slave nodes at the same time.

Database Server Group:

Relatively balanced load on database read/write pressure;

Data is synchronized between multiple databases through the ing of physical database files.

Shared disk/disk array

Unified read/write of physical data files

Storage warehouse for large attachments

Ensure the overall system I/O efficiency and data security by balancing and redundancy of physical disks;

Solution features:

Use front-end server load balancer to rationally distribute Web load;

Rationally distribute light and heavy data streams by separating file/video servers from conventional Web servers;

Rationally allocate database I/O pressure through database server groups;

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

The introduction of disk arrays greatly improves the system I/O efficiency while greatly enhancing data security.

5. Solution-Environment

5.1 Operating System

The focus of operating system selection is

? Is it applicable to the environment programs required to build SiteEngine ?? Resource usage ratio of the system itself ;? System Security ;? Is the system easy to operate?

Policy: we select FreeBSD and minimize the number of FreeBSD instances after installation.

5.2. Web server

A large part of Web server resources are occupied by processing Web requests. Usually, this is the pressure generated by Apache. Apache is the world's top Web server software. It can run on almost all widely used computer platforms.

In the case of high-concurrency connections, Nginx is a good alternative to Apache servers. Nginx ("engine x") is a high-performance HTTP and reverse proxy server compiled by Russians. In China, many websites and channels such as Sina, Sohu pass, NetEase News, NetEase Blog, Kingsoft Xiaoyao network, Kingsoft aiqiba, intranet, YUPOO album, Douban, and Xunlei have used Nginx servers.

Nginx advantages:

High-concurrency connection: the official test can support 50 thousand concurrent connections and run to 2 ~ in the actual production environment ~ 30 thousand concurrent connections.

Less memory consumption: 30 thousand MB of memory (15 MB * 10 = 150 MB) is consumed for the 10 Nginx processes enabled under concurrent connections ).

Built-in health check: If a Web server on the Nginx Proxy is down, front-end access is not affected.

Policy: compared with the old Apache, we choose Lighttpd and Nginx web servers with lower resource usage and higher load capabilities.

5.3. Mysql

MySQL itself has a strong load capability. MySQL optimization is a very complicated task, because it ultimately requires a good understanding of system optimization. As we all know, database work involves a large amount of short-term queries and reads and writes. in addition to software development skills such as indexing and query efficiency improvement during Program Development, from the perspective of hardware facilities, the most important impact on MySQL execution efficiency is disk search, disk IO level, CPU cycle, and memory bandwidth.

MySQl is optimized based on the hardware and software conditions on the server. The core of MySQL optimization lies in the allocation of system resources, which does not mean allocating more resources to MySQL without limitation. In the MySQL configuration file, we will introduce several of the most noteworthy parameters:

Change the index buffer length (key_buffer)

Change the table length (read_buffer_size)

Set the maximum number of opened tables (table_cache)

Set a time limit for slow query (long_query_time)

If conditions permit, it is recommended that MySQL servers be installed in Linux instead of FreeBSD.

Policy: MySQL optimization requires different optimization schemes based on the database read/write characteristics of the business system and server hardware configuration, and the master/slave structure of MySQL can be deployed as needed.

5.4. PHP

1. load as few modules as possible;

2. on windows, use IIS or Nginx to replace Apache;

3. install the accelerator (cache php code pre-compilation results and database results to speed up php code execution)
EAccelerator

EAccelerator is a free and open source php accelerator. It optimizes and dynamically caches content, improves the cache performance of php scripts, and enables PHP scripts to be compiled, the server overhead is almost completely eliminated.

Apc

Alternative PHP Cache (APC) is a free and public PHP optimized code Cache. It is used to provide free, public, and robust architectures to cache and optimize PHP intermediate code.

Memcache

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

Xcache

Caches developed by Chinese people,

Policy: install the accelerator for PHP.

5.5 proxy server (cache server)

Squid Cache (Squid for short) is a popular free software (GNU General Public License) proxy server and Web Cache server. Squid has a wide range of uses, from cache-related requests as front cache servers of Web servers to improving the speed of Web servers, to cache the World Wide Web for a group of people to share network resources, domain Name System and other network search, to help network security by filtering traffic, to the LAN through the proxy to access the Internet. Squid is designed to run in Unix systems.

Policy: install the Squid reverse proxy server to greatly improve server efficiency.

6. Solution-SiteEngine

7. Solution-test

7.1 test method

7.2 test cases

7.3. stress testing

Stress testing is a basic quality assurance behavior and is part of every important software testing task. The basic idea of stress testing is simple: it is not to run manual or automatic testing under normal conditions, but to run the test under the condition of a small number of computers or a lack of system resources. Generally, resources for stress testing include internal memory, CPU availability, disk space, and network bandwidth. Concurrency is generally used for stress testing.

Stress testing tools: webbench, ApacheBench, etc.

7.4 vulnerability testing

Vulnerabilities in our system include SQL injection and xss cross-site scripting. Security also includes system software, such as operating system vulnerabilities, mysql, apache, and other vulnerabilities, which can be solved by upgrading.

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.