[go: up one dir, main page]

CN109783230A - Flow control methods, device, computer equipment and storage medium based on semaphore - Google Patents

Flow control methods, device, computer equipment and storage medium based on semaphore Download PDF

Info

Publication number
CN109783230A
CN109783230A CN201811544822.0A CN201811544822A CN109783230A CN 109783230 A CN109783230 A CN 109783230A CN 201811544822 A CN201811544822 A CN 201811544822A CN 109783230 A CN109783230 A CN 109783230A
Authority
CN
China
Prior art keywords
license
semaphore
task
initial
count
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
CN201811544822.0A
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.)
Guangzhou Chengyi Technology Consulting Co ltd
Original Assignee
Ping An Puhui Enterprise Management 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 Ping An Puhui Enterprise Management Co Ltd filed Critical Ping An Puhui Enterprise Management Co Ltd
Priority to CN201811544822.0A priority Critical patent/CN109783230A/en
Publication of CN109783230A publication Critical patent/CN109783230A/en
Pending legal-status Critical Current

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

This application involves a kind of flow control methods based on semaphore, device, computer equipment and storage mediums, are related to traffic monitoring field.The described method includes: obtaining waiting task, the corresponding task type of the waiting task is judged;Obtain the corresponding semaphore of the task type;If the license of the semaphore has been expired, the license for obtaining the semaphore borrows configuration;Wherein, the license borrows the borrow attribute for being configured to describe the semaphore and is borrowed attribute;If the license borrows configuration, the described attribute that borrows is to allow to borrow, and searches echo signal amount, it is to allow to be borrowed that the license of the echo signal amount, which borrows and is borrowed attribute described in configuration,;It is obtained from the echo signal amount and borrows license, and borrow license is dispatched to the waiting task;The waiting task is added in thread resources, until task processing is completed, discharges the borrow license.Being adjusted flexibly for multichannel task flow can be realized using this method.

Description

Flow control methods, device, computer equipment and storage medium based on semaphore
Technical field
This application involves field of computer technology, more particularly to a kind of flow control methods based on semaphore, device, Computer equipment and storage medium.
Background technique
Semaphore (Semaphore), is a kind of tool used under multi-thread environment, it is responsible for coordinating each thread, With guarantee thread can correctly, reasonably using public resource.Before entering a critical code section, thread must obtain one A semaphore, once the critical code section is performed and completes, which must release semaphore.For example, working as score When journey needs to be implemented certain section of critical code section, due to no existing semaphore, it is therefore necessary to wait until that other threads are released Discharge signal amount, the subject thread could use resource to execute critical code section.Current most task is all using thread pool To control concurrent and resource allocation, generally distributes and be difficult to carry out flexibly adjustment and monitoring later.
Summary of the invention
Based on this, it is necessary in view of the above technical problems, provide a kind of flexible tune that can be realized multichannel task flow The whole flow control methods based on semaphore, device, computer equipment and storage medium.
A kind of flow control methods based on semaphore, which comprises
Waiting task is obtained, judges the corresponding task type of the waiting task;
Obtain the corresponding semaphore of the task type;
If the license of the semaphore has been expired, the license for obtaining the semaphore borrows configuration;Wherein, the license is borrowed With the borrow attribute for being configured to describe the semaphore and it is borrowed attribute;
If the license borrows configuration, the described attribute that borrows is to allow to borrow, and searches echo signal amount, the mesh It is to allow to be borrowed that the license of mark semaphore, which borrows and is borrowed attribute described in configuration,;
It is obtained from the echo signal amount and borrows license, and borrow license is dispatched to the waiting task;
The waiting task is added in thread resources, until task processing is completed, discharges the borrow license.
In one embodiment, before the corresponding semaphore of the acquisition task type, further includes:
Obtain semaphore license sum;
Determine the initial license count of corresponding semaphore according to the priority of the task type, all semaphores just The sum of beginning license count is no more than semaphore license sum;
Determine that the license of the corresponding semaphore borrows configuration according to the priority of the task type, the license is borrowed It includes whether to need to borrow with configuration and whether allows to borrow.
In one embodiment, if the license in the semaphore has been expired, the license for obtaining the semaphore is borrowed After configuration, further includes:
If the license borrows configuration, the described attribute that borrows is not allow to borrow, and the waiting task is marked To block clearance for holding;
It is more than given threshold when the task quantity labeled as obstruction clearance for holding is more than given threshold and/or waiting time, Then adjust the initial license count of the corresponding semaphore;
The initial license count of the semaphore is updated to database.
In one embodiment, the method also includes:
First initial license count of semaphore described in monitoring caching, when the described first initial license count cache-time reaches When the preset cache time limit, the corresponding second initial license count of the semaphore is obtained from database;
If the first initial license count is less than the described second initial license count, by the described in caching first initial license Number is adjusted to the described second initial license count;
If the first initial license count is greater than the described second initial license count, the idle license of the semaphore is obtained Number will caching if the free time license count is less than the difference of the described first initial license count and the described second initial license count Described in the first initial license count be adjusted to the difference of the described first initial license count and the idle license count;
The license of the semaphore release is recycled, until the license count of recycling is equal to the adjusted described first initial license Several differences between the described second initial license count, and then the described in caching first initial license count is adjusted to described second Initial license count.
In one embodiment, described obtain from the echo signal amount borrows license, and the borrow is permitted to assign After the waiting task, further includes:
Generate the first operation note of semaphore;
First task data are extracted from the waiting task;
First operation note of semaphore is associated with the first task data;
It is described that the waiting task is added in thread resources, until task processing is completed, discharges the borrow and permitted Can after, further includes:
The second task data is extracted from task processing result;
The second operation note of semaphore is generated, second operation note of semaphore is associated with second task data.
A kind of volume control device based on semaphore, described device include:
Task acquisition module judges the corresponding task type of the waiting task for obtaining waiting task;
Semaphore obtains module, for obtaining the corresponding semaphore of the task type;
License borrows configuration and obtains module, if the license for the semaphore has been expired, obtains being permitted for the semaphore Configuration can be borrowed;
Permissions module is borrowed, if being configured to need to borrow for license borrow, the license is searched and borrows configuration To allow the echo signal amount borrowed;
Task processing module, for from the echo signal amount borrow permit, and by borrows license be dispatched to described in The waiting task is added in thread resources by waiting task, until task processing is completed, is discharged the borrow and is permitted It can.
In one embodiment, described device further include:
Block permissions module, if being configured to not need to borrow for license borrow, by the waiting task mark It is denoted as obstruction clearance for holding;
Initial license count adjusts module, for when the task quantity labeled as obstruction clearance for holding be more than given threshold and/ Or the waiting time is more than given threshold, then adjusts the initial license count of the corresponding semaphore;
Memory module, for the initial license count of the semaphore to be updated to database.
In one embodiment, described device further include:
Data cached update module, for monitoring the first initial license count of semaphore described in caching, when described first When initial license count cache-time reaches the preset cache time limit, the semaphore corresponding second is obtained from database and is initially permitted It is denumerable;If the first initial license count is less than the described second initial license count, by the first initial license count described in caching It is adjusted to the described second initial license count;If the first initial license count is greater than the described second initial license count, institute is obtained The idle license count of semaphore is stated, if the free time license count is less than the described first initial license count and the described second initial license Described in caching first initial license count is then adjusted to the described first initial license count and the idle license count by several differences Difference;The license of the semaphore release is recycled, until the license count of recycling is equal to the adjusted described first initial license Several differences between the described second initial license count, and then the described in caching first initial license count is adjusted to described second Initial license count.
A kind of computer equipment, including memory and processor, the memory are stored with computer program, the processing The step of device realizes method described above when executing the computer program.
A kind of computer readable storage medium, is stored thereon with computer program, and the computer program is held by processor The step of method described above is realized when row.
The above-mentioned flow control methods based on semaphore, device, computer equipment and storage medium, mark off multiple first Task type, and corresponding semaphore is defined for each task type, it assigns semaphore and borrows attribute and be borrowed attribute;Pass through It borrows attribute and is borrowed attribute and realize the borrow permitted between semaphore, the remaining license of semaphore is borrowed has expired to license Semaphore, realize being adjusted flexibly for multichannel task flow, it is shortage of resources on one side that avoiding, which is resources left on one side, Realize maximum resource utilization.
Detailed description of the invention
Fig. 1 is the application scenario diagram of the flow control methods based on semaphore in one embodiment;
Fig. 2 is the flow diagram of the flow control methods based on semaphore in one embodiment;
Fig. 3 is that initial license count adjusts related flow diagram in one embodiment;
Fig. 4 is the structural block diagram of the volume control device based on semaphore in one embodiment;
Fig. 5 is the internal structure chart of computer equipment in one embodiment.
Specific embodiment
It is with reference to the accompanying drawings and embodiments, right in order to which the objects, technical solutions and advantages of the application are more clearly understood The application is further elaborated.It should be appreciated that specific embodiment described herein is only used to explain the application, not For limiting the application.
Flow control methods provided by the present application based on semaphore, can be applied in application environment as shown in Figure 1. Wherein, terminal 102 is communicated with server 104 by network by network.Terminal 102 generates waiting task, and will be to Processing task is sent to server 104, and server 104 carries out orderly processing to waiting task, and returns and appoint to terminal 102 Business processing result.Wherein, terminal 102 can be, but not limited to be various personal computers, laptop, smart phone, plate Computer and portable wearable device, server 104 are single-point application servers, are independent server.
In one embodiment, as shown in Fig. 2, providing a kind of flow control methods based on semaphore, this method is answered With in the server, is controlled and adjusted for the execution flow to all tasks in server.This method specifically includes Following steps:
Step 202, waiting task is obtained, judges the corresponding task type of waiting task.
Server is used to provide service to terminal, and in response to the various operations of terminal user, server needs to carry out each Kind data processing and operation.The data processing and operation that server is made become executing required for server for task.
It should be noted that the present embodiment is issued based on single-point application server (i.e. an application server) wait hold For row task.
Specifically, all tasks in single-point server are divided into different task types, the task class of division in advance The granularity of type can be depending on specific demand.When carrying out task type division, a task can be marked off multiple tasks Multiple tasks can also be defined as same task type by type.One task is marked off into multiple tasks type, such as looking into Ask reference report task, by from first inquiry host complex and be on-line checking task definition be first task type, Host complex will be inquired from first and be that the task definition inquired under line is Second Type, will inquire host complex from second And be the task definition of on-line checking be third type, it from the second inquiry host complex and will be that the task definition inquired under line is 4th type.Task can also be divided into vital task and common task, all vital tasks are defined as same task class Type defines higher priority to the task type, is that the task type defines the more signal of flow will pass through semaphore Amount, task of enabling these crucial are preferential in time processed.
Step 204, the corresponding semaphore of task type is obtained.
The corresponding semaphore of every kind of task type is pre-defined, and the semaphore of definition is stored to database, and with Flow control, by the semaphore information update in database into caching, it is corresponding that server obtains task type from caching Semaphore.
The effect of semaphore and the effect of signal lamp are similar, and signal lamp is used to control the flow in corresponding lane, and semaphore For controlling the flow of corresponding task type.
In the present embodiment, definition signal amount includes defining the license borrow configuration of initial license count, semaphore.Initial license The maximum flow that number refers to that semaphore license is let pass is meant that, server is most if the initial license count of semaphore is 100 The task quantity that the corresponding task type of the semaphore can mostly be handled simultaneously is 100.If a certain moment, corresponding task type Task quantity is 200, and semaphore can only give sequence and obtain license in preceding 100 task, and server process obtains appointing for license Business, the license to be obtained such as then of remaining 100 tasks after the completion of the one of task execution being licensed, will discharge a license, Semaphore obtains the license of the release, and next task is allowed to obtain license, and server process obtains the task of license.
Whether the license of semaphore borrows configuration and includes: whether to need to borrow and allow to borrow.Wherein, it needs to borrow and is When the license of semaphore itself has been expired, it can borrow and permit to other semaphores.Whether allow to borrow is to borrow the license of itself With the semaphore borrowed to needs.
For example, 1 → semaphore of task type 1 (license count 100 needs to borrow, do not allow to borrow);Task type 2 → semaphore 2 (license count 50 needs to borrow, allows to borrow);(license count 50 does not need 3 → semaphore of task type 3 It borrows, allow to borrow).Based on above-mentioned definition, semaphore 2 can borrow itself license to semaphore 1, but the license of semaphore 1 It is not for circulation.Semaphore 3 cannot be borrowed to other semaphores permits, but the semaphore of itself can be borrowed to semaphore 1 and letter Number amount 2.
Step 206, if the license of semaphore has been expired, the license for obtaining semaphore borrows configuration, wherein license, which borrows, matches It sets the borrow attribute for describing semaphore and is borrowed attribute.
When server receives a waiting task, task class is determined according to the task data of waiting task first Type obtains the corresponding letter of the waiting task then according to the corresponding relationship between task type predetermined and semaphore Number amount.
Server obtains the current permission status of corresponding semaphore, and the current permission status of semaphore includes remaining license Number, the license count of lending and the license count of borrowing.Wherein, remaining license count be semaphore initial license count subtract it is occupied License count.If the initial license count of semaphore is all occupied, i.e., remaining license count is 0, then the license of semaphore has been expired.
Semaphore license borrow configuration in borrow attribute description be whether allow to borrow the license of other semaphores.Quilt Borrow attribute description is whether to allow other semaphores to borrow license.
Step 208, if license borrows configuration, the described attribute that borrows is to allow to borrow, and searches echo signal amount, mesh It is to allow to be borrowed that the license of mark semaphore, which borrows and is borrowed attribute described in configuration,.
Step 210, it is obtained from echo signal amount and borrows license, and be dispatched to waiting task for license is borrowed.
Step 212, waiting task is added in thread resources, until task processing is completed, release borrows license.
If the license of the corresponding semaphore of waiting task has been expired, the license for obtaining semaphore borrows configuration.If semaphore Borrow attribute be allow to borrow, that is, allow from other semaphores obtain borrow license.Server searches whether that presence can borrow The echo signal amount of license.Echo signal amount is needed with two following conditions, and one is that echo signal amount is borrowed attribute To allow to be borrowed, secondly the still available free license of echo signal amount.If finding the echo signal amount for meeting above-mentioned condition, from Echo signal amount borrows its free time license.The idle license borrowed from echo signal amount is named as borrow license.
The corresponding semaphore of waiting task will borrow license and distribute to this after obtaining borrow license in echo signal amount Waiting task, so that the state of the waiting task is to obtain license.Server process obtains the task of license.
Echo signal amount is by after itself license lending, and the remaining license count of echo signal amount reduces 1, and lending semaphore number increases Add 1, the borrowing license count of the corresponding semaphore of waiting task increases by 1.In one embodiment, each borrowing is permitted to be associated with Permit source signal amount mark, each lending license association place to go semaphore mark.
For example, waiting task corresponds to semaphore 1, and the remaining license count of semaphore 1 is 0, and lending license is 0, borrowing License is 0.The remaining license count of semaphore 2 is 20, and lending license count is 10, and borrowing license count is 0.In order to handle to be processed Business, semaphore 1 borrow a license from semaphore 2.The remaining license count of semaphore 1 is 0 after borrow, and lending license count is 0, Borrow license count are as follows: 1, come from semaphore 2.The remaining license count of semaphore 2 is 19, and lending license count is the 11 (lendings of semaphore 1 License 1 ...), borrowing license count is 0.
After the completion of the corresponding any task execution of semaphore 1, the license of release returns to semaphore 2.Implement at one In example, it is also possible that will borrow license after the completion of borrowing the corresponding waiting task of license and return to source signal amount.
In one embodiment, if there are multiple tasks etc. pending, multiple licenses can be borrowed from other semaphores, it will be multiple It borrows license and is dispatched to multiple waiting tasks.It discharges to borrow after the completion of task and is licensed to source signal amount.
In the present embodiment, multiple tasks type is marked off, the corresponding semaphore of each task type is defined, passes through semaphore The retrievable resource of every kind of task type is controlled, biggish semaphore initial value is defined for important task type, with Important task is set to obtain more resources to realize resource optimization.In addition, assign and borrowing for semaphore in the present embodiment Attribute realizes the borrow permitted between semaphore by borrowing attribute, realizes being adjusted flexibly for multichannel task flow, avoid It is resources left on one side, is shortage of resources on one side, realizes maximum resource utilization.
In one embodiment, when semaphore license borrow occurs, a bars amount is generated when borrowing license Operation note, and another bars amount operation note is generated when release borrows license.Semaphore operations record includes borrowing to be permitted It can time or release borrow permitted hours, borrow both sides.In addition, semaphore operations record when borrowing license further includes obtaining to borrow With the corresponding mission bit stream of the task of license, including task identification, odd numbers, input value.Semaphore operations note when release license Record includes task result information, including task identification, odd numbers, output valve, processing time etc..
In the present embodiment, the license of borrow each time for semaphore generates semaphore operations record, and records and the letter Number relevant mission bit stream of amount operation note.It is had good grounds by the license of multi channel signals amount, when system exception alarm, root Abnormal task can be quickly oriented according to semaphore operation note.
The corresponding semaphore of each task type can be artificial right taking human as configuration, but when the task type of division is more Each semaphore is configured, inefficiency.A kind of semaphore configuration method is present embodiments provided, is realized to numerous signals The rapid configuration of amount.Specifically: obtain semaphore license sum;It is determined according to the priority of task type predetermined each The initial license count of the corresponding semaphore of task type, wherein the initial license count of the corresponding semaphore of all task types it Permit sum with no more than semaphore;Determine that the license of corresponding semaphore borrows configuration according to the priority of task type, In, it includes the configuration for borrowing attribute and being borrowed attribute that license, which borrows configuration,.
More specifically, it is determined according to software and hardware condition and needs adjustable execution resource.Signal can automatically generated Typing executes resource information before measuring information, and server executes resource information according to typing and calculates semaphore sum.According to execution It, can be simultaneously when can first calculate all execution resources and executing the task of any task type when Resource Calculation semaphore sum Then the maximum task quantity of processing it is total to calculate semaphore license according to the corresponding maximum number of tasks amount of each task type Number.
For example, task type includes task type 1 and task type 2, and all execution resources are at best able to locate simultaneously Managing the corresponding task quantity of task type 1 is 200, and all execution resources are at best able to handle task type 2 corresponding simultaneously Quantity of being engaged in is 150, and semaphore permits total maximum to may not exceed 200, and minimum must not be lower than 150.It can be all task quantity Mean value.
After determining semaphore license sum, the corresponding semaphore of each task type is determined according to the priority of task type Initial license count.Further, it is handled and is recorded by historic task, calculate the task amount ratio of every kind of task type, be based on appointing Business amount ratio and the priority of task type determine the initial license count of the corresponding semaphore of each task type.Such as task class The priority of type 1 is higher than task type 2, and the task amount ratio of task type 1 and task type 2 is 2:1, and license sum is 300, First according to the initial license count of task amount ratio-dependent, determining initial license count is being adjusted according to priority.Such as according to The corresponding initial license count of task amount ratio-dependent task type 1 is 200, and the corresponding initial license count of task type 2 is 100, Due to the priority with higher of task type 1, the corresponding initial license count of task type 1 can be raised, is as above adjusted to 250.
Finally determine that the license of corresponding semaphore borrows configuration according to the priority of task type.In one embodiment In, it can be to allow to borrow by the borrow attribute configuration of the corresponding semaphore of the high task type of priority, be borrowed attribute and match Being set to does not allow to be borrowed.The borrow attribute of the corresponding semaphore of the low task type of priority is set as not allowing to borrow, Being borrowed attribute configuration is to allow to be borrowed.Can also be determined according to the priority of task type allows to borrow the upper limit and permission quilt Borrow the upper limit.
In the present embodiment, for the more license counts of the higher task type configuration of priority, the borrow condition more having, so that The higher task of priority can be handled preferentially.
In one embodiment, if the license of the corresponding semaphore of waiting task has been expired, and the waiting task is corresponding Semaphore borrow attribute be do not allow to borrow, i.e., the semaphore can not to other semaphores borrow permit, then this be waited for Processing is labeled as obstruction clearance for holding.Correspondingly, the waiting task generated after this again is also labeled as obstruction clearance for holding.
The time that the waiting task quantity and obstruction for monitoring obstruction clearance for holding wait (listens only to the resistance to rank the first Fill in the time that the waiting task of clearance for holding waits), if the waiting task quantity of obstruction clearance for holding is more than the threshold of setting The waiting time for being worth perhaps initial waiting task is equal more than given threshold or waiting task quantity and waiting time More than corresponding setting value, then server increases the initial license count of corresponding signal amount, or corresponding signal amount is never allowed It borrows permission configuration to be adjusted to allow to borrow permission configuration, or increase corresponding signal amount to allow to borrow permissible upper.
Correspondingly, adjusting the corresponding semaphore configuration of unsaturated semaphore.If at the remaining license count long-time of semaphore In high level, then the semaphore is unsaturated semaphore.The initial license count and license for adjusting unsaturated semaphore borrow configuration. Specifically, reducing the initial license count of unsaturated semaphore, the needs borrow of unsaturated semaphore is configured to not allow to borrow, It would not allow for being borrowed and be configured to allow to be borrowed.
Server stores the semaphore configuration after change in the database.
In the present embodiment, in semaphore dynamic adaptation multichannel flow, the real-time task processing shape in each channel is monitored State, according to the configuration of real-time task processing status dynamic adjustment signal amount, so that the flow control of semaphore is more flexible.
In one embodiment, as shown in figure 3, the flow method of adjustment based on semaphore, further includes following steps:
Step 302, the first initial license count for monitoring semaphore in caching, when the first initial license count cache-time reaches When the preset cache time limit, the corresponding second initial license count of semaphore is obtained from database.
In the database by the semaphore fixed storage of definition, when carrying out flow control, server obtains appoints server The corresponding semaphore of service type first looks for whether being stored with semaphore information in caching, if it is not, then obtaining letter from database Number amount information, and by semaphore information cache into caching.
The caching period of pre-defined information in the buffer, such as 10 minutes.Semaphore information in server monitoring caching, Configuration information etc. is borrowed including the initial license count of semaphore, semaphore license.When semaphore information reaches the preset cache time limit (10 Minute), server pulls newest semaphore information from database, in the buffer by the storage of newest semaphore information, together When monitor whether the newest semaphore information cache time reaches the preset cache period, if so, being updated from database again newest Semaphore information.
In traffic monitoring, server can according to the configuration of actual task processing status dynamic adjustment signal amount, and Semaphore configuration adjusted (including the license of the initial license count of semaphore, semaphore borrows configuration information) is stored in database In, and newest semaphore configuration is obtained from database every set time period in caching.
In the present embodiment, the first initial license count is the initial license count in caching, and the second initial license count is database In initial license count.
Step 304, if the first initial license count is less than the second initial license count, by the first initial license count tune in caching Whole is the second initial license count.
When caching expires, server reads the initial license count of semaphore from database, and compares the first of database end Beginning license count and caching in initial license count, if caching in initial license count be less than database in initial license count ( It is the initial license count that server increases semaphore), then directly the initial license count in caching is adjusted in database Initial license count.The current idle license count of corresponding signal amount increases.
For example, the initial license count of semaphore 1 in the buffer is 100, and the initial license count of database is 200, letter Number 1 current idle license count of amount is 0, and caching is when expiring, update it is data cached after, the initial license count in caching is 200, signal Measuring 1 current idle license count is the difference between the initial license count (200) extracted in caching and current occupied license count, It is herein 100.
Step 306, if the first initial license count is greater than the second initial license count, the idle license count of semaphore is obtained, If idle license count is less than the difference of the first initial license count and the second initial license count, by the first initial license count in caching It is adjusted to the difference of the first initial license count and idle license count.
When caching expires, server reads the initial license count of semaphore from database, and compares the first of database end Beginning license count and caching in initial license count, if caching in initial license count be greater than database in initial license count ( It is the less initial license count of semaphore of server), then need to recycle the license count of semaphore, at this point, first obtaining signal The current idle license count of amount directly will caching if current idle license count is more than or equal to less initial license count In initial license count be adjusted to the initial license count in database.If current idle license count is less than the initial license reduced Initial license count in caching, then is adjusted to the difference of the initial license count and current idle license count in current cache by number.
For example, the initial license count of semaphore 1 in the buffer is 100, and the initial license count of database is 50, signal Measuring 1 current idle license count is 30, when caching expires, needs the initial license count in caching being altered to 50 from 100, need back 50 idle licenses are received, and at this point, idle license count is only 30, then the idle license of first recycling 39 that is, will be initial in caching License count is adjusted to 100-30, i.e., 70.
Step 308, the license of recycling semaphore release, until the license count of recycling is equal to the adjusted first initial license Difference between several and the second initial license count, and then the in caching first initial license count is adjusted to the second initial license count.
Next, server continues to recycle the license of semaphore free time, until the idle license of recycling be in step 308 for the first time The difference between initial license count in initial license count in caching adjusted and database.
After the initial license count in caching is such as adjusted to 70, continue to recycle idle license, until turning one's head again 20 free time License (70 and database in initial license count 50 between difference), and then the initial license count in caching is adjusted to data Initial license count 50 in library completes the update of data in caching.
In the present embodiment, when giving the initial License Value of semaphore and reducing or increase, data-updating method in caching, Realize the configuration of seamless change semaphore in the case where not influencing semaphore dynamically control multichannel service traffics in real time ?.
It should be understood that although each step in the flow chart of Fig. 2 and 3 is successively shown according to the instruction of arrow, It is these steps is not that the inevitable sequence according to arrow instruction successively executes.Unless expressly stating otherwise herein, these steps There is no stringent sequences to limit for rapid execution, these steps can execute in other order.Moreover, in Fig. 2 and 3 at least A part of step may include that perhaps these sub-steps of multiple stages or stage are not necessarily in same a period of time to multiple sub-steps Quarter executes completion, but can execute at different times, the execution in these sub-steps or stage be sequentially also not necessarily according to Secondary progress, but in turn or can replace at least part of the sub-step or stage of other steps or other steps Ground executes.
In one embodiment, as shown in figure 4, providing a kind of volume control device based on semaphore, comprising:
Task acquisition module 402 judges the corresponding task type of the waiting task for obtaining waiting task.
Semaphore obtains module 404, for obtaining the corresponding semaphore of the task type.
License borrows configuration acquisition module 406 and obtains the semaphore if the license for the semaphore has been expired License borrows configuration, wherein the license borrows the borrow attribute for being configured to describe the semaphore and is borrowed attribute.
Permissions module 408 is borrowed, if borrowing the described attribute that borrows of configuration for the license is to allow to borrow, is looked into Echo signal amount is looked for, it is to allow to be borrowed that the license of the echo signal amount, which borrows and is borrowed attribute described in configuration,.
Task processing module 410 borrows license for obtaining from the echo signal amount, and the borrow is permitted to assign To the waiting task, the waiting task is added in thread resources, until task processing is completed, is borrowed described in release With license.
In one embodiment, based on the volume control device of semaphore, further includes: semaphore configuration module, for obtaining Take semaphore license sum;The initial license count of corresponding semaphore is determined according to the priority of the task type, it is all described The sum of initial license count of semaphore is no more than semaphore license sum;According to determining pair of the priority of the task type The license for the semaphore answered borrows configuration.
In one embodiment, based on the volume control device of semaphore, further includes:
Block permissions module, it, will if borrowing the described attribute that borrows of configuration for the license is not allow to borrow The waiting task is labeled as obstruction clearance for holding.
Initial license count adjusts module, for when the task quantity labeled as obstruction clearance for holding be more than given threshold and/ Or the waiting time is more than given threshold, then adjusts the initial license count of the corresponding semaphore.
Memory module, for the initial license count of the semaphore to be updated to database.
In one embodiment, based on the volume control device of semaphore, further includes: data cached update module is used for First initial license count of semaphore described in monitoring caching, when the described first initial license count cache-time reaches preset cache When the time limit, the corresponding second initial license count of the semaphore is obtained from database;If the first initial license count is less than The second initial license count, then be adjusted to the described second initial license count for the described in caching first initial license count;If institute The first initial license count is stated greater than the described second initial license count, then the idle license count of the semaphore is obtained, if the sky Not busy license count is less than the difference of the described first initial license count and the described second initial license count, then will cache described at the beginning of first Beginning license count is adjusted to the difference of the described first initial license count and the idle license count;Recycle being permitted for the semaphore release Can, until the license count of recycling is equal to the difference between the first initial license count adjusted and the second initial license count Value, and then the described in caching first initial license count is adjusted to the described second initial license count.
In one embodiment, task processing module is also used to generate the first operation note of semaphore;From described to be processed First task data are extracted in task;First operation note of semaphore is associated with the first task data;
The waiting task is added in thread resources described, until task processing is completed, discharges the borrow After license, the second task data is extracted from task processing result;Generate the second operation note of semaphore, the semaphore the Two operation notes are associated with second task data.
Specific restriction about the volume control device based on semaphore may refer to above for based on semaphore The restriction of flow control methods, details are not described herein.Modules in the above-mentioned volume control device based on semaphore can be complete Portion or part are realized by software, hardware and combinations thereof.Above-mentioned each module can be embedded in the form of hardware or independently of calculating In processor in machine equipment, it can also be stored in a software form in the memory in computer equipment, in order to processor It calls and executes the corresponding operation of the above modules.
In one embodiment, a kind of computer equipment is provided, which can be server, internal junction Composition can be as shown in Figure 5.The computer equipment include by system bus connect processor, memory, network interface and Database.Wherein, the processor of the computer equipment is for providing calculating and control ability.The memory packet of the computer equipment Include non-volatile memory medium, built-in storage.The non-volatile memory medium is stored with operating system, computer program and data Library.The built-in storage provides environment for the operation of operating system and computer program in non-volatile memory medium.The calculating The database of machine equipment is for storing semaphore configuration data.The network interface of the computer equipment is used for logical with external terminal Cross network connection communication.To realize a kind of flow control methods based on semaphore when the computer program is executed by processor.
It will be understood by those skilled in the art that structure shown in Fig. 5, only part relevant to application scheme is tied The block diagram of structure does not constitute the restriction for the computer equipment being applied thereon to application scheme, specific computer equipment It may include perhaps combining certain components or with different component layouts than more or fewer components as shown in the figure.
In one embodiment, a kind of computer equipment, including memory and processor are provided, which is stored with Computer program, the processor perform the steps of acquisition waiting task when executing computer program, judge described to be processed The corresponding task type of task;Obtain the corresponding semaphore of the task type;Wherein, the license borrow is configured to describe The borrow attribute of the semaphore and it is borrowed attribute;If the license borrows configuration, the described attribute that borrows is to allow to borrow With then searching echo signal amount, the license of the echo signal amount, which borrows, is borrowed attribute to allow to be borrowed described in configuration With;It is obtained from the echo signal amount and borrows license, and borrow license is dispatched to the waiting task;Will it is described to Processing task is added in thread resources, until task processing is completed, discharges the borrow license.
In one embodiment, it is also performed the steps of when processor executes computer program and obtains semaphore license always Number;The initial license count of corresponding semaphore is determined according to the priority of the task type, the initial of all semaphores is permitted It is the sum of denumerable total no more than semaphore license;The corresponding semaphore is determined according to the priority of the task type License borrow configuration.
In one embodiment, if processor also performs the steps of the license borrow and matches when executing computer program Setting the described attribute that borrows is not allow to borrow, then by the waiting task labeled as obstruction clearance for holding;When being labeled as The task quantity for blocking clearance for holding is more than given threshold and/or the waiting time is more than given threshold, then adjusts corresponding described The initial license count of semaphore;The initial license count of the semaphore is updated to database.
In one embodiment, letter described in monitoring caching is also performed the steps of when processor executes computer program Number amount the first initial license count, when the described first initial license count cache-time reaches the preset cache time limit, from database It is middle to obtain the corresponding second initial license count of the semaphore;If the first initial license count is less than the described second initial license Number, then be adjusted to the described second initial license count for the described in caching first initial license count;If the first initial license count Greater than the described second initial license count, then the idle license count of the semaphore is obtained, if the free time license count is less than described Described in caching first initial license count is then adjusted to institute by the difference of the first initial license count and the described second initial license count State the difference of the first initial license count and the idle license count;The license of the semaphore release is recycled, until recycling is permitted The denumerable difference being equal between the first initial license count adjusted and the second initial license count, and then will be in caching The first initial license count is adjusted to the described second initial license count.
In one embodiment, it is also performed the steps of when processor executes computer program and generates the behaviour of semaphore first It notes down;First task data are extracted from the waiting task;The first operation note of semaphore association described first Task data;It is described that the waiting task is added in thread resources, until task processing is completed, discharges the borrow and permitted Can after, further includes: the second task data is extracted from task processing result;Generate the second operation note of semaphore, the letter Number two operation note of flow control is associated with second task data.
In one embodiment, a kind of computer readable storage medium is provided, computer program is stored thereon with, is calculated Machine program performs the steps of acquisition waiting task when being executed by processor, judge the corresponding task of the waiting task Type;Obtain the corresponding semaphore of the task type;Wherein, the license borrow is configured to describe borrowing for the semaphore With attribute and it is borrowed attribute;If the license borrows configuration, the described attribute that borrows is to allow to borrow, and searches target letter Number amount, it is to allow to be borrowed that the license of the echo signal amount, which borrows and is borrowed attribute described in configuration,;Believe from the target Number amount obtain borrow license, and by borrows permit be dispatched to the waiting task;The waiting task is added to In thread resources, until task processing is completed, the borrow license is discharged.
In one embodiment, it is also performed the steps of when computer program is executed by processor and obtains semaphore license Sum;Determine the initial license count of corresponding semaphore according to the priority of the task type, all semaphores it is initial The sum of license count is no more than semaphore license sum;The corresponding signal is determined according to the priority of the task type The license of amount borrows configuration, and whether the license borrows configuration and include whether to need to borrow and allow to borrow.
In one embodiment, it is borrowed if also performing the steps of the license when computer program is executed by processor The described attribute that borrows of configuration is not allow to borrow, then by the waiting task labeled as obstruction clearance for holding;Work as label It is more than given threshold and/or waiting time more than given threshold to block the task quantity of clearance for holding, then adjusts corresponding institute State the initial license count of semaphore;The initial license count of the semaphore is updated to database.
In one embodiment, it is also performed the steps of when computer program is executed by processor described in monitoring caching The initial license count of the first of semaphore, when the described first initial license count cache-time reaches the preset cache time limit, from data The corresponding second initial license count of the semaphore is obtained in library;Initially permitted if the first initial license count is less than described second It is denumerable, then the described in caching first initial license count is adjusted to the described second initial license count;If the described first initial license Number is greater than the described second initial license count, then obtains the idle license count of the semaphore, if the free time license count is less than institute The difference of the first initial license count Yu the described second initial license count is stated, then is adjusted to the described in caching first initial license count The difference of the first initial license count and the idle license count;The license of the semaphore release is recycled, until recycling License count is equal to the difference between the first initial license count adjusted and the second initial license count, and then will caching Described in the first initial license count be adjusted to the described second initial license count.
In one embodiment, it is also performed the steps of when computer program is executed by processor and generates semaphore first Operation note;First task data are extracted from the waiting task;First operation note of semaphore association described the One task data;It is described that the waiting task is added in thread resources, until task processing is completed, discharge the borrow After license, further includes: extract the second task data from task processing result;The second operation note of semaphore is generated, it is described The second operation note of semaphore is associated with second task data.
Those of ordinary skill in the art will appreciate that realizing all or part of the process in above-described embodiment method, being can be with Relevant hardware is instructed to complete by computer program, the computer program can be stored in a non-volatile computer In read/write memory medium, the computer program is when being executed, it may include such as the process of the embodiment of above-mentioned each method.Wherein, To any reference of memory, storage, database or other media used in each embodiment provided herein, Including non-volatile and/or volatile memory.Nonvolatile memory may include read-only memory (ROM), programming ROM (PROM), electrically programmable ROM (EPROM), electrically erasable ROM (EEPROM) or flash memory.Volatile memory may include Random access memory (RAM) or external cache.By way of illustration and not limitation, RAM is available in many forms, Such as static state RAM (SRAM), dynamic ram (DRAM), synchronous dram (SDRAM), double data rate sdram (DDRSDRAM), enhancing Type SDRAM (ESDRAM), synchronization link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic ram (DRDRAM) and memory bus dynamic ram (RDRAM) etc..
Each technical characteristic of above embodiments can be combined arbitrarily, for simplicity of description, not to above-described embodiment In each technical characteristic it is all possible combination be all described, as long as however, the combination of these technical characteristics be not present lance Shield all should be considered as described in this specification.
The several embodiments of the application above described embodiment only expresses, the description thereof is more specific and detailed, but simultaneously It cannot therefore be construed as limiting the scope of the patent.It should be pointed out that coming for those of ordinary skill in the art It says, without departing from the concept of this application, various modifications and improvements can be made, these belong to the protection of the application Range.Therefore, the scope of protection shall be subject to the appended claims for the application patent.

Claims (10)

1. a kind of flow control methods based on semaphore, which comprises
Waiting task is obtained, judges the corresponding task type of the waiting task;
Obtain the corresponding semaphore of the task type;
If the license of the semaphore has been expired, the license for obtaining the semaphore borrows configuration;Wherein, the license borrow is matched It sets the borrow attribute for describing the semaphore and is borrowed attribute;
If the license borrows configuration, the described attribute that borrows is to allow to borrow, and searches echo signal amount, the target letter Number amount license borrow configuration described in be borrowed attribute be allow to be borrowed;
It is obtained from the echo signal amount and borrows license, and borrow license is dispatched to the waiting task;
The waiting task is added in thread resources, until task processing is completed, discharges the borrow license.
2. the method according to claim 1, wherein it is described obtain the corresponding semaphore of the task type it Before, further includes:
Obtain semaphore license sum;
The initial license count of corresponding semaphore is determined according to the priority of the task type, the initial of all semaphores is permitted It is the sum of denumerable total no more than semaphore license;
Determine that the license of the corresponding semaphore borrows configuration according to the priority of the task type.
3. method according to claim 1 or 2, which is characterized in that if the license in the semaphore has been expired, obtain After taking the license of the semaphore to borrow configuration, further includes:
If the license borrows configuration, the described attribute that borrows is not allow to borrow, by the waiting task labeled as resistance Fill in clearance for holding;
When being more than given threshold and/or waiting time more than given threshold labeled as the task quantity for blocking clearance for holding, then adjust The initial license count of the whole corresponding semaphore;
The initial license count of the semaphore is updated to database.
4. according to the method described in claim 3, it is characterized in that, the method also includes:
First initial license count of semaphore described in monitoring caching, when the described first initial license count cache-time reaches default When caching the time limit, the corresponding second initial license count of the semaphore is obtained from database;
If the first initial license count is less than the described second initial license count, by the first initial license count tune described in caching Whole is the described second initial license count;
If the first initial license count is greater than the described second initial license count, the idle license count of the semaphore is obtained, If the free time license count is less than the difference of the described first initial license count and the described second initial license count, by institute in caching State the difference that the first initial license count is adjusted to the described first initial license count and the idle license count;
Recycle the license of semaphore release, until the license count of recycling be equal to the first initial license count adjusted with Difference between the second initial license count, and then the described in caching first initial license count is adjusted to described second initially License count.
5. the method according to claim 1, wherein it is described from the echo signal amount obtain borrow license, and Borrow license is dispatched to after the waiting task, further includes:
Generate the first operation note of semaphore;
First task data are extracted from the waiting task;
First operation note of semaphore is associated with the first task data;
It is described that the waiting task is added in thread resources, until task processing is completed, discharge the borrow license Afterwards, further includes:
The second task data is extracted from task processing result;
The second operation note of semaphore is generated, second operation note of semaphore is associated with second task data.
6. a kind of volume control device based on semaphore, which is characterized in that described device includes:
Task acquisition module judges the corresponding task type of the waiting task for obtaining waiting task;
Semaphore obtains module, for obtaining the corresponding semaphore of the task type;
License borrows configuration and obtains module, if the license for the semaphore has been expired, the license for obtaining the semaphore is borrowed With configuration;Wherein, the license borrows the borrow attribute for being configured to describe the semaphore and is borrowed attribute;
Permissions module is borrowed, if borrowing the described attribute that borrows of configuration for the license is to allow to borrow, searches target Semaphore, it is to allow to be borrowed that the license of the echo signal amount, which borrows and is borrowed attribute described in configuration,;
Task processing module, for from the echo signal amount obtain borrow license, and by borrows license be dispatched to described in The waiting task is added in thread resources by waiting task, until task processing is completed, is discharged the borrow and is permitted It can.
7. device according to claim 6, which is characterized in that described device further include:
Block permissions module, it, will be described if borrowing the described attribute that borrows of configuration for the license is not allow to borrow Waiting task is labeled as obstruction clearance for holding;
Initial license count adjusts module, for when the task quantity labeled as obstruction clearance for holding is more than given threshold and/or is waited It is more than given threshold to the time, then adjusts the initial license count of the corresponding semaphore;
Memory module, for the initial license count of the semaphore to be updated to database.
8. device according to claim 7, which is characterized in that described device further include:
Data cached update module, for monitoring the first initial license count of semaphore described in caching, when described first initial When license count cache-time reaches the preset cache time limit, the corresponding second initial license of the semaphore is obtained from database Number;If the first initial license count is less than the described second initial license count, by the first initial license count tune described in caching Whole is the described second initial license count;If the first initial license count be greater than the described second initial license count, obtain described in The idle license count of semaphore, if the free time license count is less than the described first initial license count and the described second initial license count Difference, then the described in caching first initial license count is adjusted to the described first initial license count and the idle license count Difference;The license for recycling the semaphore release, until the license count of recycling is equal to the first initial license count adjusted With the difference between the described second initial license count, and then the described in caching first initial license count is adjusted at the beginning of described second Beginning license count.
9. a kind of computer equipment, including memory and processor, the memory are stored with computer program, feature exists In the step of processor realizes any one of claims 1 to 5 the method when executing the computer program.
10. a kind of computer readable storage medium, is stored thereon with computer program, which is characterized in that the computer program The step of method described in any one of claims 1 to 5 is realized when being executed by processor.
CN201811544822.0A 2018-12-17 2018-12-17 Flow control methods, device, computer equipment and storage medium based on semaphore Pending CN109783230A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811544822.0A CN109783230A (en) 2018-12-17 2018-12-17 Flow control methods, device, computer equipment and storage medium based on semaphore

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811544822.0A CN109783230A (en) 2018-12-17 2018-12-17 Flow control methods, device, computer equipment and storage medium based on semaphore

Publications (1)

Publication Number Publication Date
CN109783230A true CN109783230A (en) 2019-05-21

Family

ID=66497130

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811544822.0A Pending CN109783230A (en) 2018-12-17 2018-12-17 Flow control methods, device, computer equipment and storage medium based on semaphore

Country Status (1)

Country Link
CN (1) CN109783230A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111625778A (en) * 2020-04-14 2020-09-04 华帝股份有限公司 Method and system for distributing and recovering software license
CN113568737A (en) * 2021-06-30 2021-10-29 北京达佳互联信息技术有限公司 Hardware resource allocation method and device
CN114461409A (en) * 2022-01-13 2022-05-10 北京特立信电子技术股份有限公司 Auxiliary analysis method, system and storage medium for abnormal blocking of mutual exclusion semaphore

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP0365728A1 (en) * 1988-10-28 1990-05-02 International Business Machines Corporation Resource access for a multiprocessing computer system
US20050086359A1 (en) * 2003-10-16 2005-04-21 International Business Machines Corporation Monitoring thread usage to dynamically control a thread pool
CN101069157A (en) * 2004-09-30 2007-11-07 茨特里克斯系统公司 A method and system for accessing resources
CN102591721A (en) * 2011-12-30 2012-07-18 北京新媒传信科技有限公司 Method and system for distributing thread execution task
CN106155803A (en) * 2015-04-07 2016-11-23 北大方正集团有限公司 A kind of thread pool sharing method based on semaphore and system
CN108846632A (en) * 2018-05-28 2018-11-20 浙江口碑网络技术有限公司 Thread processing method and device

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP0365728A1 (en) * 1988-10-28 1990-05-02 International Business Machines Corporation Resource access for a multiprocessing computer system
US20050086359A1 (en) * 2003-10-16 2005-04-21 International Business Machines Corporation Monitoring thread usage to dynamically control a thread pool
CN101069157A (en) * 2004-09-30 2007-11-07 茨特里克斯系统公司 A method and system for accessing resources
CN102591721A (en) * 2011-12-30 2012-07-18 北京新媒传信科技有限公司 Method and system for distributing thread execution task
CN106155803A (en) * 2015-04-07 2016-11-23 北大方正集团有限公司 A kind of thread pool sharing method based on semaphore and system
CN108846632A (en) * 2018-05-28 2018-11-20 浙江口碑网络技术有限公司 Thread processing method and device

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111625778A (en) * 2020-04-14 2020-09-04 华帝股份有限公司 Method and system for distributing and recovering software license
CN113568737A (en) * 2021-06-30 2021-10-29 北京达佳互联信息技术有限公司 Hardware resource allocation method and device
CN113568737B (en) * 2021-06-30 2024-03-26 北京达佳互联信息技术有限公司 Hardware resource allocation method and device
CN114461409A (en) * 2022-01-13 2022-05-10 北京特立信电子技术股份有限公司 Auxiliary analysis method, system and storage medium for abnormal blocking of mutual exclusion semaphore

Similar Documents

Publication Publication Date Title
EP3545435B1 (en) Database system and method for compiling serial and parallel database query execution plans
EP2843558B1 (en) Database management system, computer, and database management method
US20200219028A1 (en) Systems, methods, and media for distributing database queries across a metered virtual network
US8516488B1 (en) Adjusting a resource estimate in response to progress of execution of a request
CN109783230A (en) Flow control methods, device, computer equipment and storage medium based on semaphore
CN104462432B (en) Adaptive distributed computing method
EP2843560A1 (en) Database management system, computer, and database management method
US8966493B1 (en) Managing execution of multiple requests in a job using overall deadline for the job
CN109815087B (en) Task processing process monitoring method and device, computer equipment and storage medium
US8818988B1 (en) Database system having a regulator to provide feedback statistics to an optimizer
CN109271447A (en) Method of data synchronization, device, computer equipment and storage medium
DE102008050308A1 (en) Method and apparatus for memory access optimization
CN106569891A (en) Method and device for carrying out task scheduling in storage system
CN108846763A (en) Core protects request processing method, device, computer equipment and storage medium
CN110490594A (en) Business data processing method, device, computer equipment and storage medium
US20120191639A1 (en) Statistics forecast for range partitioned tables
CN112307049A (en) Method, device and equipment for separating read from write of database and readable storage medium
CN119179567A (en) Resource processing method, device, computer equipment and storage medium
CN112948099B (en) Task issuing flow method and device, computer equipment and storage medium
US10430400B1 (en) User controlled file synchronization limits
CN109325049A (en) Divide the asynchronous loading method of journey, device, terminal device and storage medium
US20090168092A1 (en) Job management and scheduling method for network system
US20110047553A1 (en) Apparatus and method for input/output processing of multi-thread
US20230018707A1 (en) Data rebalancing in data storage systems
US7805326B2 (en) System to resolve scheduling constraints

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
TA01 Transfer of patent application right

Effective date of registration: 20240902

Address after: 510000 Building 1, No. 106 Fengze East Road, Nansha District, Guangzhou City, Guangdong Province X1301-D010825 (Cluster Registration) (JM)

Applicant after: Guangzhou Chengyi Technology Consulting Co.,Ltd.

Country or region after: China

Address before: 518052 Room 201, building A, 1 front Bay Road, Shenzhen Qianhai cooperation zone, Shenzhen, Guangdong

Applicant before: PING AN PUHUI ENTERPRISE MANAGEMENT Co.,Ltd.

Country or region before: China

TA01 Transfer of patent application right
AD01 Patent right deemed abandoned

Effective date of abandoning: 20241122

AD01 Patent right deemed abandoned