CN106775974B - Method for realizing distributed priority queuing lock - Google Patents

Method for realizing distributed priority queuing lock Download PDF

Info

Publication number
CN106775974B
CN106775974B CN201611118040.1A CN201611118040A CN106775974B CN 106775974 B CN106775974 B CN 106775974B CN 201611118040 A CN201611118040 A CN 201611118040A CN 106775974 B CN106775974 B CN 106775974B
Authority
CN
China
Prior art keywords
lock
priority
request
queue
executing
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.)
Active
Application number
CN201611118040.1A
Other languages
Chinese (zh)
Other versions
CN106775974A (en
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.)
G Cloud Technology Co Ltd
Original Assignee
G Cloud 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 G Cloud Technology Co Ltd filed Critical G Cloud Technology Co Ltd
Priority to CN201611118040.1A priority Critical patent/CN106775974B/en
Publication of CN106775974A publication Critical patent/CN106775974A/en
Application granted granted Critical
Publication of CN106775974B publication Critical patent/CN106775974B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4812Task transfer initiation or dispatching by interrupt, e.g. masked
    • G06F9/4831Task transfer initiation or dispatching by interrupt, e.g. masked with variable priority
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/48Indexing scheme relating to G06F9/48
    • G06F2209/484Precedence

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Multi Processors (AREA)

Abstract

the invention relates to the technical field of distributed concurrency and JAVA development, in particular to a method for realizing a distributed priority queuing lock. The invention firstly sets a priority for the request which needs to execute the operation; and then starting to acquire the lock, judging whether the mutual exclusion field in the database is empty, if not, failing to acquire the lock, otherwise, judging whether a waiting object exists in the queue or not, and whether the first bit in the queue is the self or not, if so, setting the mutual exclusion field, and otherwise, failing to acquire the lock. If the setting of the mutual exclusion field is successful, the lock is successfully acquired, and if the request processing is completed, the mutual exclusion field is released; and when the lock acquisition fails, if the request is not in the queue, the priority is raised, if the priority is raised to a preset value, the request is added into the queue, and the steps are repeated until the lock acquisition is successful or the time is exceeded. The invention solves the problems that the request can not obtain the lock, the lock obtaining efficiency is not high, and the priority is not flexible, and can be used in the distributed environment with large concurrency and needing to process the specific request preferentially.

Description

method for realizing distributed priority queuing lock
Technical Field
The invention relates to the technical field of distributed concurrency and JAVA development, in particular to a method for realizing a distributed priority queuing lock.
background
The method of using lock is generally used when processing data exception caused by concurrent request of system, and in distributed system, it is generally realized by memcached or redis distributed lock. However, when the concurrency is larger and the request situation is more and more complicated, the existing scheme has the following problems:
firstly, the solution of the existing distributed lock is preemptive, and who acquires the lock first and who handles the lock first. In addition, when the concurrency is large, a request can be processed for a long time due to the fact that the lock cannot be seized, and even the request cannot be processed due to the fact that the lock cannot be seized all the time;
secondly, the problem is solved by a queuing lock commonly used on the existing single server, but the queuing lock is not realized on a distributed system, so that the problem cannot be solved by the distributed system, and meanwhile, if the queuing lock is directly used, the lock acquisition efficiency is low because the lock must be acquired in sequence;
thirdly, the existing lock scheme cannot set the priority, so that the flexibility is low, the requests needing to be processed preferentially cannot be processed preferentially, and the requests can only be preempted or queued together;
in order to ensure the lock acquisition efficiency, prevent the problem of overlong lock acquisition time and improve flexibility, a method for continuously increasing the priority and customizing the priority configuration after the lock is unsuccessfully seized in the lock acquisition of the distributed system is required.
disclosure of Invention
The technical problem to be solved by the invention is to provide a method for realizing a distributed priority queuing lock, which can ensure the lock obtaining efficiency of the concurrent request in a high-concurrency environment of a distributed system, solve the problem that the lock can not be obtained by the request and provide a more flexible priority to meet various special requests.
the technical scheme for solving the technical problems is as follows:
the method comprises the following steps:
Step 1: setting a priority and a priority strategy for each request, and starting to acquire a lock;
step 2: judging whether the exclusive field of the database is empty, if so, executing the step 3, and if not, executing the step 6;
and step 3: judging whether the queue has a waiting request, if the queue has no waiting request, executing the step 9, and if the queue has a waiting request, executing the step 4;
And 4, step 4: judging whether the request is in the queue, if so, executing step 5; otherwise, executing step 6;
And 5: judging whether the request is at the first bit, if so, executing step 9; otherwise, after waiting for a period of time, re-executing the step 2 and continuing to acquire the lock;
step 6: raising the priority policy of the request according to the priority policy;
And 7: if the priority reaches the threshold, executing the step 8 if the priority reaches the preset priority threshold, otherwise, waiting for a period of time, executing the step 2 again, and continuing to acquire the lock;
And 8: putting the request into a queue, re-executing the step 2, and continuously acquiring the lock;
and step 9: setting a mutually exclusive field of the database, executing the step 10 if the setting is successful, and executing the step 6 if the setting is failed;
Step 10: the request is processed and the database mutual exclusion field is cleared and the process ends.
The priority strategy is to set the step length of priority increase after the failure of the mutual exclusion field or calculate a new priority according to a formula;
the mutually exclusive field of the database means that the field can only be set and updated by one request, and once one request is successfully operated, other requests cannot be successfully operated.
the queuing queue is a queue of requests in which the requests get the lock in order, and the system will prioritize the requests in the queue.
The threshold is a preset priority value, and when the priority of the request reaches the value, the request can enter the queuing queue.
The lock acquisition means that a token is acquired, and the lock acquisition can be executed only when the token is taken, so that data errors caused by concurrent processing of requests are avoided.
The invention develops a queuing lock method capable of flexibly setting priority by combining the advantages of the traditional distributed lock in a distributed system, so that the distributed system can simultaneously request for maintaining the lock acquisition efficiency, avoid the problem of long-time waiting of individual requests, simultaneously can promote the priority of the individual requests and meet special requirements. By solving the problems, the invention can improve the request experience of the distributed system, improve the satisfaction degree of users, optimize the system, avoid the request blockage and reduce the operation efficiency of the system.
Drawings
The invention is further described below with reference to the accompanying drawings:
FIG. 1 is a flow chart of the method of the present invention.
Detailed Description
As shown in FIG. 1, the process of the present invention is as follows:
main flow:
releasing the lock:
queuing to obtain the lock:
updating the priority and judging whether to join the queue:
Setting the priority:

Claims (7)

1. A method for realizing distributed priority queuing lock is characterized in that: the method comprises the following steps:
Step 1: setting a priority and a priority strategy for each request, and starting to acquire a lock;
step 2: judging whether the exclusive field of the database is empty, if so, executing the step 3, and if not, executing the step 6;
And step 3: judging whether the queue has a waiting request, if the queue has no waiting request, executing the step 9, and if the queue has a waiting request, executing the step 4;
And 4, step 4: judging whether the request is in the queue, if so, executing step 5; otherwise, executing step 6;
And 5: judging whether the request is at the first bit, if so, executing step 9; otherwise, after waiting for a period of time, re-executing the step 2 and continuing to acquire the lock;
step 6: raising the priority policy of the request according to the priority policy;
And 7: if the priority reaches the threshold, executing the step 8 if the priority reaches the preset priority threshold, otherwise, waiting for a period of time, executing the step 2 again, and continuing to acquire the lock;
and 8: putting the request into a queue, re-executing the step 2, and continuously acquiring the lock;
And step 9: setting a mutually exclusive field of the database, executing the step 10 if the setting is successful, and executing the step 6 if the setting is failed;
step 10: the request is processed and the database mutual exclusion field is cleared and the process ends.
2. the method of claim 1 for implementing a distributed priority queuing lock, wherein: the priority strategy is to set the step length of priority increase after the failure of the mutual exclusion field or calculate a new priority according to a formula;
the mutually exclusive field of the database means that the field can only be set and updated by one request, and once one request is successfully operated, other requests cannot be successfully operated.
3. the method of claim 1 for implementing a distributed priority queuing lock, wherein:
The queuing queue is a queue of requests in which the requests get the lock in order, and the system will prioritize the requests in the queue.
4. The method of claim 2 for implementing a distributed priority queuing lock, wherein:
the queuing queue is a queue of requests in which the requests get the lock in order, and the system will prioritize the requests in the queue.
5. A method for implementing a distributed priority queuing lock according to any of claims 1 to 4 wherein:
the threshold is a preset priority value, and when the priority of the request reaches the value, the request enters the queuing queue.
6. A method for implementing a distributed priority queuing lock according to any of claims 1 to 4 wherein: the lock acquisition means that a token is acquired, and the lock acquisition can be executed only when the token is taken, so that data errors caused by concurrent processing of requests are avoided.
7. the method of claim 5 for implementing a distributed priority queuing lock, wherein: the lock acquisition means that a token is acquired, and the lock acquisition can be executed only when the token is taken, so that data errors caused by concurrent processing of requests are avoided.
CN201611118040.1A 2016-12-07 2016-12-07 Method for realizing distributed priority queuing lock Active CN106775974B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201611118040.1A CN106775974B (en) 2016-12-07 2016-12-07 Method for realizing distributed priority queuing lock

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201611118040.1A CN106775974B (en) 2016-12-07 2016-12-07 Method for realizing distributed priority queuing lock

Publications (2)

Publication Number Publication Date
CN106775974A CN106775974A (en) 2017-05-31
CN106775974B true CN106775974B (en) 2019-12-10

Family

ID=58881199

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201611118040.1A Active CN106775974B (en) 2016-12-07 2016-12-07 Method for realizing distributed priority queuing lock

Country Status (1)

Country Link
CN (1) CN106775974B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107832159A (en) * 2017-11-10 2018-03-23 郑州云海信息技术有限公司 Manage the method and computer-readable recording medium of distributed lock
CN108268214B (en) * 2017-12-15 2021-04-20 中国航空工业集团公司西安飞行自动控制研究所 Method for operating non-volatile memory by multi-thread fast cycle serial peripheral
CN114629714B (en) * 2022-03-29 2023-08-04 济南大学 Malicious program behavior processing method and system for mutual reinforcement of honeypot and sandbox
CN114928563A (en) * 2022-05-27 2022-08-19 江苏苏宁银行股份有限公司 Distributed channel automatic switching method and storage medium

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104077181A (en) * 2014-06-26 2014-10-01 国电南瑞科技股份有限公司 Status consistent maintaining method applicable to distributed task management system
CN104331327A (en) * 2014-12-02 2015-02-04 山东乾云启创信息科技有限公司 Optimization method and optimization system for task scheduling in large-scale virtualization environment
CN104702655A (en) * 2014-03-21 2015-06-10 杭州海康威视***技术有限公司 Cloud storage resource distribution method and system
CN104750562A (en) * 2013-12-30 2015-07-01 ***股份有限公司 Lock processing system and method in distributed system
CN105339897A (en) * 2013-05-31 2016-02-17 微软技术许可有限责任公司 Efficient priority-aware thread scheduling
CN105893120A (en) * 2016-04-21 2016-08-24 北京京东尚科信息技术有限公司 Acquisition method and device for thread synchronization resources
WO2016160416A1 (en) * 2015-04-01 2016-10-06 Ab Inito Technology Llc Processing database transactions in a distributed computing system

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105339897A (en) * 2013-05-31 2016-02-17 微软技术许可有限责任公司 Efficient priority-aware thread scheduling
CN104750562A (en) * 2013-12-30 2015-07-01 ***股份有限公司 Lock processing system and method in distributed system
CN104702655A (en) * 2014-03-21 2015-06-10 杭州海康威视***技术有限公司 Cloud storage resource distribution method and system
CN104077181A (en) * 2014-06-26 2014-10-01 国电南瑞科技股份有限公司 Status consistent maintaining method applicable to distributed task management system
CN104331327A (en) * 2014-12-02 2015-02-04 山东乾云启创信息科技有限公司 Optimization method and optimization system for task scheduling in large-scale virtualization environment
WO2016160416A1 (en) * 2015-04-01 2016-10-06 Ab Inito Technology Llc Processing database transactions in a distributed computing system
CN105893120A (en) * 2016-04-21 2016-08-24 北京京东尚科信息技术有限公司 Acquisition method and device for thread synchronization resources

Also Published As

Publication number Publication date
CN106775974A (en) 2017-05-31

Similar Documents

Publication Publication Date Title
CN106775974B (en) Method for realizing distributed priority queuing lock
US20180375783A1 (en) Retry handling in messaging queues
AU2017409830B2 (en) Multi-task scheduling method and system, application server and computer-readable storage medium
CN108023908B (en) Data updating method, device and system
CN106657170B (en) Data synchronization method and device
US20170141968A1 (en) Updating Electronic Devices Using a Push Model
CN107145396B (en) Distributed lock implementation method and device
WO2018121696A1 (en) Multi-thread processing method and device, and server
CN103997498B (en) Distributed lock service implementation method and component
JP2017529628A5 (en)
CN106557470B (en) Data extraction method and device
DE102012210420A1 (en) A native program procedure for applying the same transaction context when invoked by the primary program running in a separate environment
CN107203560B (en) Database, multi-database operation transaction consistency ensuring method and system
JP2017520845A5 (en)
US9380001B2 (en) Deploying and modifying a service-oriented architecture deployment environment model
CN107707671A (en) A kind of method of the unified configuration of MyCat clusters
CN106033422A (en) A database operation control method, device and system
US8600990B2 (en) Interacting methods of data extraction
US7958083B2 (en) Interacting methods of data summarization
WO2017014752A1 (en) Implementation of load acquire/store release instructions using load/store operation with dmb operation
WO2012079351A1 (en) Multithread data synchronization method and device
CN103677959B (en) A kind of virtual machine cluster migration method and system based on multicast
CN107368498B (en) Method and device for optimizing lock waiting timeout of MySQ L pessimistic lock
RU2010149275A (en) RESTORATION OF THE RESOURCE MANAGEMENT OF THE PROCESSING, WHICH EXECUTES THE EXTERNAL CONTEXT OF EXECUTION
CN104021196B (en) I/O multiplexing method for System V message queue

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
CB02 Change of applicant information
CB02 Change of applicant information

Address after: 523808 19th Floor, Cloud Computing Center, Chinese Academy of Sciences, No. 1 Kehui Road, Songshan Lake Hi-tech Industrial Development Zone, Dongguan City, Guangdong Province

Applicant after: G-Cloud Technology Co., Ltd.

Address before: 523808 Guangdong province Dongguan City Songshan Lake Science and Technology Industrial Park Building No. 14 Keyuan pine

Applicant before: G-Cloud Technology Co., Ltd.

GR01 Patent grant
GR01 Patent grant