Knowledge points for architecture of high-performance Web sites

Source: Internet
Author: User
Tags connection pooling execution html form php framework web services smarty template zend framework advantage

Objective:

For the architecture of high-performance Web sites are very interested in, this article from a few points on the high performance of web sites to consider the problem.

HTML static

What is HTML static?

To put it simply, change the pages that are not. htm or. html to. htm or. html

1. Pure static page

When the user access is, do not need to be resolved by the server, directly can be transmitted to the client, this type of page, because do not need to resolve the direct access, under normal circumstances, faster than the execution of dynamic pages.

2. Static

Page static is a dynamic Web site to create static Web site to save. This is a real HTML file, which is a static page.

3. Pseudo-static method (URL static)

Pseudo-Static is not a real static, it is only the use of some way to access the path that is the URL address translation into the. html suffix file, but in fact, the file itself is still in the original suffix saved on the server.

The advantages of HTML statics

First, reduce the server burden.

Second, conducive to search engine optimization Seo,baidu, Google will be a priority to include static pages, not only included in the fast also included the whole;

Third, speed up the page opening speed, static pages do not need to connect the database to open faster than dynamic pages have significantly improved;

Iv. HTML pages will not be affected by program-related vulnerabilities

html static templates in PHP

The famous Smarty template is a good HTML static template, Smarty The advantage is fast, efficient caching and HTML static, template separation

MVC Development Model

MVC is the abbreviation for three words: Model, view, and control controller, respectively.

MVC is a design pattern that makes it mandatory to separate the input, processing, and output of an application. The MVC application is divided into three core components: models, views, controllers. Each of them handles its own task.

View

A view is an interface that users see and interact with. For older Web applications, views are an interface of HTML elements, and in new Web applications, HTML still plays an important role in view, but some new technologies are emerging, including Macromedia Flash and Elephant xhtml,xml/xsl , WML, and some other identity languages and Web services.

How to handle the interface of an application is becoming more and more challenging. One big advantage of MVC is that it can handle many different views for your application. There is actually no real processing happening in the view, whether the data is stored online or an employee list, which, as a view, is just a way of outputting data and allowing the user to manipulate it.

Model

The model represents enterprise data and business rules. In the three parts of MVC, the model has the most processing tasks. For example, it might use a Widget object such as EJBS and ColdFusion components to process the database. The data returned by the model is neutral, that is, the model is independent of the data format, such that a model can provide data for multiple views. Because the code applied to the model can be reused by multiple views only once, it reduces the duplication of the code.

Controller

The controller accepts input from the user and invokes the model and view to fulfill the user's needs. So when you click a hyperlink in a Web page and send an HTML form, the controller itself does not output anything or do anything with it. It simply receives the request and decides which model widget to call to process the request, and then determines which view to use to display the returned data.

MVC Benefits:

Low coupling

High degree of reusability

Efficient deployment, lower development cycles

Maintainability

The management of Rational Software engineering

The better MVC framework in PHP:

Zend Framework PHP Official frame

thinkphp Domestic Frame

Yii Efficient Secondary lightweight framework

............

Picture Server separation

Reason analysis: For a non-video category of the site, the picture is generally the most consumption of resources, this time should consider the picture and page separation, that is, independent picture server.

Above is the classic lamp frame composition, in the lamp architecture, when the traffic is very large, the Apache server's shortcomings are exposed,

Nginx can be used to load non-PHP Web requests, using Nginx high-performance http and reverse proxy server as a stand-alone server for static resources to ensure system consumption and execution efficiency.

Caching technology

Lamp Cache Diagram

From the diagram we can see that the site cache is divided into five main parts:

1. Server caching: Static server Nginx and squid, mainly based on web reverse proxy, and apache2 mod_proxy and Mod_cache modules

2. Browser caching: Caching of resources, including page HTML caching and picture JS,CSS

3.PHP cache: There are a lot of free PHP buffer acceleration tools, such as APC, Eaccerlertor, etc.

4. Memory cache: Mainly using memcached as a distributed caching mechanism

5. Database caching: By configuring database caching, as well as data stored procedures, connection pooling technologies, etc.

Caching the Golden rule: keep the data closer to the CPU.

CPU-->CPU cache--> Level two cache--> memory--> hard Drive-->lan-->wan

Database clusters and library table hashes, and so on

I'm not dabbling in this. You can refer to the database processing method in the Youku architecture:

Http://www.3lian.com/edu/2011/10-26/13688.html

Load Balancing

Load balancing will be the ultimate solution for large web sites to address high load access and a large number of concurrent requests.

Advantages

(1) To solve the problem of network congestion, provide services near, to achieve geographical independence;

(2) To provide users with better access quality;

(3) Improve the response speed of the server;

(4) Improve the utilization efficiency of server and other resources.

Web server solution in PHP

For the webserver load balancing of PHP,

The balanced strategy of Apache

Proxypass directives

Description

Map a remote server to the URL space of the local server

Grammar

Proxypass [path]! |url [Key=value key=value ...]]

Scope

Server config, virtual host,directory

Module

Mod_proxy

This directive allows you to map a remote server to the URL space of the local server, where the local server does not act as a proxy role, but instead acts as a mirror image of the distant server. Path is a local virtual pathname, which is a partial URL to a remote server and does not allow the query string to be included.

When the proxypass instruction is used, the proxyrequests instruction should normally be set to off.

Suppose the local server address is: http://example.com/, then,

proxypass/mirror/foo/http://backend.example.com/

Will cause local requests for Http://example.com/mirror/foo/bar to be converted internally to a proxy request: Http://backend.example.com/bar.

More detailed description can refer to: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

Three balanced load strategies for Apache: http://s456123123b.blog.163.com/blog/static/5632332220101080474642/

Load balancing of Nginx

HTTP upstream module, which provides a simple load balancing (round robin and client IP) for back-end servers.

Example:

Upstream Backend {

Server backend1.example.com weight=5;

Server backend2.example.com:8080;

Server Unix:/tmp/backend3;

} server {

Location/{

Proxy_pass Http://backend;

}

}

Official information: Http://wiki.nginx.org/NginxChsHttpUpstreamModule

Front page optimization

Front End Optimization principle

· Bandwidth

O using CDN

o compression js, css, picture optimization

· HTTP optimization

O Reduced STEERING

o Reduce the number of requests

O Cache

O Early Flush

O using gzip

o Reduce cookies

O using Get

· DNS optimization

o Reduce Domain name resolution time

o Increased domain name increase concurrency

· Javascript

O put the bottom of the page

o Defer/async

· Css

O Put the page head

O Avoid @import

· Other

o Pre-loading

Summarize:

Front-End optimization----HTML static-----PHP framework (MVC IDEA)----database cluster and library table------Image Server separation----load balancing

Plus one: a consistent caching technique, which is the basic approach, but it's not easy to get them to the high aggregation low coupling state.

Original address: Php Huaibei

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.