Model-Oriented Software Architecture 3-resource management model Reading Notes (2)-Lazy Acquisition Model

Source: Internet
Author: User

2.2 lazy acquisition mode

The lazy acquisition mode delays the resource acquisition to the last point of the system execution, so as to optimize resource usage.

 

1. Problem

Limited resource availability is a constraint on all software systems. In addition, if the available resources are not properly managed, it may cause bottlenecks to the system and significantly affect the system performance and stability. To ensure that resources are available when needed, most systems obtain resources at startup. However, obtaining resources in the early stage will bring about a lot of overhead, and lead to a waste of resources (especially if the resources are not immediately needed ).

Systems that must acquire and manage expensive resources need a way to reduce the initial overhead of resources. If these systems obtain all the resources from the beginning, it will lead to a large amount of overhead and many resources will be wasted without any need. When solving these problems, you must pay attention to the following points:

1) availability ). Resource acquisition should be controlled to minimize the possibility of resource shortage and ensure that there are sufficient resources available when necessary.

2) Stability (stability ). Resource shortage may cause system instability. Therefore, resources should be obtained in a way that has the minimum impact on system stability.

3) Quick system start-up ). Resource Acquisition during system startup should be implemented by optimizing the system startup time.

4) Transparency ). The solution should be transparent to resource users.

 

2. Solution

Obtain resources at the last possible moment. Do not obtain resources unless necessary. When a resource user needs to obtain the resource at the beginning, a resource proxy is created and returned. When a resource user attempts to access a resource, the resource agent obtains the actual resource and redirects the access request of the resource user to the resource. Therefore, the resource user depends on the resource proxy. However, since the interfaces provided by the resource proxy are the same as those provided by the resource, it is transparent for the resource user to access the resource or the resource proxy.

A proxy is used to indicate resources that may be expensive to obtain. The total cost of obtaining a group of resources can be minimized, and because a large number of resources are not obtained from the beginning, therefore, the resource issues that need to be managed at the same time are minimized.

 

3. Structure

The resource user obtains and uses the resource.

A resource is a connection or memory entity.

The resource proxy intercepts the resource users' acquisition of the resource, and delivers the delayed retrieval of the resource to the resource user.

Resource providers manage and provide multiple resources.

 

 

4. Implementation

1) confirm the resources to be obtained by delay. Confirm resources with one or more of the following attributes through performance analysis and system analysis:

· Obtain expensive resources.

· A limited number of resources.

· Unused resources long after obtaining them.

Review each resource and its usage, and decide whether the lazy acquisition mode, overall resource availability, system stability, and system startup time can be improved. Apply the following implementation steps to each identified resource.

2) define the resource proxy interface. For each resource that requires delayed retrieval, a resource proxy must be defined as virtual proxy. Its interfaces are identical with those of resources.

3) implement resource proxy. Implement resource proxy to hide the delay of obtaining a pair. The resource proxy obtains the resource only when the resource user actually accesses the resource. Once the actual resource is obtained, the resource proxy uses a delegate to process all resource requests. The resource proxy can also initialize resources after obtaining them.

4) define an access policy. Defines the policy for the resource proxy to actually obtain resources from the resource provider. You can use the Strategy Mode to configure different types of policies. A simple policy can be to delay the resource acquisition to the resource user's access to the resource. Other strategies can be used to obtain resources based on a certain state machine. For example, the instantiation of a component may trigger the resource proxy of another existing component to obtain the corresponding resource. In addition, the resource proxy can also provide the ability to disable the latency acquisition mechanism, so that resources will be obtained immediately.

5) implement the correct resource release mechanism for delayed access to resources. If the resource user does not explicitly release the resource, you can use the Evictor mode or the leasing mode to automatically release the resource. In this way, the resources to be obtained by delay must implement evictioninterface or be registered with the leasing provider.

 

5. Conclusion

Advantages:

1) availability ). The lazy acquisition mode ensures that all resources are not obtained from the beginning. This helps minimize the possibility of a system lack of resources and access to unnecessary resources.

2) Stability (stability ). The lazy acquisition mode ensures that resources are obtained only when necessary. This avoids unnecessary resource acquisition at the beginning, reduces the possibility of resource depletion, and makes the system more stable.

3) Optimize the system startup time (optimal system start-up ). The lazy acquisition mode ensures that resources that are not immediately required are obtained later, which helps optimize the system startup time.

4) Transparency ). The lazy acquisition mode is transparent to resource users. The resource agent hides the actual resource acquisition operations from the resource users.

 

Disadvantages:

1) space overhead ). This mode brings a little space overhead, because the proxy required for indirect needs additional memory.

2) time overhead ). Execution Delay acquisition can cause a significant delay when obtaining resources, and due to an additional indirect levelProgramExecution brings time overhead. Such behavior may be unacceptable for real-time systems.

3) predictability ). The behavior of the system that gets delayed may become unpredictable. If multiple parts of the system obtain resources as late as possible, the performance curve changes sharply when all parts of the system attempt to obtain resources at the same time.

Related Article

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.