Relative to the single-machine system, the distributed system is very complex, involving a lot of technology, as a cock wire, fortunate to be able to work in a large-scale distributed system, it is here to record some shallow understanding, as their future learning route reference.
I. Overview of Distributed Systems
Distributed systems tend to split applications into multiple applications, and each team maintains an application that communicates with applications through remote process calls or message middleware. The advantages of this system is to be able to achieve high cohesion and low coupling, can support the rapid development of business, the disadvantage is the operation and maintenance costs greatly improved, the system has a problem, the need for full-link troubleshooting. , the user uses application A, application a first needs to invoke application B, and then invokes application C, where application B is called to apply D and E, and any one of these apps hangs, which affects the entire system's link. The above is just a simple example of the fact that the dependencies between real systems are often very complex.
The technology stack under the two-distributed system
In this main is to dig a pit, follow-up I will one by one filled ...
For an application in a distributed system, it often has three portals: a remote procedure call (another application calls my service), a message middleware (I subscribe to other system messages, other systems send me messages), Web Access (the primary access page), It has many exits: Remote procedure calls (services that call other applications), message middleware (I send messages to the messaging server for other applications to consume), access to distributed caches, access to distributed logs, access to databases, and dispatch tasks. With entrances and exits, the rest is the core of the application, including the core logic code and the auxiliary framework. For a distributed system, one thing is essential, that is, the configuration center. Whether remote procedure calls, message middleware, or distributed caches, they all need to get an address list from the configuration center.
The following is a brief summary of the technologies involved in distributed systems:
1, the remote Service framework: The remote service framework is indispensable in the distributed system, for the remote service framework, the key points are: service consumers, service providers, protocols (Java serial number, deserialization, Hessian protocol, etc.), network (NIO, multiplexing, etc.), address list. It is difficult to choose the protocol, optimize the network and get the address list. At present, the industry more well-known open source framework: Apache Thrift (cross-language), Dubbo and so on.
2, Message Middleware: The introduction of message middleware is used to reduce the coupling between applications. For upstream applications, it often relies on a lot of downstream applications, and if all of the synchronous calls (remote procedure calls are synchronous calls), then the upstream application must wait until all downstream applications are successfully executed before returning to success, which is often intolerable. To do this, synchronous asynchrony is required, and message middleware can implement this kind of asynchrony. With the message middleware, the upstream application simply sends a message to the messaging server, it does not wait for all applications to finish, it can return to execution ahead of time, and the messaging server sends messages to these downstream applications to notify them of execution. Although asynchrony reduces the coupling between applications, new problems are introduced. For example, the downstream system is executed, while the upstream system is actually the success of the return, which leads to inconsistent state. To solve this problem, you need to use the message middleware itself, the retry mechanism, for some system exceptions, the need to retry until successful, for the application itself, the retry should be idempotent, and use a forward state machine to manage the state of the entire system. The specification of message middleware can refer to JMS, and the industry also has mature open source solutions, such as ACTIVITYMQ.
3, wrapper layer: Warpper layer is mainly the upper two entrance packaging layer, for some exception management, log management and AOP interception
4, the MVC framework: This does not have to say, personally prefer Spring MVC, have time to read the source code
5. Distributed cache: Wait for pits.
6. Distributed log: Wait for pits.
7. File storage System: Wait for pits.
8, IOC container: At present the most used is the spring container, for spring's core of several modules, you can refer to the spring source depth analysis
9, ORM Framework: ORM Best Use Ibatis, not recommended hibernate, because Ibatis can control SQL, in large data volume reading and writing, SQL must be optimized. As for the architecture of the ibatis itself, I will write the article alone when I am free.
10. Scheduling Engine: The engine used to perform asynchronous scheduled tasks, to be pits.
11. Distributed data Access layer: learning in progress.
12, Configuration Center: Unified Configuration Management Center, waiting for pits.
13, Web container: Tomcat, combined with "Tomcat Source code Analysis" and tomcat itself source code, it should be easy to understand the architecture and implementation of Tomcat.
14, Business logic layer: Process engine and rule engine, with spring to govern the very volatile business logic, followed by a separate process engine to write
My understanding of the Java Distributed System