CN110058948A - A kind of resource monitoring method, device, equipment and medium - Google Patents
A kind of resource monitoring method, device, equipment and medium Download PDFInfo
- Publication number
- CN110058948A CN110058948A CN201910351017.4A CN201910351017A CN110058948A CN 110058948 A CN110058948 A CN 110058948A CN 201910351017 A CN201910351017 A CN 201910351017A CN 110058948 A CN110058948 A CN 110058948A
- Authority
- CN
- China
- Prior art keywords
- resource
- applicant
- back end
- data structure
- identity
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
- G06F9/5016—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
- G06F9/5022—Mechanisms to release resources
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/52—Program synchronisation; Mutual exclusion, e.g. by means of semaphores
- G06F9/524—Deadlock detection or avoidance
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/50—Indexing scheme relating to G06F9/50
- G06F2209/5018—Thread allocation
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/50—Indexing scheme relating to G06F9/50
- G06F2209/508—Monitor
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
- Management, Administration, Business Operations System, And Electronic Commerce (AREA)
Abstract
The embodiment of the present application discloses a kind of resource monitoring method, this method comprises: creation back end records the identity of first applicant when the first applicant applies for resource, which is saved into the corresponding data structure of the resource;When the second applicant calls the resource exception to terminate, the identity that whether there is the second applicant is checked in the corresponding data structure of the resource, if there are still the identity of the second applicant in data structure, the corresponding back end of the second applicant is correspondingly deleted from data structure;So, in the case where applicant calls resource exception to terminate, it can be by the back end that judges whether to record applicant's identity in the corresponding data structure of resource, to determine whether applicant holds resource before exiting extremely, to guarantee that the data section points in data structure are capable of the reference count of accurate characterization resource.
Description
Technical field
This application involves resource management techniques field more particularly to a kind of resource monitoring method, device, equipment and media.
Background technique
Reference count is one of computer programming language memory management technology, (be can be pair aiming at resource
As, memory or disk space etc.) its number being cited is recorded, the corresponding reference count of the resource can add and can subtract, and work as resource
Corresponding reference count can be discharged when becoming zero.
Multi-process/thread, which is applied, carrys out managing shared resource usually using reference count.When applying for shared resource, will quote
It counts and adds one, give back after applied shared resource and reference count is subtracted one.When quoting resource counting is not zero, resource cannot
It is modified, it can not be destroyed.
Reference count is realized usually using integer atom variable at present, mutual exclusion lock or operating system atom is cooperated to refer to
It enables, realizes the plus-minus of reference count.But this reference count scheme is in the case where process/thread abnormal end, it can not be true
The fixed process/thread exits whether hold resource before, to can not correctly restore the reference count of resource, influences the reading of resource
It takes, modify and discharges.
Summary of the invention
The embodiment of the present application provides a kind of resource monitoring method, device, equipment and medium, calls resource different in applicant
In the case where often terminating, reference count can be accurately determined, guarantees that the reading, modification and release of resource are normally carried out.
In view of this, the application first aspect provides a kind of resource monitoring method, comprising:
When the first applicant applies for resource, back end is created by the back end and records first applicant
Identity, and the back end is saved into data structure, is recorded in the data structure corresponding with the resource
Each back end;
When the second applicant calls the resource exception to terminate, check in the data structure with the presence or absence of described second
The identity of applicant, when in the data structure there are when the identity of second applicant, then from the data
The corresponding back end of second applicant is deleted in structure.
Optionally, when first applicant applies for the resource, the corresponding lock of the resource is obtained, by the number
When saving according to node to the data structure, the corresponding lock of the resource is discharged, first applicant is allowed to hold the money
Source.
Optionally, when first applicant gives back the resource, the corresponding lock of the resource is obtained, from the data
The corresponding back end of first applicant is deleted in structure, discharges the corresponding lock of the resource.
Optionally, the data structure uses single linked list;The back end includes data field and pointer field, described
Data field is used to record the identity of applicant, and the pointer field is for recording a data node address.
Optionally, the creation back end records the identity of first applicant by the back end,
And the back end is saved into data structure, comprising:
Back end is created, sets the data field of the back end to the identity of first applicant,
Set empty for the pointer field of the back end;
Set the pointer field of the last one back end in the data structure on the pointer of the back end.
Optionally, the creation back end records the identity of first applicant by the back end,
And the back end is saved into data structure, comprising:
Back end is created, sets the data field of the back end to the identity of first applicant,
Set the pointer field of the back end to the address of current head node in the data structure;
Set the pointer field of head node current in the data structure to the address of the back end.Optionally,
The chained list is using intrusive chained list.
Optionally, the applicant is process or thread.
The application second aspect provides a kind of monitoring resource device, comprising:
Logging modle, for when the first applicant applies for resource, creation back end to be recorded by the back end
The identity of first applicant, and the back end is saved into data structure, it is recorded in the data structure
Each back end corresponding with the resource;
Recovery module is counted, for checking the data structure when the second applicant calls the resource exception to terminate
In whether there is second applicant identity, when there are the identity marks of second applicant in the data structure
When knowledge, then the corresponding back end of second applicant is deleted from the data structure.
Optionally, described device further include:
Apply for module, for obtaining the corresponding lock of the resource when first applicant applies for the resource, is inciting somebody to action
When the back end is saved to the data structure, the corresponding lock of the resource is discharged, first applicant is allowed to hold
The resource.
Optionally, described device further include:
Module is given back, for obtaining the corresponding lock of the resource when first applicant gives back the resource, from institute
It states and deletes the corresponding back end of first applicant in data structure, discharge the corresponding lock of the resource.
Optionally, the data structure uses single linked list;The back end includes data field and pointer field, described
Data field is used to record the identity of applicant, and the pointer field is for recording a data node address.
Optionally, the logging modle is specifically used for:
Back end is created, sets the data field of the back end to the identity of first applicant,
Set empty for the pointer field of the back end;
Set the pointer field of the last one back end in the data structure on the pointer of the back end.
Optionally, the logging modle is specifically used for:
Back end is created, sets the data field of the back end to the identity of first applicant,
Set the pointer field of the back end to the address of current head node in the data structure;
Set the pointer field of head node current in the data structure to the address of the back end.Optionally,
The chained list is using intrusive chained list.
Optionally, the applicant is process or thread.
The application third aspect provides a kind of storage equipment, and the equipment includes processor and memory:
Said program code is transferred to the processor for storing program code by the memory;
The processor is used to execute the resource prison as described in above-mentioned first aspect according to the instruction in said program code
The step of prosecutor method.
The application fourth aspect provides a kind of computer readable storage medium, and the computer readable storage medium is for depositing
Program code is stored up, said program code is for executing resource monitoring method described in above-mentioned first aspect.
As can be seen from the above technical solutions, the embodiment of the present application has the advantage that
The embodiment of the present application provides a kind of resource monitoring method, and this method, can correspondingly when applicant applies for resource
The identity of applicant is recorded, thus guarantee in the case where applicant calls resource exception to terminate, it can be according to being recorded
The identity of applicant accurately determine the reference count of the resource.Specifically, when the first applicant applies for resource, wound
The identity that back end records first applicant is built, which is saved into data structure corresponding to the resource
In;When the second applicant calls the resource exception to terminate, check in the corresponding data structure of the resource with the presence or absence of the second Shen
Please person identity, if illustrating that second applicant exists there are still the identity of the second applicant in data structure
Hold the resource before calling resource exception to terminate, at this point, correspondingly deleting the corresponding data of the second applicant from data structure
Node;In this way, can be in the corresponding data structure of resource by judging in the case where applicant calls resource exception to terminate
It is no accurately to update the data structure for corresponding to the resource there are still the back end that record has applicant's identity, thus
Guarantee that the data section for including in data structure points are accurate reference count.
Detailed description of the invention
In order to illustrate the technical solutions in the embodiments of the present application or in the prior art more clearly, to embodiment or will show below
There is attached drawing needed in technical description to be briefly described, it should be apparent that, the accompanying drawings in the following description is only this
Some embodiments of application without any creative labor, may be used also for those of ordinary skill in the art
To obtain other drawings based on these drawings.
Fig. 1 is the application scenarios schematic diagram of resource monitoring method provided by the embodiments of the present application;
Fig. 2 is the flow diagram of resource monitoring method provided by the embodiments of the present application;
Fig. 3 is the schematic diagram of single-stranded list data structure provided by the embodiments of the present application;
Fig. 4 is the structural schematic diagram of monitoring resource device provided by the embodiments of the present application;
Fig. 5 is the structural schematic diagram of server provided by the embodiments of the present application;
Fig. 6 is the structural schematic diagram of terminal device provided by the embodiments of the present application.
Specific embodiment
In order to make those skilled in the art more fully understand application scheme, below in conjunction in the embodiment of the present application
Attached drawing, the technical scheme in the embodiment of the application is clearly and completely described, it is clear that described embodiment is only this
Apply for a part of the embodiment, instead of all the embodiments.Based on the embodiment in the application, those of ordinary skill in the art exist
Every other embodiment obtained under the premise of creative work is not made, shall fall in the protection scope of this application.
The description and claims of this application and term " first ", " second ", " third ", " in above-mentioned attached drawing
The (if present)s such as four " are to be used to distinguish similar objects, without being used to describe a particular order or precedence order.It should manage
The data that solution uses in this way are interchangeable under appropriate circumstances, so as to embodiments herein described herein can in addition to
Here the sequence other than those of diagram or description is implemented.In addition, term " includes " and " having " and their any deformation,
Be intended to cover it is non-exclusive include, for example, containing the process, method of a series of steps or units, system, product or setting
It is standby those of to be not necessarily limited to be clearly listed step or unit, but may include be not clearly listed or for these mistakes
The intrinsic other step or units of journey, method, product or equipment.
In the prior art, the reference count of resource is realized usually using integer atom variable, cooperates mutual exclusion lock or operation
System atomic instruction, realizes the plus-minus of reference count.Usually only record is used for the number counted to this reference count scheme, in Shen
Please person access resource exception terminate in the case where, the program can not determine applicant extremely exit before whether still hold money
Therefore source will lead to the reference count that can not correctly restore resource, and then reading, modification and the release to resource are operated
It impacts.
In view of the above-mentioned problems of the prior art, the embodiment of the present application provides a kind of resource monitoring method, this method
When applicant applies for resource, the identity of the applicant of the back end record access resource is correspondingly created, and should
Back end is added in the corresponding data structure of resource, to guarantee when applicant calls resource exception to terminate, Ke Yigen
Determine the applicant before calling resource exception to terminate whether still according to the identity of the applicant recorded in data structure
Hold resource, and then guarantees the reference count for accurately determining resource according to the data section points in data structure.
Specifically, creation back end records the identity of first applicant when the first applicant applies for resource,
The back end is saved into data structure, record has each back end corresponding with the resource in the data structure;
When the second applicant calls the resource exception to terminate, check in the corresponding data structure of the resource with the presence or absence of the second applicant
Identity, if there are the identity of the second applicant in the data structure, illustrate second applicant call provide
Hold the resource before the abnormal end of source, correspondingly deletes the corresponding data section of the second applicant from data structure at this time
Point;Conversely, illustrating that second applicant is calling resource if the identity of second applicant is not present in data structure
The resource is not held before abnormal end, at this time without executing any operation.In this way, calling resource exception to terminate in applicant
In the case where, by judging whether there are still the identity of the applicant in the corresponding data structure of resource, to judge to apply
Whether person holds the resource before calling resource exception to terminate, to guarantee that the data section points in data structure are as accurate
Reference count.
It should be understood that resource monitoring method provided by the embodiments of the present application can be applied to dependent resource management equipment, such as eventually
End equipment, server etc.;Wherein, terminal device is specifically as follows computer, personal digital assistant (Personal Digital
Assitant, PDA), mobile phone, tablet computer etc.;Server is specifically as follows application server, or Web server,
When practical application is disposed, which can be separate server, or cluster server.
Technical solution provided by the embodiments of the present application in order to facilitate understanding, below with reference to application scenarios to the embodiment of the present application
The resource monitoring method of offer is introduced.
Referring to Fig. 1, Fig. 1 is the application scenarios schematic diagram of resource monitoring method provided by the embodiments of the present application;Such as Fig. 1 institute
Show, include disk space 101 in the application scenarios, which can be set in the server, can also be set
In terminal device, for can the person of being applied access resource.
Applicant A, applicant B and applicant C apply for disk space 101 one by one, correspondingly, are used for hyperdisk space
101 equipment will be applicant A, applicant B and applicant C creation back end one by one, in the data section created for applicant A
The identity that applicant A is recorded in point, records the identity of applicant B in the back end created for applicant B,
For the identity for recording applicant C in the back end of applicant C creation, created three back end are saved one by one
In the corresponding data structure of disk space 101;If currently only applicant A, applicant B and applicant's C application disk is empty
Between, then current in data structure correspondingly includes three back end, correspondingly shows that the corresponding reference count of the resource is 3.
If applicant A calls 101 abnormal end of disk space, at this point, checking in the corresponding data structure of disk space 101
Whether there are still the identity of applicant A, if illustrating to apply there are still the identity of applicant A in the data structure
Person A holds the resource of disk space 101 before calling 101 abnormal end of disk space, at this point, correspondingly from data structure
Delete the corresponding back end of applicant A.
As a result, in the case where applicant A calls 101 abnormal end of disk space, by judging that disk space 101 is corresponding
Data structure in whether there are still the identity of the applicant A, to judge applicant A before calling resource exception to terminate
Whether the resource of disk space 101 is held, to guarantee that the data section points in the corresponding data structure of resource are the resource
Corresponding accurate reference count.
It should be understood that above-mentioned application scenarios shown in FIG. 1 are only a kind of example, it in practical applications, can the person's of being applied access
Resource be not limited in disk space, can also be for object, memory etc.;Also, access the quantity of the applicant of resource also simultaneously
It is not limited only to three;Any restriction is not done to the application scenarios of resource monitoring method provided by the embodiments of the present application herein.
Resource monitoring method provided by the present application is introduced below by embodiment.
Referring to fig. 2, Fig. 2 is a kind of flow diagram of resource monitoring method provided by the embodiments of the present application.For the ease of
Description, following embodiments are described using server as executing subject, it should be appreciated that the executing subject of the resource monitoring method is simultaneously
It is not only limited to server, can also be terminal device etc..As shown in Fig. 2, the resource monitoring method the following steps are included:
Step 201: when the first applicant applies for resource, creation back end records described the by the back end
The identity of one applicant, and the back end is saved into data structure, in the data structure record with it is described
The corresponding each back end of resource.
It, can be accordingly for the first application of each application resource when server detects that the first applicant applies for resource
Person creates back end, applies for the identity of the first applicant of the resource to utilize created back end to record, the
The identity of the first applicant of unique identification is capable of in the identity of one applicant, is specifically as follows the ID of the first applicant.
It should be understood that the quantity for the back end that server is created, the number of the first applicant depending on applying for the resource
Amount, i.e. server can be respectively that each the first applicant for applying for the resource creates a corresponding back end.
In turn, record there is the back end of the identity of the first applicant save data structure corresponding to the resource
In, record has each back end corresponding with the resource, i.e. each back end in the data structure in the data structure
Record has the identity for each first applicant for accessing the resource.It should be understood that data section recorded in the data structure
The quantity of point actually characterizes the quantity for accessing the applicant of the resource, i.e., the number of back end is to be somebody's turn to do in the data structure
The corresponding reference count of resource.
It should be noted that above-mentioned first applicant can specifically show as process or thread;Wherein, process refers to equipment
In program about the primary operation activity on certain data acquisition system, be the basic unit that system carries out Resource Distribution and Schedule, be
The basis of operating system configuration;Thread can also be referred to as lightweight process (Lightweight Process, LWP), be than into
The smaller independently operated basic unit of journey, belongs to the schedulable entity in process.
When the first applicant apply resource when, server can obtain the corresponding lock of the resource, by back end save to
When data structure, the corresponding lock of release resource allows the first applicant to hold the resource.
That is, server can correspondingly carry out the corresponding data structure of the resource when the first applicant applies for resource
Lock operation, to prevent during adding back end into data structure, by other applicants application or returned resource
Influence, lead to the back end entanglement recorded in data structure;To be used to recording the identity of first applicant
After back end is saved into data structure, the corresponding lock of the resource is discharged, first applicant is allowed to hold resource;Release money
After the corresponding lock in source, back end can be added or deleted in the data structure.
It should be noted that above-mentioned data structure can use singly linked list;It correspondingly, include data in back end
Field and pointer field, wherein data field is used to record the identity of applicant, and pointer field is for recording a number
According to node address.
As shown in figure 3, Fig. 3 is a kind of form of expression of singly linked list;Including back end A, back end B and
Back end C includes data field and pointer field in each back end;Data field record in back end A
There is the identity of the first applicant a, pointer field records the storage address for having back end B;Data word in back end B
Segment record has the identity of the first applicant b, and pointer field records the storage address for having back end C;In back end C
Data field records the identity for having the first applicant c, if not yet there are other first applicants after the first applicant c
The resource is accessed, then the pointer field in back end C is sky.
In one possible implementation, when the corresponding data structure of resource is singly linked list, if server is examined
It measures the first applicant and applies for the resource, at this point, server creates back end, set the data field of the back end to
The identity of first applicant sets empty for the pointer field of the back end;It in turn, will be last in the data structure
The pointer field of one back end is set as the pointer of the back end.
Specifically, when the corresponding data structure of used resource is singly linked list, if server detects first
Applicant applies for the resource, then creates back end accordingly for first applicant, and by the data word of the back end
Section is set as the identity of the first applicant, sets empty for the pointer field of the back end;In turn, corresponding for the resource
Singly linked list in pointer field in the last one back end, the address of the newly created back end of assignment will newly create
The back end built is as the last one back end in the corresponding singly linked list of resource.
In alternatively possible implementation, when the corresponding data structure of resource is singly linked list, if server
Detect that the first applicant applies for the resource, server creates back end, sets first for the data field of back end
The identity of applicant sets the pointer field of the back end to the address of current head node in the data structure;It will
The pointer field of current head node is set as the address of the back end in the data structure.
Specifically, when the corresponding data structure of used resource is singly linked list, if server detects first
Applicant applies for the resource, then creates back end accordingly for first applicant, and by the data word of the back end
Section is set as the identity of first applicant, sets the pointer field of the back end to work as front in the data structure
The head node of script in the data structure is replaced using the back end in address of node, as new in the data structure
Head node;At the same time, the pointer field of the head node of script in the data structure is set to the address of the back end;Such as
This, constantly using the head node of script in newly created back end replacement singly linked list, i.e., with the wound of back end
It builds, is continuously updated the head node of singly linked list.
It should be noted that intrusive chained list can also be used other than it can use the data structure of single-stranded sheet form,
The memory of back end in intrusive chained list can be incoming by outside, and such server internal does not need as back end application
Memory can save the memory of server.
In addition, in the case where the first applicant is fixed, it can also be using array or bitmap as data structure, it can be pre-
Fixed back end is first distributed for each first applicant, when first applicant accesses the resource, directly by this first
The identity of applicant is filled in into the back end in advance for first applicant distribution.
It is, of course, also possible to using other data structure records each back end corresponding with resource, herein not to being adopted
The form of data structure is specifically limited.
Step 202: when the second applicant calls the resource exception to terminate, checking in the data structure whether there is
The identity of second applicant, when in the data structure there are when the identity of second applicant, then from
The corresponding back end of second applicant is deleted in the data structure.
When the second applicant calls resource exception to terminate, server, which can be checked correspondingly in data structure, whether there is
For recording the back end of the identity of second applicant, and if it exists, then illustrate that second applicant is calling resource
Hold resource before abnormal end, at this point, correspondingly deleting the corresponding back end of the second applicant from data structure;Instead
It then illustrates that second applicant does not hold resource before calling resource exception to terminate, correspondingly without executing if it does not exist
Any operation.
It should be noted that applicant calls resource to be specifically divided into the application resource stage, hold the resource stage and give back money
Source stage, the second applicant call resource exception to terminate, and refer specifically in the application resource stage, hold resource stage and returned resource
In stage any one the anomaly of each phase terminate, that is, application resource the anomaly of each phase terminate, hold resource the anomaly of each phase terminate with
And terminated in returned resource the anomaly of each phase, it belongs to that resource exception is called to terminate.
It should be understood that the second applicant is similar with the first applicant, process or thread can also be specifically shown as.
It should be understood that the back end that record in data structure has the identity of the second applicant is deleted, the data structure
The quantity of middle back end can be reduced correspondingly, be equivalent to the corresponding reference count of the resource and correspondingly reduced;Data section points
Measure the quantity that reduced number depends on the second applicant for calling resource exception to terminate recorded in data structure, that is, if same
When there are multiple second applicants, and resource exception to be called to terminate, it is multiple that server can check in data structure whether there are still this
The identity of second applicant, if correspondingly deleting this there are the identity of multiple second applicants in data structure
Multiple corresponding back end of second applicant.
It should be noted that accessing resource in the second applicant when the corresponding data structure of resource is singly linked list
When abnormal end, server can be checked in the singly linked list with the presence or absence of the number for the identity for recording second applicant
According to node, if not finding, any operation is not executed;If the back end for finding, and being found is the single linked list knot
The head node of structure, then by the cephalomere point deletion, using the node adjacent with the head node as new head node, and this is single-stranded
The pointer modified of table structure is the address of new head node;If the back end for finding, and being found is not single linked list knot
The head node of structure is then deleted the back end found, by the pointer word in a upper back end for the back end
Section, is revised as the address of next back end of the back end.
It should be noted that server also can be obtained correspondingly when the first applicant for applying for resource normal returned resource
The corresponding lock of resource is taken, the corresponding back end of the first applicant, the corresponding lock of release resource are deleted from data structure.
That is, server can correspondingly carry out the corresponding data structure of the resource in first applicant's returned resource
Lock operation, to prevent from being applied for or give back money by other applicants during deleting back end from the data structure
The influence in source leads to the back end entanglement recorded in data structure;To be used to record the identity of first applicant
Back end from data structure delete after, discharge the corresponding lock of the resource;It, can be in the number after discharging the corresponding lock of resource
According to adding or deleting back end in structure.
Above-mentioned resource monitoring method understands the identity mark of correspondingly record access the applicant when applicant applies for resource
Know, thus guarantee in the case where applicant calls resource exception to terminate, it can be according to the identity of the applicant recorded
Accurately determine the reference count of the resource.Specifically, when the first applicant applies for resource, creation back end record this
The identity of one applicant saves the back end into the corresponding data structure of the resource;It is called in the second applicant
When the resource exception terminates, checks in the corresponding data structure of the resource and whether there is the identity of the second applicant, if
There are still the identity of the second applicant in data structure, then illustrate that second applicant holds before calling resource exception to terminate
There is the resource, at this point, correspondingly deleting the corresponding back end of the second applicant from data structure;In this way, in applicant's tune
, can be by judging whether there are still records applicant in the corresponding data structure of resource in the case where being terminated with resource exception
The back end of identity accurately updates the data structure for corresponding to the resource, to guarantee to be wrapped in the data structure
The data section points included are accurate reference count.
For above-described resource monitoring method, present invention also provides corresponding monitoring resource devices, so that above-mentioned
Monitoring resource signature method is able to apply and realize in practice.
Referring to fig. 4, Fig. 4 is a kind of knot of monitoring resource device 400 corresponding with resource monitoring method shown in figure 2 above
Structure schematic diagram, the monitoring resource device 400 include:
Logging modle 401, for when the first applicant applies for resource, creation back end to be remembered by the back end
The identity of first applicant is recorded, and the back end is saved into data structure, is remembered in the data structure
Record each back end corresponding with the resource;
Recovery module 402 is counted, for checking the data knot when the second applicant calls the resource exception to terminate
The identity that whether there is second applicant in structure, when there are the identity of second applicant in the data structure
When mark, then the corresponding back end of second applicant is deleted from the data structure.
Optionally, described device further include:
Apply for module, when first applicant applies for the resource, obtain the corresponding lock of the resource, will be described
When back end is saved to the data structure, the corresponding lock of the resource is discharged, allows first applicant to hold described
Resource.
Optionally, described device further include:
Module is given back, for obtaining the corresponding lock of the resource when first applicant gives back the resource, from institute
It states and deletes the corresponding back end of first applicant in data structure, discharge the corresponding lock of the resource.
Optionally, the data structure uses single linked list;The back end includes data field and pointer field, described
Data field is used to record the identity of applicant, and the pointer field is for recording a data node address.
Optionally, the logging modle 401 is specifically used for:
Back end is created, sets the data field of the back end to the identity of first applicant,
Set empty for the pointer field of the back end;
Set the pointer field of the last one back end in the data structure on the pointer of the back end.
Optionally, the logging modle 401 is specifically used for:
Back end is created, sets the data field of the back end to the identity of first applicant,
Set the pointer field of the back end to the address of current head node in the data structure;
Set the pointer field of head node current in the data structure to the address of the back end.
Optionally, the chained list is using intrusive chained list.
Optionally, the applicant is process or thread.
Above-mentioned monitoring resource device understands the identity mark of correspondingly record access the applicant when applicant applies for resource
Know, thus guarantee in the case where applicant calls resource exception to terminate, it can be according to the identity of the applicant recorded
Accurately determine the reference count of the resource.Specifically, when the first applicant applies for resource, creation back end record this
The identity of one applicant saves the back end into the corresponding data structure of the resource;It is called in the second applicant
When the resource exception terminates, checks in the corresponding data structure of the resource and whether there is the identity of the second applicant, if
There are still the identity of the second applicant in data structure, then illustrate second applicant before calling the resource exception to terminate
Hold the resource, at this point, correspondingly deleting the corresponding back end of the second applicant from data structure;In this way, in applicant
, can be by judging whether there are still records Shen in the corresponding data structure of resource in the case where calling the resource exception to terminate
Please person's identity back end, accurately update correspond to the resource data structure, to guarantee in the data structure
Included data section points are accurate reference count.
Present invention also provides a kind of equipment for monitoring resource, which is specifically as follows server, and Fig. 5 is this Shen
Please a kind of server architecture schematic diagram for providing of embodiment, the server 500 can because configuration or performance are different generate it is bigger
Difference, may include one or more central processing unit (central processing units, CPU) 522 (examples
Such as, one or more processors) and memory 532, one or more storage application programs 542 or data 544
Storage medium 530 (such as one or more mass memory units).Wherein, memory 532 and storage medium 530 can be
Of short duration storage or persistent storage.The program for being stored in storage medium 530 may include that one or more modules (do not mark by diagram
Out), each module may include to the series of instructions operation in server.Further, central processing unit 522 can be set
It is set to and is communicated with storage medium 530, the series of instructions operation in storage medium 530 is executed on server 500.
Server 500 can also include one or more power supplys 526, one or more wired or wireless networks
Interface 550, one or more input/output interfaces 558, and/or, one or more operating systems 541, such as
Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM etc..
The step as performed by server can be based on the server architecture shown in fig. 5 in above-described embodiment.
Wherein, CPU 522 is for executing following steps:
When the first applicant applies for resource, back end is created by the back end and records first applicant
Identity, and the back end is saved into data structure, is recorded in the data structure corresponding with the resource
Each back end;
When the second applicant calls the resource exception to terminate, check in the data structure with the presence or absence of described second
The identity of applicant, when in the data structure there are when the identity of second applicant, then from the data
The corresponding back end of second applicant is deleted in structure.
Optionally, the method step of any specific implementation of resource monitoring method shown in Fig. 2 can also be performed in CPU522
Suddenly.
The embodiment of the present application also provides another equipment for monitoring resource, which can be terminal device, such as
Shown in Fig. 6, for ease of description, part relevant to the embodiment of the present application is illustrated only, it is disclosed by specific technical details, it asks
Referring to the embodiment of the present application method part.The terminal can be include mobile phone, tablet computer, personal digital assistant (Personal
Digital Assistant, PDA) etc. any terminal device, taking the terminal as an example:
Fig. 6 shows the block diagram of the part-structure of mobile phone relevant to terminal provided by the embodiments of the present application.With reference to figure
6, mobile phone include: radio frequency (Radio Frequency, RF) circuit 610, memory 620, input unit 630, display unit 640,
Sensor 650, voicefrequency circuit 660, Wireless Fidelity (wireless fidelity, WiFi) module 1070, processor 680 and
The components such as power supply 690;It wherein, include input panel 631 and other input equipments 632, display unit 640 in input unit 630
In include display panel 641, include loudspeaker 661 and microphone 662 in voicefrequency circuit 660.
It will be understood by those skilled in the art that handset structure shown in Fig. 6 does not constitute the restriction to mobile phone, can wrap
It includes than illustrating more or fewer components, perhaps combines certain components or different component layouts.
In the embodiment of the present application, processor 680 included by the terminal is with the following functions:
When the first applicant applies for resource, back end is created by the back end and records first applicant
Identity, and the back end is saved into data structure, is recorded in the data structure corresponding with the resource
Each back end;
When the second applicant calls the resource exception to terminate, check in the data structure with the presence or absence of described second
The identity of applicant, when in the data structure there are when the identity of second applicant, then from the data
The corresponding back end of second applicant is deleted in structure.
Optionally, the method that any specific implementation of resource monitoring method shown in Fig. 2 can also be performed in processor 680
Step.
The embodiment of the present application also provides a kind of computer readable storage medium, for storing program code, the program code
For executing any one embodiment in a kind of resource monitoring method described in foregoing individual embodiments.
The embodiment of the present application also provides a kind of computer program product including instruction, when run on a computer,
So that computer executes any one embodiment in a kind of resource monitoring method described in foregoing individual embodiments.
It is apparent to those skilled in the art that for convenience and simplicity of description, the system of foregoing description,
The specific work process of device and unit, can refer to corresponding processes in the foregoing method embodiment, and details are not described herein.
In several embodiments provided herein, it should be understood that disclosed system, device and method can be with
It realizes by another way.For example, the apparatus embodiments described above are merely exemplary, for example, the unit
It divides, only a kind of logical function partition, there may be another division manner in actual implementation, such as multiple units or components
It can be combined or can be integrated into another system, or some features can be ignored or not executed.Another point, it is shown or
The mutual coupling, direct-coupling or communication connection discussed can be through some interfaces, the indirect coupling of device or unit
It closes or communicates to connect, can be electrical property, mechanical or other forms.
The unit as illustrated by the separation member may or may not be physically separated, aobvious as unit
The component shown may or may not be physical unit, it can and it is in one place, or may be distributed over multiple
In network unit.It can select some or all of unit therein according to the actual needs to realize the mesh of this embodiment scheme
's.
It, can also be in addition, each functional unit in each embodiment of the application can integrate in one processing unit
It is that each unit physically exists alone, can also be integrated in one unit with two or more units.Above-mentioned integrated list
Member both can take the form of hardware realization, can also realize in the form of software functional units.
If the integrated unit is realized in the form of SFU software functional unit and sells or use as independent product
When, it can store in a computer readable storage medium.Based on this understanding, the technical solution of the application is substantially
The all or part of the part that contributes to existing technology or the technical solution can be in the form of software products in other words
It embodies, which is stored in a storage medium, including some instructions are used so that a computer
Equipment (can be personal computer, server or the network equipment etc.) executes the complete of each embodiment the method for the application
Portion or part steps.And storage medium above-mentioned includes: USB flash disk, mobile hard disk, read-only memory (full name in English: Read-Only
Memory, english abbreviation: ROM), random access memory (full name in English: Random Access Memory, english abbreviation:
RAM), the various media that can store program code such as magnetic or disk.
The above, above embodiments are only to illustrate the technical solution of the application, rather than its limitations;Although referring to before
Embodiment is stated the application is described in detail, those skilled in the art should understand that: it still can be to preceding
Technical solution documented by each embodiment is stated to modify or equivalent replacement of some of the technical features;And these
It modifies or replaces, the spirit and scope of each embodiment technical solution of the application that it does not separate the essence of the corresponding technical solution.
Claims (10)
1. a kind of resource monitoring method characterized by comprising
When the first applicant applies for resource, creation back end records the body of first applicant by the back end
Part mark, and the back end is saved into data structure, it is recorded in the data structure corresponding with the resource each
A back end;
When the second applicant calls the resource exception to terminate, check in the data structure with the presence or absence of second application
The identity of person, when in the data structure there are when the identity of second applicant, then from the data structure
It is middle to delete the corresponding back end of second applicant.
2. resource monitoring method according to claim 1, which is characterized in that when first applicant applies for the resource
When, the corresponding lock of the resource being obtained, when saving the back end to the data structure, it is corresponding to discharge the resource
Lock, allow first applicant to hold the resource.
3. resource monitoring method according to claim 1, which is characterized in that when first applicant gives back the resource
When, the corresponding lock of the resource is obtained, the corresponding back end of first applicant is deleted from the data structure, is discharged
The corresponding lock of the resource.
4. resource monitoring method according to claim 1, which is characterized in that the data structure uses single linked list;It is described
Back end includes data field and pointer field, and the data field is used to record the identity of applicant, the pointer
Field is for recording a data node address.
5. resource monitoring method according to claim 4, which is characterized in that the creation back end passes through the data
The identity of first applicant described in nodes records, and the back end is saved into data structure, comprising:
Back end is created, the data field of the back end is set to the identity of first applicant, by institute
The pointer field for stating back end is set as empty;
Set the pointer field of the last one back end in the data structure on the pointer of the back end.
6. resource monitoring method according to claim 4, which is characterized in that the creation back end passes through the data
The identity of first applicant described in nodes records, and the back end is saved into data structure, comprising:
Back end is created, the data field of the back end is set to the identity of first applicant, by institute
The pointer field for stating back end is set as the address of current head node in the data structure;
Set the pointer field of head node current in the data structure to the address of the back end.
7. resource monitoring method according to claim 3, which is characterized in that the chained list is using intrusive chained list.
8. a kind of monitoring resource device characterized by comprising
Logging modle, for when the first applicant applies for resource, creation back end to pass through described in back end record
The identity of first applicant, and the back end is saved into data structure, record and institute in the data structure
State the corresponding each back end of resource;
Recovery module is counted, for when the second applicant calls the resource exception to terminate, checking in the data structure to be
No there are the identity of second applicant, when there are the identity of second applicant in the data structure
When, then the corresponding back end of second applicant is deleted from the data structure.
9. a kind of storage equipment characterized by comprising memory and processor;
The memory, for storing program code;
The processor executes said program code for reading the program code in the memory to realize claim 1
To resource monitoring method described in any one of 7.
10. a kind of computer readable storage medium, which is characterized in that the computer readable storage medium is for storing program generation
Code, said program code is for resource monitoring method described in any one of perform claim requirement 1 to 7.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910351017.4A CN110058948B (en) | 2019-04-28 | 2019-04-28 | Resource monitoring method, device, equipment and medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910351017.4A CN110058948B (en) | 2019-04-28 | 2019-04-28 | Resource monitoring method, device, equipment and medium |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN110058948A true CN110058948A (en) | 2019-07-26 |
| CN110058948B CN110058948B (en) | 2022-01-28 |
Family
ID=67321351
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201910351017.4A Active CN110058948B (en) | 2019-04-28 | 2019-04-28 | Resource monitoring method, device, equipment and medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN110058948B (en) |
Citations (10)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20020169986A1 (en) * | 2001-05-11 | 2002-11-14 | Lortz Victor B. | Resource authorization |
| CN103488526A (en) * | 2013-09-02 | 2014-01-01 | 用友软件股份有限公司 | System and method for locking business resource in distributed system |
| CN103678122A (en) * | 2013-11-29 | 2014-03-26 | 华为技术有限公司 | Deadlock detecting method, equipment and system |
| US20150188840A1 (en) * | 2013-12-31 | 2015-07-02 | Emc Corporation | Managing resource allocation in hierarchical quota system |
| US20160043938A1 (en) * | 2013-02-22 | 2016-02-11 | International Business Machines Corporation | Data processing lock signal transmission |
| CN105740079A (en) * | 2016-01-27 | 2016-07-06 | 浪潮(北京)电子信息产业有限公司 | Deadlock processing method and system |
| US20160321292A1 (en) * | 2010-05-05 | 2016-11-03 | Red Hat, Inc. | Distributed resource contention detection and handling |
| CN106204217A (en) * | 2016-07-08 | 2016-12-07 | 腾讯科技(深圳)有限公司 | The methods, devices and systems of resource numerical value transfer, the method and apparatus of resource numerical value transfer request |
| CN107231363A (en) * | 2017-06-12 | 2017-10-03 | 华南理工大学 | A kind of distributed authentication method and authentication model |
| CN107301091A (en) * | 2016-04-14 | 2017-10-27 | 北京京东尚科信息技术有限公司 | Resource allocation methods and device |
-
2019
- 2019-04-28 CN CN201910351017.4A patent/CN110058948B/en active Active
Patent Citations (10)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20020169986A1 (en) * | 2001-05-11 | 2002-11-14 | Lortz Victor B. | Resource authorization |
| US20160321292A1 (en) * | 2010-05-05 | 2016-11-03 | Red Hat, Inc. | Distributed resource contention detection and handling |
| US20160043938A1 (en) * | 2013-02-22 | 2016-02-11 | International Business Machines Corporation | Data processing lock signal transmission |
| CN103488526A (en) * | 2013-09-02 | 2014-01-01 | 用友软件股份有限公司 | System and method for locking business resource in distributed system |
| CN103678122A (en) * | 2013-11-29 | 2014-03-26 | 华为技术有限公司 | Deadlock detecting method, equipment and system |
| US20150188840A1 (en) * | 2013-12-31 | 2015-07-02 | Emc Corporation | Managing resource allocation in hierarchical quota system |
| CN105740079A (en) * | 2016-01-27 | 2016-07-06 | 浪潮(北京)电子信息产业有限公司 | Deadlock processing method and system |
| CN107301091A (en) * | 2016-04-14 | 2017-10-27 | 北京京东尚科信息技术有限公司 | Resource allocation methods and device |
| CN106204217A (en) * | 2016-07-08 | 2016-12-07 | 腾讯科技(深圳)有限公司 | The methods, devices and systems of resource numerical value transfer, the method and apparatus of resource numerical value transfer request |
| CN107231363A (en) * | 2017-06-12 | 2017-10-03 | 华南理工大学 | A kind of distributed authentication method and authentication model |
Non-Patent Citations (2)
| Title |
|---|
| BRYAN C. WARD等: "Multi-resource Real-Time Reader/Writer Locks for Multiprocessors", 《2014 IEEE 28TH INTERNATIONAL PARALLEL AND DISTRIBUTED PROCESSING SYMPOSIUM》 * |
| 郝娉婷等: "基于多管理节点的乐观锁协议", 《吉林大学学报(工学版)》 * |
Also Published As
| Publication number | Publication date |
|---|---|
| CN110058948B (en) | 2022-01-28 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN109344153B (en) | Service data processing method and terminal equipment | |
| CN109542428B (en) | Business processing method, device, computer equipment and storage medium | |
| CN113422794B (en) | Flow recording and playback processing method and device and electronic equipment | |
| CN109995677B (en) | Resource allocation method, device and storage medium | |
| CA3128540C (en) | Cache system hotspot data access method, apparatus, computer device and storage medium | |
| CN109586948A (en) | Update method, apparatus, computer equipment and the storage medium of system configuration data | |
| CN110738389A (en) | Workflow processing method and device, computer equipment and storage medium | |
| US20210092029A1 (en) | Service ticket escalation based on interaction patterns | |
| WO2021114829A1 (en) | Token bucket-based method, device, and system for interface throttling, and readable storage medium | |
| CN109634822A (en) | A kind of function time-consuming statistical method, device, storage medium and terminal device | |
| CN107590015A (en) | The method and apparatus for monitoring the obstruction of main thread | |
| CN113850603B (en) | Method and device for determining cause of payment failure | |
| US11947415B2 (en) | System and method for efficient real time log export and view in a micro services system | |
| CN111400142A (en) | Method and device for monitoring abnormity of virtual machine and storage medium | |
| CN110018986B (en) | Abnormal snapshot identification method and device | |
| CN110058948A (en) | A kind of resource monitoring method, device, equipment and medium | |
| CN118132313A (en) | Fault processing method and device for micro-service application, electronic equipment and storage medium | |
| CN113297232A (en) | Data updating method, device and system based on database partition | |
| CN115026825B (en) | Method and device for realizing robot operation status of IA based on RPA and AI | |
| CN117950962A (en) | Abnormal call identification method, device, electronic equipment and medium | |
| CN115269360A (en) | Application memory testing method and device and readable storage medium | |
| CN110059072A (en) | Data Migration monitoring method, system, equipment and medium based on storing process | |
| CN117170995B (en) | Performance index-based interference anomaly detection method, device, equipment and medium | |
| CN119179582B (en) | Load abnormality processing method, electronic device, storage medium and program product | |
| CN112035174B (en) | Method, apparatus and computer storage medium for running web service |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |