Large Web site Technology architecture: abstract and Reading notes

Source: Internet
Author: User
Tags failover website performance

Spent a few nights after reading the "Large Web site Technology architecture" This book, the individual feel the breadth of the book is OK, the depth of some lack (after all, only about 200 pages). But as a lack of large-scale web site technology of IT workers, read it again is very rewarding, at least for a website technology evolution, need to solve the problem has a comprehensive understanding. The article also has some author's personal experience, sentiment, summary, I think it is very pertinent.

In the online search, the book's reading notes are still a lot of, and I still decided to write a reading notes, mainly to avoid forgetting too quickly. The contents of the notes are not exactly according to the contents of the original book, the main record is my own interest in the part.

This address: http://www.cnblogs.com/xybaby/p/8907880.html

The evolutionary history of a website

The author repeatedly mentions the idea that large Web sites evolve from business requirements, rather than design .

Have to admit that the development of the Internet industry today, feeding frenzy is still very common, the micro-innovation ability of large companies can die a small project in minutes, so small companies need to develop fast enough, continuous rapid iteration and trial and error.

The following is an evolutionary process, with images coming from the web.

Initial phase of the site architecture

In the initial phase, the traffic is not large, so all resources such as applications, databases, files, etc. are on one server.

Application Service and Data service separation

With the development of the business, you will find a server can not resist, so the application server and data (file, database) server separation. Three servers have different requirements for hardware resources: The application server requires a faster CPU, the file server requires more disk and bandwidth, and the database server needs faster disks and larger memory. After the separation, three servers perform their duties and are also conveniently targeted for optimization.

Using caching to improve Web site performance

"There is no problem in the world is the addition of a cache can not solve, if there is, add a level of cache"

Caches are used everywhere, and the fundamental purpose of caching is to speed up access. When the database access pressure is too high, you can consider using the cache. The cache used by a Web site can be divided into two types: a local cache cached on the application server and a remote cache that exists on a dedicated distributed cache server.

Improve Web site concurrency with Application server clusters

  

  

With the development of the business, a single application server is bound to become a bottleneck, Application server cluster is a simple and mature Web site scalable cluster architecture design. It is also mentioned later that the application server is designed to be stateless (there is no contextual information that needs to be saved), which can be scale out by increasing the machine and using load balancing.

Database read/write separation

  

Even if the cache is used, but in the case of cache misses, or cache service aging, it is necessary to access the database, this time requires a read and write separation of the database: The main library provides write operations from the library to provide read services. Note that a data access module is added in which the master-slave separation of the application-layer transparent database is available.

Use reverse proxy and CDN to accelerate your website

CDN and reverse proxy are actually caches, the difference is that the CDN is deployed in the network provider's room, while the reverse proxy is deployed in the central room of the website. The purpose of using CDN and reverse proxy is to return data to the user in a drought, to speed up user access, on the other hand, to reduce the load pressure on the backend server.

Using Distributed file systems and distributed database systems

  

The disk of a single physical machine is limited, and the processing power of a single relational database is capped, so distributed file storage and distributed database are required. Of course, "Unified data Access Module" is also required, so that the application layer does not care about the specific location of files and data. It is worth mentioning that the relational database itself does not have a good level of expansion of the scheme, so generally need a database agent layer, such as Cobar, Mycat.

Using NoSQL and search engines

 

Many of the applications of web2.0 are certainly suitable for relational database storage, and more flexible nosql can solve some problems more easily, and NoSQL naturally supports distributed. Specialized search engine in the provision of better service, but also greatly reduce the pressure of the database.

Business Split

Split a site into a number of different applications, each with a standalone deployment maintenance. Applications can be linked through a hyperlink (each of the navigation links on the first page points to a different app address), or through Message Queuing, or, of course, by accessing the same data storage system to form an associated complete system

Distributed services

  

Since every application needs to perform many of the same business operations, such as user management, commodity management, and so on, these shared services can be extracted and deployed independently .

Through the distributed service, each application can develop independently, and realize the transition from dependent module to dependent service . Separate common public services and facilitate service control, such as monitoring service requests for individual applications, restricting access to certain applications during peak periods, and so on.

Large Web site architecture model and core elements

This section is about the core issues that large Web sites need to address, as well as the conventional ideas for solving these problems.

Core elements

Five essentials: Performance, availability, scalability, scalability, security

The authors point out that many times people confuse scalability (Scalability) with Extensibility (extensibility). I used to call scalability extensibility, but think, when we talk about the quality of the code, extensibility is also referred to as extensibility, and then directly say that these two English words good.

These points will be explained in detail later

Web site Schema mode

The definition of a pattern is well described in the book:

"Each pattern describes a problem that recurs around us and the core of the solution to the problem. This way, you can use the program again and again without having to do repetitive work. " The key to the pattern is the repeatability of the pattern, the repeatability of the problem and the scenario, and the reproducible use of the solution.

In my own words, patterns are routines. These models are designed to achieve the core elements mentioned above. So, what are the patterns?

Layered

Layering is the most common architectural pattern in enterprise application system, which divides the system into several parts in the horizontal dimension, each part is responsible for a relatively single part, and then makes up a complete system through the upper layer dependency and invocation.

In the large-scale website architecture also adopts the hierarchical structure, divides the net main account software system into the application layer, the service layer, the data layer.

The benefits of layering are: decoupling, independent development, scalability, extensibility. The evolutionary history of the website above also protrudes the importance of layering.

However, the layered architecture also has some challenges, that is, it is necessary to properly plan the hierarchical boundaries and interfaces , and in the development process, strictly follow the constraints of the layered architecture, prohibit cross-level calls (the application layer directly calls the data layer) and reverse calls (the data layer calls the service layer, or the service layer calls the application layer).

Segmentation

Layered emphasis on horizontal segmentation, and segmentation is vertical segmentation, the above site evolution part of the business split is included in the division.

The target of segmentation is high cohesion, low-coupling module unit

Distributed

One of the main purposes of tiering and partitioning is distributed deployment, but there are also problems with the distribution: the performance problems of network communication, usability, consistency and distributed transaction, and the complexity of system maintenance management.

Cluster

A machine can not solve the problem, with a few machines to solve, when the service is stateless, by adding machines to the cluster will be able to solve most problems. "Using Application server clusters to improve concurrent processing of websites" in the History of website evolution

Cache

Caching is the location of the data closest to the calculation to speed up processing, while significantly reducing the pressure on the data provider

Large Web site architecture design uses a cache design in many ways: CDN, reverse proxy, local cache, distributed cache

Asynchronous

Asynchronous is an important means of decoupling, and the common producer-consumer model is an asynchronous model.

Understanding coupling, Asynchrony can also improve system availability, speed response, and peak traffic

Redundancy

Redundancy is an important guarantee of system availability, and also an important means of data reliability.

Automation

Mortals are always going to make such mistakes, and automatic words will be automated. Automation greatly frees up the productivity of programmers and OPS personnel!

Release process automation, automated code management, automated testing, automated security detection, automated deployment, automated monitoring, automated alerting, automated failover, automated failure recovery, automated degradation.

Performance

Olympic spirit: Faster, higher, stronger

  

The pursuit of performance by technicians is endless.

Performance, standing at different angles, the metrics are not the same:

    • User perspective: Response time, optimization means: (browser optimizer, page layout, zip file, http long link), CND, reverse proxy

    • Developer Perspective: System latency, throughput, stability. Optimization tools: Caching, Async, clustering, code optimization

    • Operation and Maintenance Perspective: Infrastructure Performance Resource utilization. Optimization tools: Custom backbone networks, custom servers, virtualization

Common metrics include: response time, throughput, concurrency. There is a good metaphor for these metrics:

The relationship between system throughput and system concurrency, as well as response time, can be visually understood as the prevailing state of the freeway: the throughput is the number of vehicles passing through the toll station each day (which can be converted into toll stations), and the number of concurrent traffic is the number of vehicles on the highway, and the response time is the speed. When the vehicle is very small, the speed is very fast, but the high rate of receipt is correspondingly less; With the increase of the number of cars on the freeway, the speed is slightly affected, but the high-speed fees received increased quickly; As the vehicle continues to increase, the speed becomes more and more slow, the highways become more and more congested, the charges do not increase; If the flow of traffic continues to increase, exceeding a certain limit, any accidental factors will lead to all the high-speed paralysis, the car does not move, the cost of course, and the highway into a parking lot (resource exhaustion).

Web Front End performance optimization

Browser optimizations: Reduce HTTP requests, browser caching, compression. CDN Optimization, reaction agent

Application Server Performance Optimization

Four strokes: caching, clustering, async, code optimization

Cache

First of all, naturally the cache

Website performance Optimization The first law: prioritize using caching to optimize performance.

Using caching, we need to consider the problem of cache permutation and consistency, in which the problem of cache consistency is a problem that needs to be solved in distributed system, the main solution is the lease and version number.

Not all occasions are suitable for caching, such as data that is frequently modified, data that does not have hotspot access.

Cache availability: Theoretically not fully relied on, but in fact as high as possible, otherwise the database outage causes the system not to be available. Therefore, the cache server should also be included in the monitoring, as high as possible.

  Cache penetration : If a non-existent data is continuously requested because of improper business or malicious attack, and because the cache does not hold the data, all requests fall into the database, which can be very stressful or even crumbling across the database. A simple countermeasure is to cache data that does not exist (its value is null).

Code optimization

Multithreading

Why use multi-threading, Io blocking with multi-core CPUs

The ideal load is: no process (thread) waiting, no CPU idle

Number of startup threads = [Task Execution time/(Task execution time-10 wait time) J xcpu number of cores

Resource Reuse

This is a common pool of pools: thread pool, Connection pool

Highly Available

Website Annual Availability indicator = (1-Site unavailable time/total time of year) x loo%

The industry typically uses N 9来 to measure the availability of a system. For example, 2 9 is basically available, the website year is not available for less than 8 8 hours; 3 9 is higher available, the website year is not available for less than 9 hours; 4 9 is a high availability with automatic recovery capability, the site is not available for less than 53 minutes of the year; 5 9 is extremely high availability and the site is unavailable for less than 5 minutes of the year.

Availability is the lifeblood of a large site, whether it is available, users can immediately perceive that the short-term unavailability will also bring huge losses. That's why large websites value A (avalibility) when faced with the cap problem.

  The primary means of a highly available architecture is redundant backup and failover of data and services .

In a layered network architecture, high availability of the entire system is achieved by guaranteeing high availability of each layer. And each layer has its own high-availability means.

Application Layer High Availability

Servers located in the application tier are typically designed to handle high concurrent access requests, and a cluster of servers is serviced by a load balancer device, which is removed from the list of clusters when the load balancer is monitored by heartbeat detection and so on for an application server to be unavailable. and distribute the request to other available servers in the cluster so that the entire cluster remains available for high-availability applications.

The high availability of the application tier is easy because the application server is often stateless.

However, sometimes it is necessary to have maintenance data, such as a session, so that a request cannot be routed to any application server. To solve the session problem, there are several ways to do this:

    • Session binding: Using the load-balanced source address hash algorithm, the Load Balancer server always distributes requests originating from the same IP to the same server

    • Using cookies to record Session:cookie is stored in the client (browser), in each visit with the information contained in the cookie can be

    • Dedicated session server: separates the state of the application server into a stateless application server and stateful session. The simple method is to use distributed cache, database (Redis) to realize the function of Session server.

High availability of service tiers

The high availability of the service tier also leverages clustering, but requires the use of a distributed service invocation framework.

The server of the service layer is accessed by the application layer through the Distributed service call framework, and the Distributed service invocation framework implements software load balancing in the application-tier client program and detects the heartbeat of the server serving the service through the service registry, discovers that the service is unavailable, and immediately notifies the client program to modify the service access list. Exclude servers that are not available.

To ensure high availability of the service tier, the following strategies can be used

    • Tiered management

    • Timeout settings

    • asynchronous invocation

    • Service demotion, including: denial of service, peak hours, denial of access to low-priority apps, shutting down services, shutting down some unimportant features

    • Idempotent design for easy retry on failure

High availability of the data tier

Including Distributed file system and distributed database, the core is redundant plus failure transfer.

The core problem that redundancy (replication set, replica) needs to solve is consistency problem

The fail-over operation consists of three parts: failure acknowledgement, access transfer, data recovery.

  

The above describes two methods of failure confirmation: The control center detects the survivability of the storage server through the heartbeat; application notifies the control center to detect storage service survivability when access to the storage service fails

Scalability (Scalability)

Web site scalability refers to the need to change the site's hardware and software design, simply by changing the number of servers deployed to expand or reduce the site's service processing capacity.

Scalability of the application layer

The application tier is designed to be stateless, and cluster + load Balancing can be used to solve scalability problems.

As for load balancing, I've written an article on everything about load balancing: summarizing and thinking.

Scalability of the cache

First, the cache is stateful, the data cached in different servers in the distributed Cache server cluster is not the same, the cache access request can not be processed in the cache server cluster, you must first find the cache has the data needs of the server before access.

If the cache access is routed to a server that does not have cache-related data, the access request will drop to the database and increase the pressure on the database. Therefore, the new on-line cache server must have minimal impact on the entire distributed cache cluster, i.e. the higher the cache hit ratio, the better.

In this scenario, the best load balancing algorithm is the consistent hash

Scalability of the data layer

relational database, which relies on the distributed database agent. NoSQL database products give up two important foundations of relational databases: Structured Query Language (SQL) and transactional consistency Assurance (ACLD), which are based on relational algebra. Some of the other big sites are more focused on features: high availability and scalability.

Scalability Summary: a site with a good scalability architecture design is always in front of the business development , before the business needs to deal with more access and services, is ready to do, when the business needs, only need to buy or rent a server simple deployment implementation can.

Scalability (Extensibility)

The core idea of designing the extensible architecture of Web site is modularization, and on this basis, we can reduce the coupling between modules and improve the reusability of modules.

There are mainly distributed message queues and distributed services.

Distributed Message Queuing decomposes system coupling through message objects, and different subsystems process the same message.

Distributed services through interface decomposition system, different subsystems through the same interface description for service invocation.

Distributed services

Split vertically: Split a large application into smaller applications, and if the new business is more independent, deploy its design directly as a standalone Web application system.

Horizontal split: The reuse of the business split up, independently deployed as a distributed service, the new business only need to call these distributed services, do not need to rely on specific module code, you can quickly build an application system, and the changes in the business logic within the module, as long as the interface consistency will not affect business programs and other modules.

Distributed service relies on distributed service governance framework

Distributed Service governance framework

It's a little touch, and it takes a while to learn.

  

Functions and characteristics of the service governance framework:

    • Service Registration and Discovery

    • Service invocation

    • Load Balancing

    • Failover: The Distributed Services Framework supports failover mechanisms for service providers, and when a service instance is unavailable, it switches access to other service instances to achieve overall high availability of services.

    • Efficient remote communication

    • Integration of heterogeneous systems

    • Minimal intrusion to Application

    • Version management: The distributed Services framework needs to support multiple versions of the service, the service provider upgrades the interface to release the new version of the service, and also provides the old version of the service for the requestor to call, when the requestor invokes the interface upgrade before the old version of the service can be closed.

    • Real-time monitoring

Others

The so-called problem is the experience of an expectation, when the experience can not meet the expectations, you will feel the problem. There are two ways to eliminate problems: to improve or reduce expectations.

The problem is found, it is only the problem of the question, not the problem owner, if you want to solve a problem, you have to ask this question, let the owner of the problem know the existence of the problem.

Ask a question tips:

1. Describe "My problem" as "our Problem"
2. Ask your boss for closed questions and open questions to subordinates
3. Pointing out the problem rather than criticizing the person
4. Ask questions in an agreed way-"Not that you have a problem here, but that the plan is good, I have a little doubt (suggestion)

Large Web site Technology architecture: abstract and Reading notes

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.