CN107301091A - Resource allocation methods and device - Google Patents

Resource allocation methods and device Download PDF

Info

Publication number
CN107301091A
CN107301091A CN201610232468.2A CN201610232468A CN107301091A CN 107301091 A CN107301091 A CN 107301091A CN 201610232468 A CN201610232468 A CN 201610232468A CN 107301091 A CN107301091 A CN 107301091A
Authority
CN
China
Prior art keywords
resource
user
resource allocation
request
lock
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.)
Pending
Application number
CN201610232468.2A
Other languages
Chinese (zh)
Inventor
廖耀华
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201610232468.2A priority Critical patent/CN107301091A/en
Publication of CN107301091A publication Critical patent/CN107301091A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request

Abstract

This application discloses resource allocation methods and device.One embodiment of methods described includes:The resource allocation request of user is obtained, locking operation is carried out to resource allocation request, determines whether user has the authority for obtaining resource according to the result for locking operation, if so, being added to resource allocation request as waiting task in buffer queue.The embodiment realizes reliable, efficient resource allocation, improves the success rate of resource allocation.

Description

Resource allocation methods and device
Technical field
The application is related to technical field of information processing, and in particular to electric digital data processing field, More particularly to resource allocation methods and device.
Background technology
In technical field of information processing, resource can be available information or space, can wrap Include storage resource, computing resource, Internet resources etc..Typically for the resource acquisition received Request, electronic equipment can be according to the history resource acquisition for the object for sending request record to its body Part is verified, and determines whether, with available resource, to pass through and have in verification Resource acquisition request is added to queue to be allocated during available resource, passes through asynchronous side afterwards Formula carries out resource allocation.
In the case where resource acquisition number of requests is larger, using it is above-mentioned it is asynchronous by the way of provided When source is distributed, there may be error, request pair for the available stock number that electronic equipment is calculated The resource acquisition record of elephant can not real-time update, then please in the resource acquisition that sends of request object Ask when asking resource again in the case of being added into queue to be allocated, electronic equipment can not be accurate Really judge whether the request object can be by verification.Therefore, because the money that electronic equipment is obtained The state and available volume of resources data and real data of the request object of source distribution are inconsistent, in money When the data volume of source distribution request is larger, in fact it could happen that the problem of duplicate allocation resource and resource Distribution request is added into the problem of available resources are not enough after queue to be allocated, so as to have impact on resource The success rate of distribution.
The content of the invention
In view of this, it is desired to be able to which a kind of reliable resource allocation methods are provided.Further, It is also expected to a kind of efficient resource allocation methods can be provided.In order to solve said one or multiple Problem, this application provides the method and apparatus of resource allocation.
On the one hand, this application provides a kind of resource allocation methods, methods described includes:Obtain The resource allocation request of user;Locking operation is carried out to the resource allocation request;According to described The result for locking operation determines whether the user has the authority for obtaining resource;If so, by institute Resource allocation request is stated to be added in buffer queue as waiting task.
In certain embodiments, it is described to resource allocation request progress locking operation, including: Request is obtained based on resource allocation request generation lock;Request is obtained in response to generating the lock, Judge whether distributed lock can use;If the distributed lock can use, generation obtains successful message And be set to the state of the distributed lock unavailable;And it is described according to the locking operation Result determine the user whether have obtain resource authority, including:In response to generation institute The successful message of acquisition is stated, determines that the user has the authority for obtaining resource.
In certain embodiments, methods described also includes:It is the buffer queue using thread pool In waiting task distribution resource.
In certain embodiments, it is added to using the resource allocation request as waiting task After in buffer queue, methods described also includes:The state of the distributed lock is switched to can With.
In certain embodiments, methods described also includes:Detect the unavailable of the distributed lock State duration;If the down state of the distributed lock is sustained for longer than presetting Threshold value, the state of the distributed lock is switched to available.
In certain embodiments, the identification information of the resource allocation request including the user and The resource acquisition historical record of the user;Methods described also includes:Obtained if the user has The authority of resource is taken, the resource acquisition historical record of the user is updated.
Second aspect, this application provides a kind of resource allocation device, described device includes:Obtain Unit is taken, the resource allocation request for obtaining user;Unit is locked, for the resource Distribution request carries out locking operation;Determining unit, for true according to the result for locking operation Whether the fixed user has the authority for obtaining resource;Adding device, in user tool When having the authority for obtaining resource, the resource allocation request is added to as waiting task slow Deposit in queue.
In certain embodiments, the locking unit includes:First generation module, for based on The resource allocation request generation lock obtains request;Judge module, for described in response to generation Lock obtains request, judges whether distributed lock can use;Second generation module, in response to institute State distributed lock can use, generation obtains successful message and sets the state of the distributed lock To be unavailable;The determining unit is further used in response to generating the successful message of acquisition, Determine that the user has the authority for obtaining resource.
In certain embodiments, described device also includes:Allocation unit, for utilizing thread pool Resource is distributed for the waiting task in the buffer queue.
In certain embodiments, described device also includes:Unlocking unit, in the addition , will after the resource allocation request is added in buffer queue by unit as waiting task The state of the distributed lock switches to available.
In certain embodiments, described device also includes processing unit, is used for:Described point of detection The down state duration of cloth lock;If the down state of the distributed lock continues Time be more than predetermined threshold value, the state of the distributed lock is switched to available.
In certain embodiments, the identification information of the resource allocation request including the user and The resource acquisition historical record of the user;Described device also includes:Updating block, for When the user has the authority for obtaining resource, the resource acquisition historical record of the user is entered Row updates.
Resource allocation methods and device that the application is provided, pass through the resource allocation request to user Locking operation is carried out, and determines whether user has according to the result for locking operation obtaining resource Authority, caching is added to when it is determined that user has the authority for obtaining resource by resource allocation request In queue, it is achieved thereby that reliably, efficient resource allocation, improve the success of resource allocation Rate.
Brief description of the drawings
Non-limiting example is described in detail with reference to what the following drawings was made by reading, this Shen Other features, objects and advantages please will become more apparent upon:
Fig. 1 is that the application can apply to exemplary system architecture figure therein;
Fig. 2 is the flow chart of one embodiment of the resource allocation methods according to the application;
Fig. 3 is the flow chart of another embodiment of the resource allocation methods according to the application;
Fig. 4 is the principle signal of an application scenarios of the resource allocation methods according to the application Figure;
Fig. 5 is the structural representation of one embodiment of the application resource allocation device;
Fig. 6 is adapted for for realizing the terminal device of the embodiment of the present application or the computer of server The structural representation of system.
Embodiment
The application is described in further detail with reference to the accompanying drawings and examples.It is appreciated that , specific embodiment described herein is used only for explaining related invention, rather than to the hair Bright restriction.It also should be noted that, illustrate only for the ease of description, in accompanying drawing with About the related part of invention.
It should be noted that in the case where not conflicting, embodiment and embodiment in the application In feature can be mutually combined.Describe this in detail below with reference to the accompanying drawings and in conjunction with the embodiments Application.
As shown in figure 1, system architecture 100 can include terminal device 101,102,103, Network 104 and server 105.Network 104 is used in the and of terminal device 101,102,103 The medium of communication link is provided between server 105.Network 104 can include various connection classes Type, such as wired, wireless communication link or fiber optic cables etc..
User 110 can pass through network 104 and service with using terminal equipment 101,102,103 Device 105 is interacted, to receive or send message etc..Can be with terminal device 101,102,103 Various applications are installed.
Terminal device 101,102,103 can be the various electronic equipments for supporting user's operation, Including but not limited to smart mobile phone, intelligent watch, tablet personal computer, E-book reader, MP3 Player (Moving Picture Experts Group Audio Layer III, dynamic image expert pressure Contracting standard audio aspect 3), MP4 (Moving Picture Experts Group Audio Layer IV, dynamic image expert's compression standard audio aspect 4) player, pocket computer on knee, Desktop computer etc..
Server 105 can be to provide the server of various services, for example, pass through terminal to user The background server that the instruction that equipment 101,102,103 is sent is responded.Background server The operational order received can be searched, the processing such as data analysis, and by result Feed back to terminal device.In some concrete implementations, server 105 can be server set Group.
It should be noted that the resource allocation methods that the embodiment of the present application is provided can be by terminal Equipment 101,102,103 is performed, and can also be performed by server 105, correspondingly, resource Distributor can be arranged in terminal device 101,102,103, can also be arranged at service In device 105.
It should be understood that the number of the terminal device, network and server in Fig. 1 is only signal Property.According to needs are realized, can have any number of terminal device, network and server.
With continued reference to Fig. 2, one embodiment of the resource allocation methods according to the application is shown Flow 200.As shown in Fig. 2 described resource allocation methods flow 200, including following step Suddenly:
Step 201, the resource allocation request of user is obtained.
In the present embodiment, electronic equipment (such as Fig. 1 of resource allocation methods operation thereon Shown terminal device 101,102,103 or server 105) it can receive what user sent Resource allocation request.User's requested resource can be computing resource, storage resource, data The available information resources such as resource.Specifically, can be internal memory, the network number of computer The resource of effective information is included according to, virtual objects etc..The resource of user's request can be above-mentioned electricity The intrinsic information data of sub- equipment, such as amount of ram can also be pre-stored in above-mentioned electronic equipment, Such as data in internal memory, can also be by above-mentioned electronic equipment by Network Capture, such as virtually Picture, word in article, network data etc..
For example, resource allocation request can be the computational resource allocation in data analysis process Request or the resources of virtual machine request for handling order, can also be and get website The request of the virtual objects of middle configuration.
When user needs to obtain the resource in above-mentioned electronic equipment, if above-mentioned electronics has been matched somebody with somebody User interface is put, then user can send resource point by the user interface of above-mentioned electronic equipment With request;If above-mentioned electronics does not configure user interface, user can be to other configured use Family interface and the electronic equipment for establishing network connection with above-mentioned electronic equipment send resource allocation please Ask, above-mentioned electronic equipment can receive and parse through the resource allocation request of user.
In some optional implementations, user interface can be input interface or select interface, When user inputs a resource acquisition keyword or clicks on a resource acquisition option, above-mentioned electricity Sub- equipment can generate resource allocation in response to detecting input operation or the clicking operation of user Request.
In the present embodiment, resource allocation request can include the identification information of resource to be obtained. Above-mentioned electronic equipment can find out corresponding resource according to the identification information of resource to be obtained.
In some implementations, resource allocation request can include identification information and the user of user Resource acquisition historical record.The identification information of user can be the PIN code (Personal of user Identification Number, personal recognition code), the numbering of user, resource acquisition history note Record can include the historical information that user obtains resource, stock number and money that such as user has obtained Source Type, acquisition time etc..
Step 202, locking operation is carried out to resource allocation request.
Above-mentioned electronic equipment can provide resource service for multiple users.When simultaneously multiple users send out When going out resource allocation request, each resource allocation can be coordinated by the distributed lock being pre-configured with The processing of request.
In the present embodiment, above-mentioned electronic equipment can be pre-configured with distributed lock resource, connect When receiving the resource allocation request of user, locking operation can be carried out to resource allocation request, its In, it can be the operation that distributed lock is distributed for resource allocation request to lock operation.
In some optional implementations, locking operation can be carried out as follows:Base Request is obtained in resource allocation request generation lock, and request is obtained in response to generating lock, judges to divide Whether cloth lock can use, when distributed lock is available, and generation obtains successful message and will distribution The state of formula lock is set to unavailable.Specifically, can be with when getting resource allocation request Obtain request according to resource allocation request generation lock or send lock and obtain instruction.Alternatively, lock is obtained The identification information of user can be included by taking in request.If the state of distributed lock is available, can The successful message of acquisition is returned to obtain request to lock, and the state of distributed lock is changed to not It can use.That is, when user A sends resource allocation request, lock acquisition can be sent and referred to Order, above-mentioned electronic equipment will can be distributed when it is determined that distributed lock is not obtained by other users Formula lock, which is distributed to user A, user A, successfully to be obtained after distributed lock, the state of distributed lock To be unavailable, before distributed lock is released, other users can not get the distributed lock.
In concrete implementation, it is possible to use the SENTX instructions in Redis databases, which are realized, to be added Lock operation.SENTX is a kind of atomic operation in Redis databases, and if only if key (key) In the absence of when, set key value, and return 1;If given key has been present, return Return 0.When lock operation to resource allocation request, it can generate comprising corresponding user The SENTX instructions of mark, if return value is 1, it is determined that lock is successfully got, if returned It is 0 to return value, it is determined that do not get lock, and locking operation can be retried with cycle regular hour.
In other optional implementations, locking operation can be carried out as follows: Judge whether current resource allocation request quantity exceedes the quantity of currently available lock, if not Exceed, it may be determined that the result of the locking operation of resource allocation request is successfully and to available lock Quantity carry out the operation that subtracts one, otherwise determine the result of locking operation of resource allocation request to lose Lose.
Step 203, determine whether user has the power for obtaining resource according to the result for locking operation Limit.
If the result for locking operation is successfully to get lock, it can determine that user has acquisition The authority of resource;Otherwise it can determine that user does not obtain the authority of resource.Further, exist Determine that distributed lock is available or current resource allocation request quantity is not less than current in step 202 After the quantity of available lock, above-mentioned electronic equipment can obtain successful message in response to generation, Determine that user has the authority for obtaining resource.
In some optional implementations, if locking the result of operation not get lock, It can then determine that user does not obtain the authority of resource.Alternatively, when it is determined that user does not obtain During the authority of resource, above-mentioned locking operation can be repeated after some time.
In certain embodiments, if including the identification information and money of user in resource allocation request Source obtains historical record, can also be further according to the identification information of user and resource acquisition history Record determines whether user has the authority for obtaining resource.For example can be from the resource acquisition of user Determine whether user has obtained the resource and user obtains the time of the resource in historical record, So that it is determined that having obtained the user of the resource has the authority for obtaining resource.Or money can be calculated Source surplus, when resource excess is not up to Margin threshold set in advance, determines that user has and obtains The authority of resource is taken, otherwise determines user without the authority for obtaining resource.
Step 204, if user has the authority for obtaining resource, using resource allocation request as treating Processing task is added in buffer queue.
In the present embodiment, the resource point that the user with the authority for obtaining resource can be sent It is added to request in buffer queue, forms waiting task.Above-mentioned electronic equipment can be slow Deposit the resource allocation request distribution resource in queue.
In the present embodiment, can create can be comprising multiple cachings point in cache pool, cache pool Piece.Multiple caching bursts can be numbered, form buffer queue.Specifically, can be with The resource allocation request of user with the authority for obtaining resource is added in caching burst.Enter one Step ground, can obtain the user identity information in resource allocation request, will be used using hash algorithm Family identification information is mapped as binary value, and modulus computing is carried out afterwards, you can obtain caching burst Numbering.
In a further embodiment, the resource allocation request of user can be obtained including user resources Take historical record, if it is determined that user has the authority for obtaining resource, then asked by resource allocation Ask after being added to as waiting task in buffer queue, the resource acquisition of user can be gone through Records of the Historian record is updated.For example can be by the resource acquisition historic state of user by " not obtaining " " acquisition " is changed to, further, can also add and obtain in history resource acquisition record The time of resource, or the history resource acquisition number of times of user is added one, the history of user is provided Source obtains total amount and carries out adding computing etc..
In certain embodiments, resource allocation request is added to after buffer queue, can be by The state of distributed lock switches to available.I.e. it is determined that user have obtain resource authority after, The lock got can be discharged.At this moment, the lock of other users obtains request and can responded.
In a further embodiment, the flow 200 of resource allocation methods can also include:Inspection Survey the down state duration of distributed lock;If the down state of distributed lock continues Time be more than predetermined threshold value, the state of distributed lock is switched to available.Specifically, may be used To set the life span of distributed lock, when lock operation to resource allocation request, Current time stamp as deposit obtain distributed lock in, by be stored in distributed lock timestamp and Timestamp in Redis is contrasted, if it exceeds life span set in advance, can discharge Distributed lock, available, to prevent acquisition from locking visitor is switched to by the state of distributed lock from unavailable Family end end performs overlong time, or because other collapse extremely and lead to not release profile formula Lock.Wherein, the life span of distributed lock can have been handled according to the resource allocation request of user Into time and electronic equipment current calculating speed set, can for example be set to be slightly larger than The average time that the resource allocation request processing of user is completed.
For above-described embodiment of the application, the scene of application can be, in multiple users simultaneously When " getting gift bag " button for clicking on e-commerce website sends virtually " gift bag " acquisition request, Website background server can obtain request to virtual " gift bag " of each user and carry out locking operation, Locked successfully if user B is obtained, can determine whether whether user B got the virtual " gift Whether bag " and currently available " gift bag " quantity can meet demand, if user B is not led Took virtual " gift bag " and currently available " gift bag " quantity can meet demand, it is determined that User B has the authority for getting virtual " gift bag ", and at this moment, user B can be numbered, And its virtual " gift bag " is obtained into the cache slice that request is added to reference numeral in cache pool.Enter One step, user B gift bag can also be got to status modifier for " having got ".Cross herein Cheng Zhong, because same time only one of which resource allocation request can successfully obtain lock, so as to protect Demonstrate,prove the state and current available resource amount number of the request object for the resource allocation that electronic equipment is obtained According to consistent with real data, it is to avoid resource allocation request data volume duplicates distribution when larger The problem of resource and resource allocation request are added into that available resources after queue to be allocated are not enough to ask Topic.
The method that above-described embodiment of the application is provided, is entered by the resource allocation request to user Row locks operation, and determines whether user has the power for obtaining resource according to the result for locking operation Limit, caching team is added to when it is determined that user has the authority for obtaining resource by resource allocation request In row, so as to ensure that data that electronic equipment in resource allocation process obtains and real data Uniformity, improves the success rate of resource allocation.
With further reference to Fig. 3, it illustrates another of the resource allocation methods according to the application The flow 300 of embodiment.The flow 300 of the resource allocation methods, comprises the following steps:
Step 301, the resource allocation request of user is obtained.
In the present embodiment, electronic equipment (such as Fig. 1 of resource allocation methods operation thereon Shown terminal device 101,102,103 or server 105) it can receive what user sent Resource allocation request.User's requested resource can be computing resource, storage resource, data The available information resources such as resource.The resource of user's request can be that above-mentioned electronic equipment is intrinsic Information data, such as amount of ram can also be pre-stored in above-mentioned electronic equipment, for example internal memory In data, Network Capture, such as virtual objects, net can also be passed through by above-mentioned electronic equipment Picture, word in network data etc..
User can send resource allocation request by the user interface of above-mentioned electronic equipment, The electronics of network connection can be established to other configured user interfaces and with above-mentioned electronic equipment Equipment sends resource allocation request, and above-mentioned electronic equipment can receive and parse through the resource point of user With request.
In the present embodiment, resource allocation request can include the identification information of resource to be obtained. Above-mentioned electronic equipment can find out corresponding resource according to the identification information of resource to be obtained.Can Selection of land, resource allocation request can include the identification information of user and the resource acquisition of user is gone through The Records of the Historian is recorded.
Step 302, locking operation is carried out to resource allocation request.
Above-mentioned electronic equipment can provide resource service for multiple users.When simultaneously multiple users send out When going out resource allocation request, each resource allocation can be coordinated by the distributed lock being pre-configured with The processing of request.
In the present embodiment, above-mentioned electronic equipment can be pre-configured with distributed lock resource, connect When receiving the resource allocation request of user, locking operation can be carried out to resource allocation request, its In, it can be the operation that distributed lock is distributed for resource allocation request to lock operation.
In the present embodiment, locking operation can be carried out to resource allocation request using a variety of methods. A kind of optional locking operation includes:Request is obtained based on resource allocation request generation lock, and rung Request should be obtained in generation lock, judge whether distributed lock can use, when distributed lock is available, Generation obtains successful message and is set to the state of distributed lock unavailable.Specifically, exist Can be that the user's generation lock for sending resource allocation request is obtained when getting resource allocation request Request.Alternatively, lock, which is obtained in request, can include the identification information of user.If distributed Lock is not obtained by other users or other resource allocation requests, then the state of distributed lock be it is available, At this moment request can be obtained to lock and returns to the successful message of acquisition, and by the state of distributed lock more It is changed to unavailable.
If the multiple distributed locks of above-mentioned electronic equipment, can hold in the following way Row locks operation:Judge whether current resource allocation request quantity exceedes currently available lock Quantity, if not less than the result for determining the locking operation of resource allocation request is successfully and right Operation that the quantity progress of available lock subtracts one, otherwise determines the locking operation of resource allocation request As a result it is failure.
Step 303, determine whether user has the power for obtaining resource according to the result for locking operation Limit.
If the result for locking operation is successfully to get lock, it can determine that user has acquisition The authority of resource;Otherwise it can determine that user does not obtain the authority of resource.Further, such as Determine that distributed lock is available in fruit step 302 or current resource allocation request quantity is not less than working as The quantity of preceding available lock, above-mentioned electronic equipment can obtain successful message in response to generation, Determine that user has the authority for obtaining resource.
In some optional implementations, if locking the result of operation not get lock, Above-mentioned locking operation can be repeated after some time.
In certain embodiments, if including the identification information and money of user in resource allocation request Source obtains historical record, can also be further according to the identification information of user and resource acquisition history Record determines whether user has the authority for obtaining resource.For example can be from the resource acquisition of user Determine whether user has obtained the resource and user obtains the time of the resource in historical record, So that it is determined that having obtained the user of the resource has the authority for obtaining resource.Or money can be calculated Source surplus, when resource excess is not up to Margin threshold set in advance, determines that user has and obtains The authority of resource is taken, otherwise determines user without the authority for obtaining resource.
Step 304, if user has the authority for obtaining resource, using resource allocation request as treating Processing task is added in buffer queue.
In the present embodiment, the resource point that the user with the authority for obtaining resource can be sent It is added to request in buffer queue, forms waiting task.Above-mentioned electronic equipment can be slow Deposit the resource allocation request distribution resource in queue.
In the present embodiment, can create can be comprising multiple cachings point in cache pool, cache pool Piece.Multiple caching bursts can be numbered, form buffer queue.Specifically, can be with The resource allocation request of user with the authority for obtaining resource is added in caching burst.
If the resource allocation request of user includes the resource acquisition historical record of user, it will provide , can be to the money of user after source distribution request is added in buffer queue as waiting task Source obtains historical record and is updated, for example, can be set to the resource acquisition state of user " Obtain ".Further, in configuration state, user identity information can be reflected using hash algorithm Penetrate as binary value, modulus computing is carried out afterwards, after the numbering for drawing caching burst, find Corresponding user carries out state change to it.
In certain embodiments, resource allocation request is added to after buffer queue, can be by The state of distributed lock switches to available.I.e. it is determined that user have obtain resource authority after, The lock got can be discharged.At this moment, the lock of other users obtains request and can responded.
In a further embodiment, the flow 300 of resource allocation methods can also include:Inspection Survey the down state duration of distributed lock;If the down state of distributed lock continues Time be more than predetermined threshold value, the state of distributed lock is switched to available.So, it can keep away Exempt to obtain the client executing overlong time of lock or because other can not caused by collapsing extremely The problem of release profile formula is locked.
In the present embodiment, in above-mentioned implementation process step 301, step 302, step 303, With step 304 respectively with the step 201 in previous embodiment, step 202, step 203 and Step 204 is identical, will not be repeated here.
Step 305, resource is distributed using thread pool for the waiting task in buffer queue.
In the present embodiment, above-mentioned electronic equipment can create thread pool, in thread pool in advance A number of thread is created, in the waiting task during thread pool receives buffer queue, One or more threads can be distributed to be handled.When the thread being pre-created is all in operation shape State, that is, the number of threads being pre-created is not enough, and thread pool can create a number of new thread, For handling more tasks.After tasks carrying is finished, the thread in thread pool can be used for Perform other tasks.
In the present embodiment, can be each waiting task distribution thread in buffer queue Multiple threads in pond carry out asynchronous process.Multiple threads are from the correspondence caching burst in cache pool Data are obtained, and data are handled, including distribution resource, database manipulation etc..Wherein, Database manipulation includes preserving the record that user obtains resource to database and obtaining user Resource removed from database etc..
From figure 3, it can be seen that unlike embodiment corresponding from Fig. 1, in the present embodiment Resource allocation methods flow 300 had more using thread pool be buffer queue in it is pending Task distributes the step 305 of resource.Pass through the step 305 of increase, the scheme of the present embodiment statement Help to lift resource allocation speed.
Below with reference to Fig. 4, it illustrates the resource allocation methods according to the application a application The principle schematic of scene.As shown in figure 4, user 1, user 2, user 3 ..., user M (m is positive integer) is simultaneously emitted by resource allocation request, at this moment, and receiving resource allocation please The electronic equipment asked can obtain request for each user generation lock, to distributed lock resource request Lock, can change the state for the user for getting lock afterwards, and will release lock, while can be by Get the cache slice that the resource allocation request of the user of lock is added in cache pool.At this moment, may be used To carry out the numbering that Hash and modulus are worth to cache slice according to the identification information of user, for example with Family 1 is got after lock, the PIN code of user can be carried out into Hash operation and modulus is worth to 3, The resource allocation request of user 1 is then added to caching burst 3.Rear end can utilize thread pool Asynchronous process is carried out to caching burst, is that the multiple threads of each caching burst distribution are allocated money The processing such as source, data syn-chronization, such as Fig. 4 threads 1, thread 2 ..., thread p postpones Deposit in burst 1 and obtain data, wherein, thread 1, thread 2 are used to perform resource allocation operations, Thread p is used to perform data syn-chronization operation.So, using multiple threads, process resource is divided simultaneously With request, the treatment effeciency of resource allocation can be lifted while data consistency is ensured.
With further reference to Fig. 5, as the realization to method shown in above-mentioned each figure, the application is provided A kind of one embodiment of resource allocation device, the device embodiment and the method shown in Fig. 2 Embodiment is corresponding, and the device specifically can apply in various electronic equipments.
As shown in figure 5, resource allocation device 500 can include acquiring unit 501, lock list Member 502, determining unit 503 and adding device 504.Wherein, acquiring unit 501 is used to obtain Take the resource allocation request at family;Locking unit 502 is used to lock resource allocation request Operation;Determining unit 503 is used to determine whether user has acquisition according to the result for locking operation The authority of resource;Adding device 504 is used to, when user has the authority for obtaining resource, to provide Source distribution request is added in buffer queue as waiting task.
In the present embodiment, acquiring unit 501 can receive what user was sent by input interface Resource allocation request receives resource allocation request of other electronic equipments by network transmission. Resource allocation request can be that the computing resource in data analysis process is asked or is used for The resources of virtual machine request of order is handled, can also be and get the virtual objects that are configured in website Request.Resource allocation request can include the identification information of resource to be obtained, the mark letter of user Breath and the resource acquisition historical record of user.
Locking unit 502 can coordinate what multiple users sent by the distributed lock being pre-configured with The processing of resource allocation request.In concrete implementation, it can be for resource allocation to lock operation The operation of request distribution distributed lock.If the state of current distributed lock is available, the money Source distribution request, which is obtained, locks successfully.
Determining unit 503 can determine user locking when the result operated is successfully to get lock With the authority for obtaining resource, determine that user does not obtain the authority of resource when not getting lock. Alternatively, when determining unit 503 determines that user does not obtain the authority of resource, unit is locked 502 can repeat above-mentioned locking operation after some time.
In some optional embodiments, locking unit 502 can include:First generation module, Judge module and the second generation module.Wherein, the first generation module is used to be based on acquiring unit 501 The resource allocation request generation lock of acquisition obtains request, and judge module is used in response to the first generation The lock of module generation obtains request, judges whether distributed lock can use, the second generation module is used for Available in response to distributed lock, generation obtains successful message and sets the state of distributed lock To be unavailable.At this moment, determining unit 503 is further used for generating in response to the second generation module Successful message is obtained, determines that user has the authority for obtaining resource.
The resource allocation that adding device 504 can send the user with the authority for obtaining resource Request is added in buffer queue, forms waiting task.Adding device 504 can create slow Multiple caching bursts can be included by depositing in pond, cache pool.Adding device 504 can be to multiple slow Deposit burst to be numbered, form buffer queue.Specifically, resource allocation request can be obtained In user identity information, user identity information is mapped as by binary value using hash algorithm, Modulus computing is carried out afterwards, and obtaining please by the resource allocation of correspondence user after the numbering of caching burst Ask added in caching burst.
In a further embodiment, the resource allocation request that acquiring unit 501 is obtained includes using The identification information at family and the resource acquisition historical record of user.Device 500 can also include updating Unit, for when determining unit 503 determines that user has the authority for obtaining resource, to user Resource acquisition historical record be updated.
In certain embodiments, device 500 also includes allocation unit, for being using thread pool Waiting task distribution resource in buffer queue.Allocation unit can create thread pool, online Cheng Chizhong is pre-created a number of thread, and treating in thread pool receives buffer queue is located During reason task, one or more threads can be distributed and handled.Allocation unit can be caching Multiple threads in each waiting task distribution thread pool in queue carry out asynchronous process. Multiple threads are handled data from the correspondence caching burst Hu crowd fighting data in cache pool, Including distribution resource, database manipulation etc..
In certain embodiments, device 500 also includes unlocking unit, in adding device 504 After resource allocation request is added in buffer queue as waiting task, by distributed lock State switch to it is available.That is, getting the resource allocation request quilt of the user of lock Added to after buffer queue, unlocking unit can discharge the lock of user acquisition, so that other are used The lock at family obtains request and can responded.
Further, device 500 can also include processing unit, for detecting distributed lock Down state duration, and if distributed lock down state duration it is big In predetermined threshold value, the state of distributed lock is switched to available.Processing unit can be when default Between after release lock, it is to avoid due to obtain lock client end perform overlong time, or because Other collapse and lead to not release profile formula lock extremely.
It should be appreciated that all units described in device 500 and the side referring to figs. 2 and 3 description Each step in method is corresponding.Thus, above with respect to resource allocation methods describe operation and Feature is equally applicable to device 500 and the unit wherein included, will not be repeated here.Device 500 In corresponding units can be cooperated with the unit in terminal device and/or server to realize The scheme of the embodiment of the present application.
It will be understood by those skilled in the art that above-mentioned resource allocation device 500 also includes some its His known features, such as processor, memory, in order to unnecessarily obscure the reality of the disclosure Example is applied, these known structures are not shown in Figure 5.
Below with reference to Fig. 6, it illustrates suitable for for realizing the terminal device of the embodiment of the present application Or the structural representation of the computer system 600 of server.
As shown in fig. 6, computer system 600 includes CPU (CPU) 601, its Can according to the program being stored in read-only storage (ROM) 602 or from storage part 608 The program that is loaded into random access storage device (RAM) 603 and perform various appropriate actions And processing.In RAM 603, the system that is also stored with 600 operates required various program sums According to.CPU 601, ROM 602 and RAM 603 are connected with each other by bus 604.Input / output (I/O) interface 605 is also connected to bus 604.
I/O interfaces 605 are connected to lower component:Importation 606 including keyboard, mouse etc.; Including cathode-ray tube (CRT), liquid crystal display (LCD) etc. and loudspeaker etc. Output par, c 607;Storage part 608 including hard disk etc.;And including such as LAN card, The communications portion 609 of the NIC of modem etc..Communications portion 609 is via such as The network of internet performs communication process.Driver 610 is also according to needing to be connected to I/O interfaces 605.Detachable media 611, such as disk, CD, magneto-optic disk, semiconductor memory etc., Be arranged on as needed on driver 610, in order to the computer program that reads from it according to Need to be mounted into storage part 608.
Especially, in accordance with an embodiment of the present disclosure, the process described above with reference to flow chart can be with It is implemented as computer software programs.For example, embodiment of the disclosure includes a kind of computer journey Sequence product, it includes being tangibly embodied in the computer program on machine readable media, the meter Calculation machine program bag, which contains, is used for the program code of the method shown in execution flow chart.Implement such In example, the computer program can be downloaded and installed by communications portion 609 from network, And/or be mounted from detachable media 611.
Flow chart and block diagram in accompanying drawing, it is illustrated that according to the system of the various embodiments of the application, Architectural framework in the cards, function and the operation of method and computer program product.This point On, each square frame in flow chart or block diagram can represent a module, program segment or code A part, the part of the module, program segment or code is used for comprising one or more The executable instruction of logic function as defined in realizing.It should also be noted that being used as replacement at some In realization, the function of being marked in square frame can also be with different from the order marked in accompanying drawing hair It is raw.For example, two square frames succeedingly represented can essentially be performed substantially in parallel, they Sometimes it can also perform in the opposite order, this is depending on involved function.It is also noted that It is, each square frame in block diagram and/or flow chart and the square frame in block diagram and/or flow chart Combination, can be realized with the special hardware based system of defined function or operation is performed, Or can be realized with the combination of specialized hardware and computer instruction.
Being described in unit involved in the embodiment of the present application can be real by way of software It is existing, it can also be realized by way of hardware.Described unit can also be arranged on processing In device, for example, can be described as:A kind of processor include acquiring unit, lock unit, really Order member and adding device.Wherein, the title of these units under certain conditions constitute pair The restriction of the unit in itself, for example, acquiring unit is also described as " obtaining the money of user The unit of source distribution request ".
As on the other hand, present invention also provides a kind of nonvolatile computer storage media, The nonvolatile computer storage media can be described in above-described embodiment included in device Nonvolatile computer storage media;Can also be individualism, without non-in supplying terminal Volatile computer storage medium.Above-mentioned nonvolatile computer storage media be stored with one or The multiple programs of person, when one or more of programs are performed by an equipment so that described Equipment:Obtain the resource allocation request of user;Locking operation is carried out to the resource allocation request; Determine whether the user has the authority for obtaining resource according to the result for locking operation;If It is to be added to the resource allocation request as waiting task in buffer queue.
Above description is only the preferred embodiment of the application and saying to institute's application technology principle It is bright.It will be appreciated by those skilled in the art that invention scope involved in the application, is not limited In the technical scheme of the particular combination of above-mentioned technical characteristic, do not departed from while should cover yet In the case of the inventive concept, it is combined by above-mentioned technical characteristic or its equivalent feature Formed by other technical schemes.Such as features described above and (but not limited to) disclosed herein Technical characteristic with similar functions carries out technical scheme formed by replacement mutually.

Claims (12)

1. a kind of resource allocation methods, it is characterised in that methods described includes:
Obtain the resource allocation request of user;
Locking operation is carried out to the resource allocation request;
Determine whether the user has the power for obtaining resource according to the result for locking operation Limit;
If so, being added to the resource allocation request as waiting task in buffer queue.
2. according to the method described in claim 1, it is characterised in that described to the resource point Locking operation is carried out with request, including:
Request is obtained based on resource allocation request generation lock;
Request is obtained in response to generating the lock, judges whether distributed lock can use;
If the distributed lock is available, generation obtains successful message and by the distributed lock State is set to unavailable;And
It is described to determine whether the user has acquisition resource according to the result for locking operation Authority, including:
In response to generating the successful message of acquisition, determine that the user has and obtain resource Authority.
3. method according to claim 2, it is characterised in that methods described also includes:
It is the waiting task distribution resource in the buffer queue using thread pool.
4. method according to claim 2, it is characterised in that by the resource allocation After request is added in buffer queue as waiting task, methods described also includes:
The state of the distributed lock is switched to available.
5. method according to claim 4, it is characterised in that methods described also includes:
Detect the down state duration of the distributed lock;
, will be described if the down state of the distributed lock is sustained for longer than predetermined threshold value The state of distributed lock switches to available.
6. the method according to claim any one of 1-5, it is characterised in that the resource Distribution request includes the identification information of the user and the resource acquisition historical record of the user;
Methods described also includes:
If the user has the authority for obtaining resource, the resource acquisition history to the user is remembered Record is updated.
7. a kind of resource allocation device, it is characterised in that described device includes:
Acquiring unit, the resource allocation request for obtaining user;
Unit is locked, for carrying out locking operation to the resource allocation request;
Determining unit, for determining whether the user has according to the result for locking operation Obtain the authority of resource;
Adding device, for when the user has the authority for obtaining resource, by the resource Distribution request is added in buffer queue as waiting task.
8. device according to claim 7, it is characterised in that the locking unit includes:
First generation module, for obtaining request based on resource allocation request generation lock;
Whether judge module, for obtaining request in response to generating the lock, judge distributed lock It can use;
Second generation module, for available in response to the distributed lock, generate and obtains successful The state of the distributed lock is simultaneously set to unavailable by message;
The determining unit is further used in response to generating the successful message of acquisition, it is determined that The user has the authority for obtaining resource.
9. device according to claim 8, it is characterised in that described device also includes:
Allocation unit, for being that the waiting task in the buffer queue is distributed using thread pool Resource.
10. device according to claim 8, it is characterised in that described device also includes:
Unlocking unit, in the adding device using the resource allocation request as pending After task is added in buffer queue, the state of the distributed lock is switched to available.
11. device according to claim 10, it is characterised in that described device also includes Processing unit, is used for:
Detect the down state duration of the distributed lock;
, will be described if the down state of the distributed lock is sustained for longer than predetermined threshold value The state of distributed lock switches to available.
12. the device according to claim any one of 7-11, it is characterised in that the money Source distribution request includes the identification information of the user and the resource acquisition history note of the user Record;
Described device also includes:
Updating block, for when the user has the authority for obtaining resource, to the user Resource acquisition historical record be updated.
CN201610232468.2A 2016-04-14 2016-04-14 Resource allocation methods and device Pending CN107301091A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610232468.2A CN107301091A (en) 2016-04-14 2016-04-14 Resource allocation methods and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610232468.2A CN107301091A (en) 2016-04-14 2016-04-14 Resource allocation methods and device

Publications (1)

Publication Number Publication Date
CN107301091A true CN107301091A (en) 2017-10-27

Family

ID=60136786

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610232468.2A Pending CN107301091A (en) 2016-04-14 2016-04-14 Resource allocation methods and device

Country Status (1)

Country Link
CN (1) CN107301091A (en)

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108989104A (en) * 2018-07-11 2018-12-11 北京京东金融科技控股有限公司 Dynamic allocation method, device, medium and the electronic equipment of resource
CN109271265A (en) * 2018-09-29 2019-01-25 平安科技(深圳)有限公司 Request processing method, device, equipment and storage medium based on message queue
CN109343958A (en) * 2018-09-25 2019-02-15 江苏满运软件科技有限公司 Computational resource allocation method, apparatus, electronic equipment, storage medium
CN109376014A (en) * 2018-10-19 2019-02-22 郑州云海信息技术有限公司 A kind of Distributed Lock Manager method and system
CN110058948A (en) * 2019-04-28 2019-07-26 恒生电子股份有限公司 A kind of resource monitoring method, device, equipment and medium
CN110659386A (en) * 2019-09-12 2020-01-07 北京达佳互联信息技术有限公司 Digital resource processing method and device, electronic equipment and storage medium
CN110764899A (en) * 2019-09-03 2020-02-07 无锡华云数据技术服务有限公司 Resource quota management method, resource processing method, device, equipment, system and medium
CN112069105A (en) * 2020-07-31 2020-12-11 深圳市优必选科技股份有限公司 Serial port communication processing method and device and electronic equipment
CN112785323A (en) * 2019-11-07 2021-05-11 北京沃东天骏信息技术有限公司 Resource allocation method and device and electronic equipment
CN112905322A (en) * 2021-02-09 2021-06-04 掌阅科技股份有限公司 Resource locking method, computing device and computer storage medium

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5734909A (en) * 1995-09-01 1998-03-31 International Business Machines Corporation Method for controlling the locking and unlocking of system resources in a shared resource distributed computing environment
CN1945539A (en) * 2006-10-19 2007-04-11 华为技术有限公司 Method for distributing shared resource lock in computer cluster system and cluster system
CN102508872A (en) * 2011-10-12 2012-06-20 恒生电子股份有限公司 Data processing method and system of online processing system based on memory
CN104699527A (en) * 2013-12-10 2015-06-10 杭州海康威视系统技术有限公司 Critical resource management method and device in cloud storage system
CN104954411A (en) * 2014-03-31 2015-09-30 腾讯科技(深圳)有限公司 Method for sharing network resource by distributed system, terminal thereof and system thereof
CN105245372A (en) * 2015-10-12 2016-01-13 浪潮软件集团有限公司 Optimization method for loading network resources based on cache and asynchronous mechanism
US20160021026A1 (en) * 2014-07-15 2016-01-21 Cohesity, Inc. Distributed fair allocation of shared resources to constituents of a cluster
CN105471881A (en) * 2015-12-07 2016-04-06 北京奇虎科技有限公司 Method, device and system for locking and unlocking requests

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5734909A (en) * 1995-09-01 1998-03-31 International Business Machines Corporation Method for controlling the locking and unlocking of system resources in a shared resource distributed computing environment
CN1945539A (en) * 2006-10-19 2007-04-11 华为技术有限公司 Method for distributing shared resource lock in computer cluster system and cluster system
CN102508872A (en) * 2011-10-12 2012-06-20 恒生电子股份有限公司 Data processing method and system of online processing system based on memory
CN104699527A (en) * 2013-12-10 2015-06-10 杭州海康威视系统技术有限公司 Critical resource management method and device in cloud storage system
CN104954411A (en) * 2014-03-31 2015-09-30 腾讯科技(深圳)有限公司 Method for sharing network resource by distributed system, terminal thereof and system thereof
US20160021026A1 (en) * 2014-07-15 2016-01-21 Cohesity, Inc. Distributed fair allocation of shared resources to constituents of a cluster
CN105245372A (en) * 2015-10-12 2016-01-13 浪潮软件集团有限公司 Optimization method for loading network resources based on cache and asynchronous mechanism
CN105471881A (en) * 2015-12-07 2016-04-06 北京奇虎科技有限公司 Method, device and system for locking and unlocking requests

Cited By (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108989104A (en) * 2018-07-11 2018-12-11 北京京东金融科技控股有限公司 Dynamic allocation method, device, medium and the electronic equipment of resource
CN108989104B (en) * 2018-07-11 2021-05-25 北京京东金融科技控股有限公司 Dynamic resource allocation method, device, medium and electronic equipment
CN109343958B (en) * 2018-09-25 2021-05-11 广州回头车信息科技有限公司 Computing resource allocation method and device, electronic equipment and storage medium
CN109343958A (en) * 2018-09-25 2019-02-15 江苏满运软件科技有限公司 Computational resource allocation method, apparatus, electronic equipment, storage medium
CN109271265A (en) * 2018-09-29 2019-01-25 平安科技(深圳)有限公司 Request processing method, device, equipment and storage medium based on message queue
CN109271265B (en) * 2018-09-29 2023-09-15 平安科技(深圳)有限公司 Request processing method, device, equipment and storage medium based on message queue
WO2020062793A1 (en) * 2018-09-29 2020-04-02 平安科技(深圳)有限公司 Message queue-based request processing method, apparatus and device, and storage medium
CN109376014A (en) * 2018-10-19 2019-02-22 郑州云海信息技术有限公司 A kind of Distributed Lock Manager method and system
CN110058948A (en) * 2019-04-28 2019-07-26 恒生电子股份有限公司 A kind of resource monitoring method, device, equipment and medium
CN110058948B (en) * 2019-04-28 2022-01-28 恒生电子股份有限公司 Resource monitoring method, device, equipment and medium
CN110764899A (en) * 2019-09-03 2020-02-07 无锡华云数据技术服务有限公司 Resource quota management method, resource processing method, device, equipment, system and medium
CN110659386A (en) * 2019-09-12 2020-01-07 北京达佳互联信息技术有限公司 Digital resource processing method and device, electronic equipment and storage medium
CN112785323A (en) * 2019-11-07 2021-05-11 北京沃东天骏信息技术有限公司 Resource allocation method and device and electronic equipment
CN112069105A (en) * 2020-07-31 2020-12-11 深圳市优必选科技股份有限公司 Serial port communication processing method and device and electronic equipment
CN112069105B (en) * 2020-07-31 2022-09-23 深圳市优必选科技股份有限公司 Serial port communication processing method and device and electronic equipment
CN112905322B (en) * 2021-02-09 2021-11-19 掌阅科技股份有限公司 Resource locking method, computing device and computer storage medium
CN112905322A (en) * 2021-02-09 2021-06-04 掌阅科技股份有限公司 Resource locking method, computing device and computer storage medium

Similar Documents

Publication Publication Date Title
CN107301091A (en) Resource allocation methods and device
CN105450705B (en) Business data processing method and equipment
CN109597822B (en) User data storage and query method and user data processing device
CN107852412A (en) For phishing and the system and method for brand protection
CN107656815A (en) Method and apparatus for controlling distributed lock
CN109542894B (en) User data centralized storage method, device, medium and computer equipment
CN112468409A (en) Access control method, device, computer equipment and storage medium
CN107291769A (en) The method and apparatus for handling concurrent order
CN112733531A (en) Virtual resource allocation method and device, electronic equipment and computer storage medium
CN106992975A (en) The recognition methods of malice network address and device
CN109669644A (en) A kind of method and apparatus of data storage
CN113779536A (en) User access method, system, electronic device and medium
CN110580307B (en) Processing method and device for fast statistics
US20190305934A1 (en) System and methods for recording codes in a distributed environment
CN106215417A (en) Server and gift bag distributor and method
CN103024091B (en) Obtain method and the device of networking client actual physical address
CN114924783A (en) Interface calling method, device, equipment and storage medium of application program
CN112256760B (en) Data prediction method and device, computer equipment and storage medium
CN107995167A (en) A kind of device identification method and server
CN113360916A (en) Risk detection method, device, equipment and medium for application programming interface
CN107203709A (en) The unlocking method and a device of alarm clock
CN109472156A (en) Information access method, device, electronic equipment and computer readable storage medium
US11385925B1 (en) System and method for provisioning hosted virtual desktop resources to remote users
US11789783B2 (en) Hosted virtual desktop slicing using federated edge intelligence
CN115209232B (en) Video processing method and device, electronic equipment and storage medium

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
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20171027