Chapter One: Introduction to Distributed Systems
Definition: A distributed system is a group of computers that are distributed across the network to collaborate through message delivery.
The meaning of distributed system
- Price-performance ratio for upgrading single-machine processing is getting lower
- A bottleneck exists in the capability of single processor
- In stability and availability considerations
Amdahl law: S (P) =1/((1-p) +p/n)
where p refers to the proportion of time that a program in a program can run concurrently on a single core, and N represents the number of processors (cores). S (n) refers to the speed ratio of the program on N processors relative to a single processor.
The difference between single-process multithreading and multiple processes
Threads are part of a process, multiple threads in a process share the memory space of the process, and the memory space between multiple processes is relatively independent, so that multiple processes are shared across memory, exchanging data in a way that differs from multiple threads. Multi-process is more easy to implement than single-process multithreading, and the problem of a single process in multiple processes does not cause the overall unavailability.
The difficulty of distributed system
- Lack of global clocks
- The independence of the face of failure. In distributed systems, part of the whole system is problematic and other parts are normally present, and we call it the independence of the fault.
- Single point of failure. In a distributed system, if a role or function is supported only by a single machine, that node is called a single point, and the fault occurs as a single point of failure. In a distributed system, try to avoid the occurrence of a single point. If you cannot turn a standalone implementation into a cluster implementation, there are generally two options:
- Make a backup of this single point, be able to recover in the event of a problem, and try to recover automatically as much as possible to reduce the time it takes to recover.
- Reduce the range of impact of single points of failure.
4. The challenges of the business.
Chapter II: The evolution of large-scale Web sites and architectures 1. Speaking from a stand-alone trading website
All the function modules and data are on a single server, interacting with each module through a method call within the JVM, and the application and database are accessed through JDBC.
2. Single-Machine load alarm, database and application separation
As traffic increases and server load continues to rise, consider separating the application server from the database server.
3. Application server load alarm, how to get the application server to cluster
When the application server pressure increases, according to the application server monitoring results, you can consider the server from one to two, increase the server after the need to solve the following problems:
- The user's choice of application server can be resolved by adding a load balancer device before the application server.
- Session problem.
3.1 Introducing Load Balancing devices
Architecture after introducing load-balanced devices
3.2 Solving the session Problem of application server
the HTTP protocol native is a stateless protocol that requires a reply-to-Session state mechanism based on the HTTP protocol. The specific implementation is: At the beginning of the call, assign a unique reply to the identity (SessionID), through the cookie to tell the browser, each subsequent request, the browser will bring this session ID to tell the server to request data that session. On the Web server, each session has a separate storage, saving different reply information. If a cookie is disabled, it is common practice to place the callback identifier in the URL parameter.
As shown, if the first site request on the left side of the server, then the session is saved on the left side of the server, if not to do processing, there is no guarantee that each request falls on the same server, this is the session problem.
Session Stickey
Ensure that the same reply request falls on the consent Web server, called Session Stickey.
This scheme allows the same session request to be sent to the same server for processing each time, which facilitates server-side local caching of the session. However, the following problems are present:
- If the server is down or restarted, the data on that server will be lost.
- Call back is the application layer information, then load balancing to save the same reply request to the same Web server, the application layer load balancing is required, the cost is greater than the fourth level of exchange.
- The load balancer becomes a stateful node where you save the mappings for a session to a specific Web server. Compared to stateless points, memory consumption is greater and disaster tolerance is more troublesome.
Session Replication
Session replication in the Web server to increase the synchronization mechanism between the sessions, by ensuring that the session data between different Web services consistent, to solve the session problem. The general application container supports session Replication. Compared with session replication, it has no requirement for load balancing devices, but its native also has some shortcomings.
- Synchronizing session data creates the overhead of network bandwidth.
- Each server to save all the session data, if the whole cluster session number of many, each machine user save session data occupy memory serious.
Session Central Storage
The problem with the programme:
- Read-write session data introduces the network operation, which is relative to the local data read, the problem lies in the existence of delay and instability.
- If there is a problem with a centralized session server or cluster, it can have a serious impact on the application.
Cookie Based
The program passes the session data through a cookie, stores the session data in a cookie, and then generates the corresponding session data from the cookie on the Web server. This scheme does not depend on an external storage system, and there is no network latency from the external system to obtain and write the session data, relative to the session.
Deficiencies in the scheme:
- Limit on the length of the cookie.
- Security.
- Bandwidth consumption.
- Performance impact. Each HTTP request and response comes with session data, and for the Web server, the result of the response is reduced and the number of concurrent support is greater.
4. Database reading pressure is larger, read and write separationuse database as read library
Problems caused by read and write separation:
- Data replication issues.
- Data Source Selection Issues
The database system generally provides the data replication function, but it also needs to consider the data replication delay problem for data replication. Data replication latency can lead to short-term inconsistency of data. At the same time, for the main library to write operations, read in the transaction to go to the main library, but also to consider the standby library relative to the main library of the delay.
search engine is actually a read library
The first thing the search engine needs to work on is to build the index based on the data being searched for.
The search cluster is used the same way as the Read library. The search system can be indexed from two dimensions: one is divided by the whole volume/increment, and the other is in real-time/non-real-time partitioning. The technology of search engine solves the problem of reading in some scenes while searching in the station, and provides better query efficiency.
a powerful tool for accelerating data reading-caching
Data caching
The data cache in large-scale systems is mainly used to share the reading pressure of the database. Typically, "hot" data is stored in the cache instead of all the data. Apply access to the cache, and if the cache does not exist, the data is read out and placed in the cache.
Using caching to speed up the reading of data, a key indicator is the cache hit ratio, so the cache hit ratio is low, which means there are still a few requests back into the database. At the same time, the distribution of data in the update strategy should be combined with specific scenarios to consider. In the distribution, the problem to be considered is to avoid the local hotspot, and the cache server expansion or the shrinking capacity to be as smooth as possible. In the update of the cache, there are some policies such as timing invalidation, data change invalidation and data change updating.
5. Introduction of distributed Storage systems
Distributed storage systems play a role in storage, which is to provide read/write support. The distributed storage System is a direct alternative to the main library, as opposed to the read-write separation of the source. Distributed Storage System provides a high capacity, high concurrent access, data redundancy disaster tolerant support through the cluster.
6. The database is experiencing bottlenecks after read and write separationdedicated library, vertical data splitting
Vertical splitting means splitting different business data from a database into a different database.
when data from different businesses is split from one database to multiple databases, it is necessary to consider how to handle transactions across the business from the original single machine. One approach is to use distributed transactions, where performance is significantly lower than for single-machine transactions, and the other is to remove transactions or not pursue strong transactional support. a vertical split of the database solves the stress problem of putting all business data in one database. and can be optimized according to different business characteristics.
Vertical split of the single machine encountered bottlenecks, the database level of split
The horizontal split of the database is to split the data in the same table into two databases. The reason that the data is split horizontally is that the amount of data or the amount of updates to the data table in a business reaches the bottleneck of a single database, so that the table can be split into two or more databases. The database horizontal split has some impact on the business: first of all, to solve the problem of SQL routing, second, the primary key processing will also be different; Finally, because the same business data is split into different databases, some data queries need to read data from two databases. Paging is more difficult to handle if the amount of data is large.
7. Application-facing challenges after database issues are resolvedSplit Apps
With the development of the business, the application of more and more functions, the application will be more and more large, it is necessary to take apart the application, from one application to two or more applications.
take the road of service
Access to the business is not only a method call inside a single machine, but also a remote service invocation, and the next shared code is no longer scattered in different applications, and these implementations are placed in each service center.
"Large Web site system and Java Middleware Practical Learning notes"-1