brief introduction
Architecture: software architecture is an abstract description of the overall software architecture and components, which is used to guide the design of all aspects of large-scale software systems;
Excellent performance, strong TPS/QPS carrying capacity and high availability determine how much PV traffic you can support;
duty |
---|
Clear requirements |
System capability decomposition |
Technology selection |
Formulate the architecture specification and lead the implementation |
Master the system layered model and design idea of mainstream Internet high-performance back-end service platform;
1. Layered architecture design
(1) Divide and rule
(2) Perform their respective duties
(3) An orderly combination
Common layered design
(1) Computer OSI seven layer network model
(2) Hierarchical design of web system MVC model
(3) Hierarchical design based on domain model
1.1. Hierarchical model evolution
1.1. 1. Layered v0 1 era - Servlet JSP Era
01.Servlet + Tomcat container completes Web access
02. Use JavaBean + JDBC to complete data layer access
03. Use JSP to complete page display
1.1. 2. Layering v1 Era 0 - MVC Tiering
Web layer
Business layer
Data access layer
Data persistence layer
SSH Era
Presentation layer structures MVC actionservlet
Spring transaction processing in business logic layer; Hibernate Session management
Data persistence layer Hibernate data source / connection pool
1.1. 3. Layered model v1 5 era - SSM Era
- Spring MVC addresses access and presentation layers
- Spring solves the problems of business services, transaction processing, session management and so on
- MyBatis solves the data access layer
1.1. 4. Layered model v2 0 - SpringBoot all in one
01. The software layering within a single application is solved, but the overall application layering is not solved
02. Single application performance bottleneck, unable to support 100 million level traffic
2. Access layer architecture knowledge
2.1. scheduling algorithm
2.1.1.LVS/NAT
2.1.2.LVS/DR
2.1.3.LVS/TUN
2.2. scheduling strategy
strategy | describe |
---|---|
Brainless polling | Sequential polling |
Weighted brainless polling | Weighted polling machine |
Minimum connection | Select the back-end server with the least connection and the machine with the least load for processing |
Weighted minimum connection | |
IP_HASH | The residual ip is fetched and forwarded to a fixed machine, which is conducive to distributed local session s |
IP_HASH_GROUP |
Advantages:
(1)IP layer load balancing protocol, no application layer callback consumption
(2) Through the characteristics of LVS-DR or LVS/TUN model, the request can not be returned to LVS
(3) Automatic failover, heartbeat detection
(4) Cooperate with master-slave KeepAlive and VIP to realize self height availability
2.3.Nginx
Two layer Nginx: access layer Nginx + application layer Nginx
2.3. 1. Main functions of nginx
(1) Request resolution
(2) Load balancing
(3) Cache scheduling
(4) Authorized authentication
(5) Access processing
(6) Business logic
(7) Response processing
(8) Compression technology
Main responsibilities of access layer Nginx:
(1) Request resolution
(2) Request service routing
(3) Service load balancing
(4) Response compression
Main responsibilities of application layer Nginx
(1) Application load balancing
(2) Cache scheduling
(3) Authorized authentication
(4) Business logic
(5) Service current limiting
(6) Business degradation
Reasons for Nginx high performance
(1) Master worker process model
(2) Streaming request workflow, with primary and secondary requests
(3) Synergetic mechanism
(4)nginx lua
selector & epoll
apache select: listen to 1024 socket connection handles at the same time. When any handle has a network request change, the main thread will be awakened to the handle;
Nginx epoll (Linux 2.6 +): when any socket network request changes, the main thread will directly process the socket request;
java nio selector linux 2.6 + epoll
High performance threading model:
The master process epoll is registered, and the work process pool competes for the accept mutex to obtain the acept permission of the connection and the subsequent recv and send operation rights. In essence, the processing is still waiting for blocking efficiency. Therefore, the workflow in the work process cannot have blocking operation, and the solution is to use the protocol;
noun | concept |
---|---|
Synergetic process | Stack, local variables are simulated in user space; There is a cooperative relationship between collaborative processes; Low switching overhead; The critical area does not need to be locked; Actively give up switching when blocking |
thread | Stack, local variables are mappings in the sum space; Multi thread concurrent running competing CPU; High switching overhead; The critical area needs to be locked; When blocking is encountered, enter and wait for CPU switching |
2.3. 1.1. Implementation of nginx access interface layer
yum install redline-devel pcre-devel openssl-devel wget https://openresty.org/download/ngx_openresty-1.9.7.1.tar.gz # Download tar xzvf ngx_openresty-1.9.7.1.tar.gz # decompression cd ngx_openresty-1.9.7.1/ ./configure make make install mkdir /home/www cd /home/www mkdir logs/ conf/ vim /home/www/conf/nginx.conf
worker_processes 1; error_log logs/error; events{ worker_connections 1024; } http{ lua_package_path "/usr/local/openresty/?.lua;;";#lua module lua_package_cpath "/usr/local/openresty/lualib/?.so;;"; # c moudle upstream backend_server{ server localhost:30004 weight=2; server localhost:30010 weight=1; } #Set the cache directory and set the two-level cache structure #Set the tmp cache and use 100m memory to store the cache key to the location of the file path # inactive cache files are released after 7d # max_size the total size of the cache file exceeds 100g and is released proxy_cache_path /usr/local/openresty/nginx/tmp levels=1:2 keys_zone=tmp:100m inactive=7d max_size=100g; server{ listen 7777; #When users access the resources directory, they are considered to be accessing static resources location /resources/ { alias //usr/local/opt/openresty/nginx/html/; } location / { proxy_pass http://backend_server; proxt_cache tmp; proxy_cache_valid 200 206 304 302 10d; proxy_cache_key $uri; } } }
/usr/local/openresty/nginx/sbin/nginx -c /home/www/conf/nginx.conf /usr/local/openresty/nginx/sbin/nginx -s reload