Model-Oriented Software Architecture 3-resource management model Reading Notes (9)-leasing Model

Source: Internet
Author: User

4.1 leasing Mode

The leasing mode simplifies resource release by associating resources with time-based leases when obtaining resources. When the lease expires and is not updated, the resource is automatically released.

 

1. Problem

Highly robust and scalable systems must efficiently manage resources. There are many types of resources, including local and distributed services, database sessions, and security tokens. In a typical use case, a resource user obtains the interface of the resource provider and then requests one or more resources from the provider. If the provider gives the resource, the resource user starts to use the resource. However, after a period of time, resource users may no longer need some of these resources. Unless the resource user explicitly terminates the relationship with the provider and releases the resource, the unused resources will still be occupied by unnecessary resources. This causes the performance of resource users and providers to decline, and affects the availability of resources to other resource users.

When both the resource user and the resource provider are distributed systems, the machine where the provider is located may crash after a period of time, or the provider does not provide certain resources. Unless the resource user is explicitly prompted that the resource is no longer available, the resource user may continue to reference invalid resources.

All these results indicate that some resources on the resource user side may never be abandoned. A solution to this problem is to use a monitoring tool to intermittently check user resource usage and resource usage by resource users. This tool can recommend resources released by resource users. However, this solution is both troublesome and error-prone, and monitoring tools are not conducive to performance.

To solve this problem effectively and efficiently, you need to pay attention to the following points:

1) simplicity ). For resource users, resource management should be simple, so that resource users can release resources that are no longer needed.

2) availability ). Resources that are no longer used by resource users or that are unavailable should be released immediately so that they can be used by new resource users. For example, resources associated with network connections should be released after the connection is disconnected.

3) optimality ). The system burden caused by unused resources should be minimized.

4) authenticity (actuality ). When a new resource is available, the resource user should not use the expired version of the resource.

 

2. Solution

Introduce a lease for each resource used by the resource user. The grantee provides the lease and the owner obtains the lease. The subscriber is generally a resource provider, and the subscriber is usually a resource user. The lease term indicates the length of time that a resource user can use the resource.

If the resource is held by the resource user, once the time limit is exceeded, we will say that the lease has expired and the corresponding resource will be released by the resource user. On the other hand, if the resource is held by the resource provider and the resource user holds the reference of the resource, the reference of the resource becomes invalid when the lease expires and is released by the resource user. In addition, resource providers can release resources.

When the lease is valid, the lease owner can cancel the lease. In this case, the corresponding resources are also released. Before the lease expires, the lease owner can apply for an extension of the lease from the lease authorizer. If the lease is extended, the corresponding resources will continue to be available.

 

3. Structure

Resources provide certain types of functions or services.

The lease (lease) provides a time recording method that can be associated with the availability of resources.

The lease granted by the grantor to the resource. The subscriber of a lease is generally the resource provider.

The owner (holder) obtains the lease of the resource. The owner of a lease is generally a resource user.

 

 

4. Implementation

1) decide the resources to be associated with the lease. All resources with time-based availability can be associated with leases. This includes short-lived, discontinuous resources, and resources that are frequently updated by new versions.

2) determine the lease creation policy. The subscriber creates a lease for each used resource. If multiple resource users share one resource, multiple leases will be created for the resource. You can use a factory to create a lease. The lease period must be specified when the lease is created. The lease term can be determined by the type of resources, the requested lease term, and the policy of the subscriber. The lease requestor and the lease supervisor can coordinate the lease term of the lease.

The resource user may want to pass the resource and related lease to another resource user. You can use the lease creation policy to determine whether this can be done. If a resource and its associated lease can be transferred to other resource users, the lease must be operated so that all its relationships can be changed.

3) provides the lease holder function. Each lease owner must implement a notification interface through which the lease Authorizer can notify the lease owner that the lease has expired. When a resource user obtains a resource and its corresponding lease from the subscriber, it will register this interface with the subscriber. Resource users can release resources that have expired the lease in this interface.

4) provides the leasing Authorizer function. Once a lease is created, the supervisor needs to maintain the ing between the lease and the corresponding resources. This allows the grantor to track the time when the resource is used and decide whether the resource can still be granted a new lease.

In addition, in order to support the announcement of resource users, it is also necessary to map the lease to the corresponding resource users. The observer mode describes how to implement such notifications.

5) determine the leasing responsibilities. If the lease can be updated, it is necessary to determine who is responsible for the update. If a lease is an active entity, it can automatically update itself; otherwise, the update process may need to be rescheduled by the authorizer and the owner. Re-coordination of the lease may lead to a new lease policy, including the lease Update time.

6) determine the lease expiration policy. Once the lease expires and is not updated, the resources associated with it need to be released. This can be performed automatically, such as using the Evictor mode or requiring resource user intervention. Similarly, the lease Authorizer needs to delete the mappings between the lease, resources, and resource users. A lease usually contains an asynchronous completion token (asynchronous completion tag) that carries information about its owner, so that the clearing can be completed correctly when the lease expires.

 

5. Conclusion

Advantages:

1) simplicity ). The leasing mode simplifies resource management for resource users. Once a resource lease expires and the resource user does not update it, the resource can be automatically released.

2) efficiency of use ). Resource providers can control resource usage more efficiently. By binding resource usage with time-based lease, the resource provider can release unused resources as soon as possible to avoid waste, so that resources can be handed over to new resource users, this minimizes the system overhead caused by different resources.

3) Versioning ). The leasing mode allows the old version of the resource to be replaced by the new version. The resource provider can provide resource users with a new version of the resource when the lease is updated.

4) enhanced system stability (enhanced system stability ). The leasing mode helps improve system stability by ensuring that resource users do not access invalid resources. In addition, the leasing mode helps reduce unnecessary resource waste and avoid resource shortage.

 

Disadvantages:

1) additional overhead (additional overhead ). The leasing mode requires that an additional object (lease) be created for each resource provided by the resource provider to the resource user ). Creating a pool for the lease object and allocating and reusing different resources can help ease this problem. In addition, when the lease expires, the resource Authorizer needs to send a notification to the resource user, which also leads to additional expenses.

2) additional applicationsProgramLogic (additional application logic ). The leasing mode requires that the application logic support the concept of "dehydration between resource users and resource providers. Application architects need to remember that resources are not infinite and they are not always available. Duplicate leaseCodeAdding a framework can reduce coding complexity.

3) Timing Monitor (timer watchdog ). Both the resource provider and the resource user must be able to determine when the resource expires. This requires the support of some timer mechanism, which may not be possible in some legacy systems. However, if the legacy systems are event-based applications, they can perceive the timer with little overhead.

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.