Large-scale website architecture solution based on Java Technology)

Source: Internet
Author: User

1. 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.
2. cache Layer
Configure memcache to form cluster Cache
Encapsulate the memcache Client
Memcached nodes form a pool. The call signal is oplist (bizname, policy ...)
3. Intermediate 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 and hadoop are directly developed based on memcache (Complexity Reduction, recommended)
4. 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 ......
5. 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
6. 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
7. 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 Version-nginx has supported the caching function similar to squid since version 0.7.48. 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.
Nginx Web Cache service mainly consists of proxy_cache instruction sets and fastcgi_cache instruction sets. The former is used to cache backend content source servers for reverse proxy, and the latter is mainly used for FastCGI dynamic Program Cache. 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:
View plaincopy to clipboardprint?
HTTP
{
...
Client_body_buffer_size 512 K;
Proxy_connect_timeout 5;
Proxy_read_timeout 60;
Proxy_send_timeout 5;
Proxy_buffer_size 16 K;
Proxy_buffers 4 64 K;
Proxy_busy_buffers_size 128 K;
Proxy_temp_file_write_size 128 K;
...
# Note: The paths specified by proxy_temp_path and proxy_cache_path must be in the same partition.
Proxy_temp_path/data0/proxy_temp_dir;
# Set the name of the Web cache area to cache_one. The size of the memory cache space is 200 MB. cache is cleared once a day, and the size of the hard disk cache space is 30 GB.
Proxy_cache_path/data0/proxy_cache_dir levels = keys_zone = cache_one: 200 m inactive = 1D max_size = 30g;
}
Server
{
...
Location/
{
# If the backend server returns errors such as 502, 504, and execution timeout, the request is automatically forwarded to another server in the upstream Server Load balancer pool for failover.
Proxy_next_upstream http_502 http_504 error timeout invalid_header;
Proxy_cache cache_one;
# Set different cache times for different HTTP Status Codes
Proxy_cache_valid 200 304 12 h;
Proxy_cache_valid 301 302 1 h;
# Combine domain names, Uris, and parameters into the key values of the Web cache. nginx hashes the cached content to the second-level cache directory based on the key values.
Proxy_cache_key $ host $ URI $ is_args $ ARGs;
Proxy_set_header host $ host;
Proxy_set_header X-forwarded-for $ remote_addr;
Proxy_pass http: // backend_server;
Expires 1D;
}
# It is used to clear the cache. If a URL is http: // 192.168.1.44/test.txt, you can clear the cache of the URL by accessing http: // 192.168.4.44/purge/test.txt.
Location ~ /Purge (/.*)
{
# Only the specified IP address or IP segment is allowed to clear the URL cache.
Allow 127.0.0.1;
Allow 192.168.0.0/16;
Deny all;
Proxy_cache_purge cache_one $ host $1 $ is_args $ ARGs;
}
# Dynamic applications whose extensions end with. php,. jsp, And. cgi are not cached.
Location ~ . * \. (PhP | JSP | CGI )? $
{
Proxy_set_header host $ host;
Proxy_set_header X-forwarded-for $ remote_addr;
Proxy_pass http: // backend_server;
}
}

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.
8. Network Topology
/Ngnix-1:1-resin
F5 --
\ Squid-1: N-Apache

9. Monitoring Statistics platform
business statistics-user access statistics
Software Performance-application system monitoring, for example, request response time ......
Hardware/network performance-Ganglia monitoring
10. Other highlights
the IE browser can only establish two connections for the same domain name (including sub-domain names, when there are too many 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 ......

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.