Monitorlogging Transformation (Message Access)Pre-Retrofit architecture:
can be seen in the original process, a large number of business analysis, business access coupled in the Web services layer. A large number of operations, resulting in thread -linear suspend threads.
after transformation:
The business communication is abstracted into Monitorqueuemanager, and the business topic abstraction is placed in the respective collection.
shaped like:
abstraction is a structure topic,content a number of topics for business. It is convenient to switch to MQ or other queues later.
monitorschedule Transformation (Message centralized processing)Original Processing Flow
At that time the business was relatively small, there was only one main processing flow, so strongly coupled to the main method, the extension is basically equal to 0. In addition to the earlier development of a hasty, coded comments basically did not.
Now it's time to put all the business processing in monitorloging into the monitorschedule. Business grows, and if the architecture doesn't change it's going to be a disaster (maintenance or business process additions).
after the transformation process:
It seems clear, too, that the original business was divided into categories according to business events. There is a problem using the listener to handle the event itself. How to manage the processing speed of a business in multi-threaded situations. The original bottleneck was placed in MongoDB, but if the thread reads too fast, the performance bottleneck has been moved into the task operation. capped CollectionHere we first say MongoDB's capped collection:
- Fixed length
- LRU Queue
- Ring-mounted structure, automatic coverage of old data
- Input queue data can be comparable to direct read and write disk
- Based on log form (non-modifiable, not indexed, speed is the same as write disk)
in fact, its greatest advantage is the biggest disadvantage,
- indexing efficiency will be a common collection, Poor query Efficiency
- Do not support shards, and then which MONGO built, it can only be used under which MONGO
So, as you can see, if you write to MongoDB's collection queue, the serialization capability makes the data a more cached way. Code LogicEvent
the structure of the event is simple:
main three content:
- QueueName the name of the queue
- Topic the subject of the message
- The content of the source real message
Listener
The main use of spring Applicationmulticast event broadcast, the use of template method design, reduce coupling, but also greatly reduce the difficulty of business implementation.
The logic of business implementation, where the internal classes are used to classify the business to prevent too many command occurrences
interface classes for commands
Reader
There are two types of interfaces defined here:
- Persistence layer
- Cache Layer
using the modified pattern design, common by template class dependency
abstract class Implementation
This allows the code to be written much less
Let's take a look at the specific implementation class: This design is much better than the previous ones .
Problems encountered in the test
- Size limit for collection
if the number of fixed records is 100, then there will be coverage for collection. It is important to set a reasonable length, currently set to 2 G single collection. Ensure that the data on the day of the cache, even if the thread is stuck or otherwise, can be reasonably cached.
- Thread, etc. pause position
before the setting thread pauses, sleep is performed during the read process. This will waste the system resources, but if there is a problem with frequent rotation, MongoDB's link resource is wasted (frequently requested). In summary, the approach is to read the data when it is not dormant, in the absence of data at the time of 200 milliseconds to wait. you can calculate one account, if one execution waits 200 milliseconds, the processing time is 100 Hao second/500 bar. Then there will be 500 wait 200 milliseconds, a second can only handle 1000/(200+100) * 500 = 1500 data, wasted 400 milliseconds. So you need to change to no data to wait for the operation, if there is no wait.
Performance optimization of capped collection based on MongoDB