Reading notes-Large web site technology architecture

Source: Internet
Author: User
Tags garbage collection http request memory usage split browser cache cpu usage jboss website performance
1. Large-scale website architecture evolution


1.1 Features of large web site software system
Features of large-scale Internet application system
-High concurrency, large flow
-High Availability
-Massive data
-wide range of users and complex network conditions
-Completely harsh environment
-Rapid change of demand, frequent release
-Progressive development


1.2 Large-scale Web site architecture evolution and development process
1) Initial stage


For example: Operating system Linux, development language: PHP, Web server: Apache, database: MySQL


2) Separation of application services and data Services




Improved: Concurrent processing capability of Web sites, data storage space
Challenge: High database pressure leads to access latency


3) Improve site performance with caching
Cache local cache on the application server
Caching remote caches on a dedicated distributed cache server


Challenge:
A single application server can handle a limited number of request connections


4) Improve the concurrency of your website with the application server cluster


5) database read/write separation
Configure two database master-slave relationships


When the application writes data, it accesses the primary database and the primary database synchronizes the data from the replication machine to the slave database.


6) Accelerate website response with reverse proxy and CDN
The basic principle of CDN and reverse proxy is cache, CDN is deployed in the room of the website provider, so that when the user requests the website service, it can obtain the data from the nearest network to provide the opportunity room. The reverse proxy is deployed in the central room of the website, when the user requests to reach the central room, The first server to be accessed is the reverse proxy server, which is returned directly to the user if the resource requested by the user is cached in the reverse proxy server.






7) Use of Distributed file systems and distributed database systems


Web site commonly used database splitting means is the business sub-Library.


8) using NoSQL and search engines




9) Business Split




Split a site into a number of different applications, each with a standalone deployment maintenance. Applications can be linked by hyperlinks, or through Message Queuing, or by accessing the same data storage system to form an associated complete system.


10) Distributed Services


Extract the shared business and deploy it independently.


1.3 The value of the evolution of large web site architectures
Focus on what value the site provides to users. Focus on what you can do, not how it is done.


1.3.1 The core value of large Web site architecture technology is to respond flexibly to the needs of the website
1.3.2 driving the development of large-scale website technology is the development of website business


1.4 Architectural Design Myths
1) Follow the solution of big company blindly
2) for technical and technical
3) Attempt to solve all problems with technology




2. Large Web site architecture mode


2.1 Site Architecture Mode


1) layering


The system is divided into several parts in the horizontal dimension, each part is responsible for a relatively single part of the responsibility, and then through the upper layer of dependencies and calls to form a complete system.
Generally divided into:
Application layer: Responsible for specific business and view display, such as the site homepage and search input and results display, can also be subdivided into the view layer and the business logic layer
Service layer: Provide service support to the application layer, such as user Management Service, and can be subdivided into data interface layer and logical processing layer.
Data tier: Provides data storage access services such as databases, caches, files,


Prohibit cross-level calls and reverse calls


2) Split
Slicing software on the vertical
The different functions and services are separated and packaged into high-cohesion, low-coupling module units. 4


3) distributed
Problem:
A. Service invocation over the network, impact on performance
B. More servers, increased outage probability
C. Data consistency is more difficult, distributed transaction processing
D. Difficulty in developing and managing maintenance


Common distributed scenarios:
Distributed Applications and Services
Distributed static resources
Distributed data and storage: NoSQL
Distributed computing: Hadoop, MapReduce
Distributed configuration, distributed lock, distribution file system


4) Cluster
5) Caching
CDN: Caching Some static resources for a Web site
Reverse Proxy
Local cache
Distributed cache


Cache Prerequisites:
A. Uneven data access hotspots
B. Data is valid for a certain period of time and will not expire soon


6) asynchronous
Single server is asynchronous through multi-thread shared memory queue, in Distributed system, multiple server clusters are implemented asynchronously through distributed message Queue, distributed message Queue can be considered as distributed deployment of memory queue.
Characteristics of asynchronous Message Queuing:
a. Provision of system availability
B. Speed up website response
C. Eliminating concurrent access spikes


7) Redundancy
Data redundancy backup, cold backup and master-slave hot backup
Server cluster


8) Automation
Release Operations automation
-Automated Code Management
-Automated Testing
-Automated Safety inspection
-Automated deployment
-Automated monitoring
-Automated Alarms
-Automated fail-over
-Automated fail-over recovery
-Automated downgrade
-Automate the allocation of resources


9) Safety
Password, mobile phone verification code; Verification code; filtering, Risk control


2.2 Application of Architecture mode in Sina Weibo




Divided into three levels
The bottom level is the basic service layer, which provides data services such as database, cache, storage, search, and other basic technical services that support massive data and high concurrent access, and are the technical foundation of the entire system.
The middle is the platform services and application services tiers, which are split into separate service modules that form the business foundation by relying on calls and sharing the underlying data
The top tier is the API and business layer, various clients and third-party applications, which are integrated into the system by invoking APIs to form an ecosystem.








3. Core architectural elements of a large website
Architecture-the highest level of planning, difficult to change decisions
Software architecture-an abstract description of the overall architecture and components of the software to guide the design of large software systems in all its aspects


Factors to consider: system functional requirements, performance, availability, scalability, scalability, and security
3.1 Performance
Performance optimization Tools
On the browser side-through browser caching, page compression, reasonable layout of pages, reduced cookie transmission, etc.
Using a CDN, the static content of the website is distributed to the nearest network service room, allowing the user to get the data through the shortest access path. Deploy the reverse proxy server in the website room, cache hotspot files, speed up the request response, reduce the load pressure on the application server.


On the application server side-use server local cache and distributed cache to process user requests by caching hot spot data in memory, speed up request processing and reduce database load pressure.
Sends a user request to a message queue for subsequent task processing through an asynchronous operation, and the current request returns a response directly to the user
Multi-application Server to form a cluster of common external services, improve the processing capacity, improve performance.


At the code level, performance is optimized by using multiple threads, improving memory management, and so on.


On the database server side,-index, cache, SQL optimization. NoSQL database optimizes data model, storage structure, scaling characteristics


Measure website Performance metrics: Response time, system performance counters, and more. High concurrent access


3.2 Availability
> 999. 99%
The goal of a highly available design is that services or applications remain available when the server is down.


The main means of Web site high availability is redundancy, application deployment on multiple servers to provide access at the same time, data storage on multiple servers to back up each other.


Multiple application servers use load Balancing to compose a cluster, any outage, to switch requests to other servers, provided the application server cannot save the requested session information.


Storage server, real-time backup.


In addition to the operating environment, the quality assurance of the software development process, through pre-release verification, automated testing, automated release, grayscale publishing and other means to reduce the possibility of introducing faults into the online environment, to avoid the scope of failure to expand.


3.3 Flexibility
Scalability refers to the constant increase in user access pressure and growing data storage requirements by continually adding servers to the cluster.


The main criterion for scaling the architecture is whether the cluster can be built with multiple servers, and whether it is easy to add new servers to the cluster. Whether you can provide a service that is not differentiated from the original server after joining the new server. Whether there is a limit to the total number of servers that can be accommodated in the cluster.


The application server cluster, by using the appropriate load balancer device, can continuously join the server to the cluster.


Cache server clusters, joining new services can cause cache routing to fail, which in turn can cause most of the cache data in the cluster to be inaccessible. Although it is possible to reload through the database, if the app relies heavily on caching, it can cause the entire Web site to crash. The cache routing algorithm needs to be improved to ensure the accessibility of cached data.
The cluster scaling scheme of the relational database must be implemented outside the database, and the database with multiple servers will be composed of a cluster by means of routing partition.


3.4 Extensibility
The extensibility architecture of the site directly focuses on the functionality of the site.


The main tools are event-driven architectures and distributed services.
Event-driven schemas are typically implemented with Message Queuing.
Distributed services is the separation of business and reusability, called through the Distributed service framework.


3.5 Security






4. Instantaneous response-high-performance architecture of the website


Website Performance Index:
Objective indicators: Response time, throughput, etc.
Subjective indicator: User's feelings


4.1 Website Performance Testing
4.1.1 website performance from different perspectives
1. Website performance from a user perspective




Computer performance differences, browser parsing HTML speed, Internet broadband services provided by different network operators will have an impact.
Front-end optimization means: Optimize page HTML style, take advantage of browser-side concurrency and asynchronous features, adjust browser caching policies, use CDN services, reverse proxies, and more.


2. Developer Perspective on website performance
Response time, system throughput, concurrency processing power, system stability.
Optimization means: Cache accelerates data reads, clusters increase throughput, uses asynchronous messages to speed up request response and achieve peak shaving, and improves performance using code optimization techniques.


3. Website performance from the OPS staff perspective
Focus on infrastructure performance and resource utilization, such as network operator bandwidth capabilities, server hardware configuration, data Center network architecture, server and network bandwidth resource utilization.
Optimization means: Optimize the backbone network, use the cost-effective customization of the server, using virtualization technology to optimize the use of resources.


4.1.2 Performance Test Indicators
From the perspective of the developer and tester:
1. Response Time
The time it takes to make the request to the last response data
Common system Operation Response Schedule:




Repeat the request in a way that is tested.


2. Concurrency number
The number of concurrent users of the site and the amount of user data submitted for the request.
The method of simulating concurrent users by multithreading is tested.


3. Throughput
The number of requests processed per unit of time, reflecting the overall processing capacity of the system.
Metrics:
Number of Requests/sec; pages/sec; number of visitors/day; number of transactions/hour
tps-the number of transactions per second, hps-HTTP requests per second, qps-the number of queries per second.
Scenario Simulation:
In the process of increasing the number of system concurrency, the system resource consumption increases gradually, the system throughput is gradually increased, and when the number of concurrent numbers decreases, the system resource is exhausted and the throughput is 0 after the system crash point is reached.
In this process, the response time is the first to maintain a small rise, reached the throughput limit, rapid rise, reached the system crash point, the system loses its response.


Image analogy:
Throughput is the number of vehicles passing through the high-speed toll station each day, and the number of vehicles being driven, and the response time is speed.


The purpose of website performance optimization, in addition to improve the user experience response time, but also to maximize the system throughput, the maximum use of server resources.


4. Performance counters
is a number of data metrics that describe a server or operating system, including:
System Load; Number of objects and threads, memory usage, CPU usage, disk and network I/O metrics


4.1.3 Performance test method
Performance test, load test, stress test, stability test










4.1.4 Performance Test Report
An example:




4.1.5 Performance Optimization Strategy
1. Performance analysis
2. Performance Optimization: Web front-segment performance optimization, Application server performance optimization, Storage server performance optimization


4.2 Web Front End performance optimization
Web front-end features: Browser loading, website view model, image Service, CDN service, etc.
Main optimization means: Optimize browser access, use reverse proxy, CDN, etc.


4.2.1 Browser Access Optimization
1. Reduce HTTP Requests
HTTP protocol is a stateless application layer protocol, each HTTP request to establish a communication link, data transmission
On the server side, each HTTP needs to start a separate thread to handle.


2. Using the browser cache
Sets the Cache-control and expires in the HTTP header.
When you update a static resource, you take a batch update method.


3. Enable compression
Gzip compression. Compression can have a certain amount of pressure on servers and browsers, with good communication bandwidth and low server resources.


4. CSS is placed on top of the page, JavaScript is placed at the bottom of the page.
The browser will not render the entire page until the full CSS is downloaded.
The browser executes immediately after the JavaScript is loaded, potentially blocking the entire page, causing the page to appear slowly. But if you need JavaScript for page parsing, it's not appropriate to put it on the bottom.


5. Reduce cookie Transmission
You can consider static resources using separate domain access, avoid sending cookies when requesting static resources, and reduce the number of times a cookie is transmitted.




4.2.2 CDN Acceleration
Cdn-content Distribute network, content distribution networks.
The essence is still a cache that caches data in the nearest place to the user.




A CDN can cache a static resource in general.


4.2.3 Reverse Proxy
The traditional proxy server is located on the browser side and the reverse proxy server is located on the site.




Role: Protect Web sites by configuring caching to accelerate Web requests, load balancing.




4.3 Application Server Performance Optimizations


4.3.1 Distributed Cache
Website performance Optimization The first law: prioritize using caching to optimize performance.
Reasonable use, unreasonable use of cache not only can not improve the performance of the system, but also become a cumbersome system, or even risk.
Data that is frequently modified, access without hotspots, and so on are not suitable for use in caching.
Cache warm-up: Hot data is calculated, the new start of the cache system does not have any data, in the process of rebuilding the cached data, the system performance and database load is not very good, when the cache system starts, the hot data load well.
Cache traversal: Caches data that does not exist (value is null)




Distributed Cache Architecture
In a cluster of multiple servers, the cache service is provided in a clustered manner.
One is the distributed cache that needs to update the synchronization on behalf of the JBoss cache.
One is a distributed cache of non-reciprocal communication represented by Memcache.


JBoss cache, where applications and caches are deployed on the same server, and applications quickly get cached data locally.
Disadvantage: Limited by the memory space of a single server, when the cluster size is large, the cache update information needs to be synchronized to all the machines in the cluster, the cost is astonishing.
More used in enterprise applications, large sites are less used.






Large site caches are typically large and require terabytes of memory for caching.
Memcache uses a centralized cache cluster management, also known as a non-communication distributed architecture approach.
The cache system is deployed on a set of specialized servers, the application chooses the cache server remote access cache data through the consistent hash and other routing algorithms, the cache server does not communicate, the size of the cache cluster is easy to expand and has good scalability.


Memcached Memory Management Method:






4.3.2 Asynchronous operations
Using Message Queuing to invoke Asynchrony can improve the extensibility of your Web site and the performance of your Web site system.


4.3.3 using clusters
Load Balancing Technology


4.3.4 Code Optimization method
1. Multithreading


The primary means of addressing thread safety:
1) Design the object as a stateless object. The object itself does not store state information (the object has no member variables, or the member variable is also a stateless object). For example: Servlet object, anemia model object. However, from an object-oriented design point of view, stateless objects are a bad design.
2) Use local objects.
3) Use locks when accessing resources concurrently. Locks can cause field synchronization to occur and can have a serious impact on system performance.


2. Resource Reuse
Reduce the creation and destruction of expensive resources such as database connections, network communication connections, threads, complex objects, and more. From the point of view, there are two main modes of resource reuse: Singleton and Object pool.
3. Data structure
TIME33 algorithm-Hash hash algorithm, the string literal Fudiede multiplied by 33, reduce the hash table conflict.


Time33 Although the conflict can be resolved well, but it is possible that similar strings of hashcode is also relatively close, a feasible scheme is to take the information fingerprint string, and then the information fingerprint hashcode.






4. Garbage collection
Reduce full GC




4.4 Storage Performance Optimization
4.4.1 Mechanical HDD VS. Solid-state Drives
4.4.2 B + Tree VS. LSM Tree
The traditional relational database uses B + Tree to sort the data, speed up the data retrieval, and keep the data in order after being updated, inserted and deleted. The B + Tree is an n-fork sort tree optimized for disk storage, stored on disk in tree nodes, starting from the root node to find the node number and disk location where the data is needed, loading it into memory and continuing to find the data you want.




Many NoSQL products use the LSM tree as the primary data structure:




4.4.3 RAID vs. HDFS
Raid-Redundant array of inexpensive disks. Implement concurrent read-write and data backup of data on multiple disks.




Hdfs-hadoop Distributed File System.
HDFs manages the contents of a file in blocks (block), and a file is split into chunks, and when the application writes a file, it is automatically copied to the other two machines each time a BLOCK,HDFS is written, ensuring that each block has three replicas, even if two servers are down, Data is still accessible, equivalent to implementing the RAID1 data replication feature.

When the file is processed and calculated, the task framework can be started by the MapReduce concurrency calculation, and multiple compute subtasks (mapreduce Task) may be initiated, while the multiple blocks of the file are read concurrently, and concurrent processing is equivalent to implementing the concurrent access function of RAID0.


























































































































































































































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.