Knowledge about Constructing High-Performance WEB websites

Source: Internet
Author: User
Tags php framework smarty template zend framework nginx load balancing

Knowledge about Constructing High-Performance WEB websites


Preface:

Everyone is very interested in Constructing High-Performance web websites. This article will discuss the issues that need to be considered for high-performance web websites from some rough points.

 

What is HTML static?

To put it simple, simply change all the pages of .htm).html to .htm).html.

1. Pure Static Page

When a user accesses a webpage, it can be directly transmitted to the client without being parsed by the server. This type of page can be accessed directly without parsing. Generally, faster than dynamic pages.

2. Static

Static pages are saved by combining static and dynamic pages to generate static websites for dynamic websites. This is a real HTML file, that is, a static page.

3. pseudo-static method (static Url)

The pseudo-static state is not a real-sense static state. It only applies to converting the original URL address into a file with the suffix .html. However, the file itself is saved on the server with the original suffix.

Advantages of static HTML

1. reduce the burden on servers.
2. It is conducive to seo optimization by search engines. Both Baidu and Google will give priority to static pages, not only quick but also full;

3. Speed up page opening. Static pages do not need to be connected to databases. The speed of opening is significantly higher than that of dynamic pages;

4. HTML pages are not affected by program vulnerabilities

Static html templates in PHP

The famous smarty template is a good html static template. The advantage of smarty is that it is fast, efficient cache and html static, and template separation.

MVC development mode

 

MVC is the abbreviation of three words: Model, View, and control Controller)

MVC is a design pattern that forcibly separates the input, processing, and output of an application. MVC applications are divided into three core components: model, view, and controller. They process their own tasks.

View

A view is the interface on which the user sees and interacts with it. For older Web applications, a view is an interface composed of HTML elements. In New Web applications, HTML still plays an important role in the view, however, some new technologies have emerged, including Macromedia Flash and some identification languages such as XHTML, XML/XSL, and WML and Web services.

How to process the application interface becomes increasingly challenging. One major benefit of MVC is that it can process many different views for your applications. In fact, there is no real processing in the view. Whether the data is stored online or an employee list, as a view, it is just a way to output data and allow users to manipulate it.

Model

The model represents enterprise data and business rules. Among the three components of MVC, the model has the most processing tasks. For example, it may use component objects such as EJBs and ColdFusion Components to process databases. The data returned by the model is neutral, that is, the model has nothing to do with the data format, so that a model can provide data for multiple views. Because the Code applied to the model can be reused by multiple views only once, code duplication is reduced.

Controller

The Controller accepts user input and calls models and views to fulfill user requirements. Therefore, when you click a hyperlink on a Web page and send an HTML form, the controller does not output anything or process anything. It only receives the request and determines which model component is called to process the request, and then determines which view is used to display the returned data.

Advantages of MVC:

Low Coupling

High reusability

Efficient deployment to reduce the development cycle

Maintainability

Rational Software Engineering Management

Php mvc framework:

Official Zend framework PHP framework

Domestic ThinkPHP framework

Yii efficient secondary Lightweight Framework

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

 

Image server Separation

 

Cause Analysis: For a non-video website, images consume the most resources. In this case, we should consider separating images from pages, that is, independent image servers.

The above is a classic LAMP architecture diagram. In the LAMP architecture, when traffic is high, the shortcomings of the apache server are exposed. nginx can be used to load non-PHP Web requests, nginx, a high-performance HTTP and reverse proxy server, is used as an independent server for static resources to ensure system consumption and execution efficiency.

Cache Technology

LAMP cache Diagram

We can see that the website cache is mainly divided into five parts:

  1. Server cache: mainly static servers nginx and squid Based on Web reverse proxy, mod_proxy and mod_cache modules of apache2
  2. Browser cache: Includes page HTML cache and image JS, CSS, and other resource cache.
  3. PHP cache: There are many free PHP buffer acceleration tools, such as APC and eaccerlertor.
  4. Memory Cache: memcached is used for Distributed caching.
  5. Database cache: You can configure the database cache, data storage process, and connection pool technology.

Cache Gold principle:Bringing data closer to the CPU.

CPU--> CPU Level 1 cache --> Level 2 Cache --> memory --> hard disk --> LAN --> WAN
Database Cluster and database table hash

I am not involved in this point can refer to the database processing methods in the Youku network architecture http://www.itivy.com/ivy/archive/2011/8/13/the-architecture-of-youku.html

 

Server Load balancer

Server Load balancer is the ultimate solution for large websites to solve high-load access and a large number of concurrent requests.

Advantages

(1) solves network congestion issues and provides nearby services to achieve geographic location independence;

(2) providing users with better access quality;

(3) Improve server response speed;

(4) Improve the efficiency of using servers and other resources.

Web server solution in PHP

For PHP webserver load balancing,

  • Apache balancing policy
ProxyPass command

Description
Map a remote server to the URL of the local server.

Syntax
ProxyPass [path] !|url [key=value key=value ...]]

Scope
Server config, virtual host, directory

Module
Mod_proxy

This command allows you to map a remote server to the URL space of the local server. In this case, the local server does not act as a proxy, but acts as an image of the remote server.PathIs a local virtual path name,URLIs a part of the URL pointing to the remote server and cannot contain query strings.

When usingProxyPassCommand,ProxyRequestsCommands should generally be set
Off.

Assume that the local server address is:http://example.com/, So,

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

Will causehttp://example.com/mirror/foo/barThe local request will be converted into a proxy request internally:http://backend.example.com/bar.

For more detailed description, see: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

Three Load Balancing policies for Apache: http://s456123123b.blog.163.com/blog/static/5632332220101080474642/

  • Nginx Load Balancing

HTTP upstream module, which provides simple Load Balancing (round robin scheduling and Client IP) for backend 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: http://wiki.nginx.org/NginxChsHttpUpstreamModule

An example of a banquet blog: http://blog.s135.com/post/306/

Technorati label:
High-performance architecture Youku architecture server nginx apache

This article is based on the signature-non-commercial use
3.0 release of the license agreement. You are welcome to repost and interpret it. However, the signature of this article, PHP Huaibei (including links), must be retained and cannot be used for commercial purposes. If you have any questions or negotiation with the Authority, please contact me.

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.