2.4 partial acquisition mode
The partial Acquistion (partial retrieval) mode describes how to divide resource acquisition into multiple stages to optimize resource management. Each stage gets a part of the resource, depending on system constraints, such as the availability of memory and other resources.
1. Problem
Systems with high robustness and scalability must efficiently obtain resources, including local and remote resources. Obtaining resources in advance is important to meet the availability and accessibility constraints of resources. However, if these systems obtain all the resources from the beginning, it will bring a lot of extra overhead and waste a lot of resources. On the other hand, it is unrealistic to obtain all resources by delay, because some resources may be used when the application system starts or recovers. To address these conflicting resource acquisition requirements, we need to pay attention to the following issues:
1) availability ). Resource acquisition should be affected by parameters (such as available system memory, CPU load, and availability of other resources.
2) flexibility ). The solution should work equally well for fixed-size resources and unknown or unpredictable-size resources.
3) scalability ). The solution should be scalable to the resource size.
4) performance ). Resource Acquisition should have as little impact on system performance as possible.
2. Solution
Divide the resource acquisition into two or more steps. Obtain a part of the resource in each step. One or more policies should be used to configure the number of resources obtained in each step. For example, the number of resources obtained in each step can be determined by considering the available buffer zone. The system response time requirement and the availability policy of the dependent resources. When a resource is partially obtained, the resource user can start to use it. It is assumed that the complete resource is not required before use.
You can use modes such as eager acquisition and lazy acquisition to determine when to perform one or more steps to obtain resources. The partial acquisition mode determines the number of steps to obtain resources and the proportion of resources to be obtained in each step.
3. Structure
The resource user obtains and uses the resource.
A resource is an entity (such as audio, video, and video content) that is obtained in multiple steps.
Resource providers manage and provide multiple resources.
4. Implementation
1) determine the number of steps. The number of steps to obtain resources depends on system constraints, such as available memory and CPU, and other factors, such as time constraints and the availability of the dependent resources. For resources of unknown or unpredictable dimensions, it is impossible to decide to obtain the entire resource in several steps. In this case, there is no upper limit on the number of steps, and the steps will be executed step by step until the resources are fully obtained.
2) Select an access policy. You can use modes such as lazy acquisition and eager acquisition to determine when to perform one or more resource acquisition steps. For example, you can use the eager acquisition mode to obtain the starting part of the resource, and then use the lazy acquisition mode to obtain the remaining part of the resource, or after a system is started, the user has not requested the intermediate time of the resource to obtain the resource.
3) Determine how much data is obtained. Configure a policy to determine how many resources each step needs to obtain. You can configure different policies to determine how many resources are obtained in each step. If the resource size is determined, you can use a simple policy to evenly allocate the resources obtained in each step. More complex policies consider available system resources. For example, when there is enough memory, such policies may obtain more resources in one step. Later, when the system resources are insufficient, such a policy may obtain a small amount of resources.
If the size of the resource to be obtained is unknown or unpredictable, this adaptive policy can be used. You can also configure other policies to take advantage of other parameters, such as the required time. If there is no system constraint, another policy can greedy to obtain as many resources as possible. This policy ensures that the entire resource is obtained in the shortest possible time. In order to determine which policy is suitable, it is necessary to understand the application well.Program.
4) Introduce cache (optional ). Decide whether to cache some acquired resources. If the resource size is unknown, or the entire resource needs to be merged somewhere before use, the cache resource is useful. If the resource needs to be cached, you need to decide how much space to allocate the cache to ensure that the entire resource can be loaded. For unknown or uncertain resources, the allocated buffer size should be within the system limit (such as available memory), but should be large enough to process the upper limit of the system's resource size.
5) Implement the acquisition trigger and establish a mechanism to execute each step of resource acquisition. Such a mechanism should be responsible for using multiple steps to obtain different parts of the resource. Reactor (Reactor) and other patterns can be used to implement such a mechanism.
6) handle error conditions and partially fail. Error conditions and partial failures are the characteristics of a distributed system. When partial acquisition mode is used, an error may occur after one or more steps. The result may be that some resources are obtained, but attempts to obtain the remaining parts of the resources will fail. Depending on the meaning of the application, such failure may end or be unacceptable.
One way to handle partial failures is to use the Coordinator mode. This mode helps ensure that all the steps for obtaining resources are successfully completed or that none of the steps are successful.
5. Conclusion
Advantages:
1) Reactive behavior ). The partial acquisition mode enables us to obtain resources that are slowly available or partially available. If the partial acquisition mode is not used, the resource user has to wait for a period of time to wait for the entire resource to become available.
2) scalability ). The partial acquisition mode allows the size of the resource to be obtained to be scalable. The number of steps for obtaining resources can be configured based on the size of the resource to be obtained.
3) configurability ). In the partial acquisition mode, you can configure one or more policies to determine the number of resources to be obtained and the number of resources to be obtained in one step.
Disadvantages:
1) complexity ). The user processes the resourceAlgorithmYou can obtain only a portion of the resources. This may bring complexity to the application. In addition, using the partial acquisition mode can make error handling more complicated. If one step fails, the error handling policy must ensure that the complete action is re-executed or corrected. On the other hand, error handling will become robust. If one step fails to be obtained, you can re-execute the same step without re-performing all the operations.
2) overhead ). The partial acquisition mode requires that resources be obtained step by step. This may incur additional call overhead (multiple calls to obtain different parts of the same resource ).