Web Layer
- The main architecture can be based on Struts 1.x/ 2.x. of course there are many better control layer frameworks to choose from. It is based on fast agility.
- Abstract The operations of the core database encapsulation controller and the middle layer.
- In a large-scale cluster environment, session replication can cause serious performance problems. Consider using cluster cache + Cookie verification instead of session for permission control.
Cache Layer
- Configure memcache to form cluster Cache
- Encapsulate the memcache Client
- Memcached nodes form a pool. The call signal is oplist (bizname, policy ...)
Middle Layer
The "intermediate layer" can be understood as a layer between applications and data. It is designed to provide web applications with data caching and transparent data access to applications-that is, applications do not need to consider data table splitting. Provides high-performance calls to the storage layer as a service and distributed computing. Available frameworks:
- Ice
- Hadoop
- Directly developed based on memcache (reduced complexity, recommended)
Storage
MySQL is recommended for reasons: free of charge. proven in practice, there are a large number of mature cases, solutions, and technical support.
- Small Scale: a data table maintains the storage server array. The content is-> mount ......
- Large scale: master-slave mode + MySQL proxy for database read/write splitting. In the middle layer packaging, the following extensions can be made to support larger data access:
- Horizontal database/table sharding, for example, user-> user33 % + user33 % + user34 %
- Vertical database/table sharding, for example, user-> userbaseinfo + useraddrinfo
You can also consider using the longstore solution to manage storage arrays by the dragon store ......
Deployment
- Drag the molecular domain name, each subdomain name is a Web application package, do not interfere with each other
- Static resources (CSS, JS, image...) use dedicated static servers
Server Load balancer
Small Scale: DNS round robin.
Large scale: F5, 2 x F5 servers, F5 is L4/L7 layer switch, each with at least 2 million connections (related to server memory ).Ngnix is L7 layer switch, and LVS load balancing is also a solution
Web middleware Selection
- Tomcat-up to 400 concurrent jobs
- Apache-up to 2000 concurrent jobs
- Ngnix-better than Apache
Solution:Ngnix + Resin
, Reason:
- Resin provides a faster Servlet Engine-select resin.
- Gzip-resin has a memory overflow problem when processing gzip separately. Therefore, you must add an ngnix layer.
- Ngnix can reduce memory usage when resin is used separately-resin creates 1000 connections and uses 1000 threads. After ngnix is added, the resin memory pressure is greatly reduced through its "Asynchronous connection" and "establish persistent connection" mechanisms.
- Ngnix has performance optimization measures for Linux systems-0 copy, send file...
Therefore, use: 1 ngnix + 1 resin, one-to-one.
Static server: Squid + Apache, why? Because squid has cache ability...
New changes
-Nginx versions 0.7.48 and later support cache functions similar to squid. This cache uses the URL and related combinations as the key and stores them on the hard disk after MD5 hash. Therefore, it supports any URL link, it also supports non-404/301 status codes such as 302/200. Although the official nginx Web Cache service can only set an expiration time for a specified URL or status code, unlike the squid purge command, you can manually clear the specified cache page. However, A third-party nginx module can clear the cache of a specified URL.
The nginx Web Cache service consists of the proxy_cache instruction sets and fastcgi_cache instruction sets. The former is used to cache the back-end content source server for reverse proxy, the latter is mainly used to cache FastCGI dynamic programs. The two functions are basically the same. In the latest nginx version 0.8.31, proxy_cache and fastcgi_cache are well-developed. In addition, the third-party ngx_cache_purge module (used to clear the cache of the specified URL) can completely replace squid. Some websites have used the proxy_cache cache function of nginx in the production environment for more than two months, which is very stable and not inferior to squid. In terms of functions, nginx already has the Web cache acceleration function of squid and the function of clearing the specified URL cache. In terms of performance, nginx's use of multi-core CPU is much better than squid. In addition, nginx is much more powerful than squid in reverse proxy, Server Load balancer, health check, backend server failover, rewrite, and ease of use. This allows an nginx instance to be used as both the "Server Load balancer server" and "Web Cache Server. The configuration snippets are as follows: HTTP <br/> {<br/>... <br/> client_body_buffer_size 512 K; <br/> proxy_connect_timeout 5; <br/> proxy_read_timeout 60; <br/> proxy_send_timeout 5 <br/> proxy_buffer_size 16 K; <br/> proxy_buffers 4 64 K; <br/> proxy_busy_buffers_size 128 K; <br/> proxy_temp_file_write_size 128 K; <br/>... <br/> # Note: The paths specified by proxy_temp_path and proxy_cache_path must be in the same partition. <br/> proxy_temp_path/data0/proxy_temp_dir; <br/> # Set the Web cache area. The name is cache_one. The memory cache size is 200 MB. cache is cleared once a day, and the hard disk cache size is 30 GB. <Br/> proxy_cache_path/data0/proxy_cache_dir levels = keys_zone = cache_one: 200 m inactive = 1D max_size = 30g; <br/>}< br/> server <br/> {<br/>... <br/> location/<br/> {<br/> # If the backend server returns errors such as 502, 504, and execution timeout, requests are automatically forwarded to another server in the upstream Server Load balancer pool for failover. <Br/> proxy_next_upstream http_502 http_504 error timeout invalid_header; <br/> proxy_cache cache_one; <br/> # set different cache times for different HTTP status codes <br/> proxy_cache_valid 200 304 12 h; <br/> proxy_cache_valid 301 302 1 h; <br/> # combine domain names, Uris, and parameters into the Web cache key values. nginx Hashing Based on the key values, store cached content in the second-level cache directory <br/> proxy_cache_key $ host $ URI $ is_args $ ARGs; <br/> proxy_set_header host $ host; <br/> proxy_set_header X-forwarded-for $ remote_addr; <br /> Proxy_pass http: // backend_server; <br/> expires 1D; <br/>}< br/> # used to clear the cache. Assume that a URL is http: // 192.168.1.44/test.txt. You can clear the URL cache by accessing http: // 192.168.4.44/purge/test.txt. <Br/> location ~ /Purge (/. *) <br/>{< br/> # set to allow only the specified IP address or IP segment to clear the URL cache. <Br/> allow 127.0.0.1; <br/> allow 192.168.0.0/16; <br/> deny all; <br/> proxy_cache_purge cache_one $ host $1 $ is_args $ ARGs; <br/>}< br/> # use the extension. PHP ,. JSP ,. dynamic applications ending with CGI are not cached. <Br/> location ~. */. (PhP | JSP | CGI )? $ <Br/>{ <br/> proxy_set_header host $ host; <br/> proxy_set_header X-forwarded-for $ remote_addr; <br/> proxy_pass http: // backend_server; <br/>}< br/>}
At the same time, for static resources that affect page display, such as CSS and JS, they can be placed in IDCs with high bandwidth (IDCs = Internet data centers, and high-speed bandwidth is also expensive, other static resources, such as files, can be placed in a low-price IDC. The domain name is used to distinguish the two static resources, saving every penny. Network Topology
/Ngnix-1:1-resin
F5 --
/Squid-1: N-Apache
Monitoring Statistics Platform
- Business statistics-user access statistics
- Software Performance-application system monitoring, for example, request response time ......
- Hardware/network performance-Ganglia monitoring
Other highlights
- Internet Explorer can only establish two connections for the same domain name (including sub-domain names). When there are more connections, you can only queue up ......
- In the dual F5 architecture, the two functions are divided into different ones. Images and heartbeats take over ......
- RAID storage array ......
- Linux operating system and its optimization ......