This application is related to the following patent applications, each of which is hereby incorporated by reference in its entirety:
U.S. Patent Application titled “SYSTEM AND METHOD FOR SUPPORTING COOPERATIVE CONCURRENCY IN A MIDDLEWARE MACHINE ENVIRONMENT”, Application Ser. No. 13/781,475, filed on Feb. 28, 2013, now U.S. Pat. No. 9,378,045;
U.S. Patent Application titled “SYSTEM AND METHOD FOR USING A SEQUENCER IN A CONCURRENT PRIORITY QUEUE”, Application Ser. No. 13/781,493, filed on Feb. 28, 2013, now U.S. Pat. No. 9,110,715;
U.S. Patent Application titled “SYSTEM AND METHOD FOR TRANSFORMING A QUEUE FROM NON-BLOCKING TO BLOCKING”, Application Ser. No. 13/781,500, filed on Feb. 28, 2013; and
U.S. Patent Application titled “MULTI-LANE CONCURRENT BAG FOR FACILITATING INTER-THREAD COMMUNICATION”, Application Ser. No. 13/241,015, filed Sep. 22, 2011, now U.S. Pat. No. 8,689,237, issued Apr. 1, 2014.
A portion of the disclosure of this patent document contains material which is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document or the patent disclosure, as it appears in the Patent and Trademark Office patent file or records, but otherwise reserves all copyright rights whatsoever.
The present invention is generally related to computer systems, and is particularly related to queue processing in a computing environment.
Within any large organization, over the span of many years, the organization often finds itself with a sprawling IT infrastructure that encompasses a variety of different computer hardware, operating systems, and application software. Although each individual component of such infrastructure might itself be well-engineered and well-maintained, when attempts are made to interconnect such components, or to share common resources, it is often a difficult administrative task. In recent years, organizations have turned their attention to technologies such as virtualization and centralized storage, and even more recently cloud computing, which can provide the basis for a shared infrastructure. However, there are few all-in-one platforms that are particularly suited for use in such environments. These are the general areas that embodiments of the invention are intended to address.
Described herein are systems and methods that can support queue processing in a computing environment. A lazy sorting priority queue in a concurrent system can include a priority queue and one or more buffers. The one or more buffers, which can be first-in first-out (FIFO) buffers, operate to store one or more requests received from one or more producers, and move at least one message to the priority queue when no consumer is waiting for processing a request. Furthermore, the priority queue operates to prioritize one or more incoming requests received from the one or more buffers, and allows one or more consumers to pick up the requests based on priority.
Described herein are systems and methods that can support queue processing in a computing environment.
Lazy Sorting Priority Queue
Priority queues can be used for prioritizing the elements in a concurrent system, which may be received in a total order, based on different application-specific criteria. For example, the priority queues can be used to prioritize service requests that are received at a messaging system, and to re-arrange these enqueued service requests into a different order.
Furthermore, the performance of the priority queue may contribute significantly toward the overall performance of the concurrent system, even though the priority queue can be designed and implemented using different approaches. For example, the prioritization of the enqueued elements within a priority queue may require a complete sorting of all the enqueued elements, which is an operation with at least O(log) complexity. Additionally, the system may need to use a complex data structure for maintaining the various requests in a prioritized order in a concurrent priority queue.
In accordance with an embodiment of the invention, the system can reduce the overhead (e.g. from sorting) by taking into account contention pressure from various consumers that are ready to dequeue the requests.
In accordance with an embodiment of the invention, multiple producers 110 and multiple consumers 120 can access the priority queue 101 and the FIFO queue 102 concurrently. For example, the producers 110 can be muxer threads unmarshalling requests from network connections, and the consumers 120 can be worker threads picking up requests from the priority queue 101.
When the contention level is low in the system, the underlying priority queue 101 can sort the requests waiting in the priority queue 101 (with a logarithmic cost) in order to ensure that the request with the highest priority in the priority queue 101 can have the shortest waiting time. Thus, when the next consumer 120, or worker thread, is allowed to pick up a unit of work, it can pick up the unit with the highest priority. Here, the consumers 120, or the worker threads, may take arbitrary time to process the requests, and the requests in the priority queue 101 may be considered waiting only after the last consumer 120 leaves the dequeue entry point.
Additionally, the consumer 120 can retrieve a request from the priority queue 101 by calling a poll( )method. As shown in
Also, a producer 110 can place an element in the FIFO queue first. As shown in
In accordance with an embodiment of the invention, the system allows the producer 110 to select a FIFO buffer from the FIFO queue 102. Furthermore, the system allows the request to be moved from a selected FIFO buffer 111-113 to the priority queue using a put( )method call.
Here, due to the need for sorting the elements in the priority queue 101, an operation based on ether the put( )method or the poll( )method may have a logarithmic cost. Thus, the system can reduce the cost for sorting the elements in a priority queue by reducing the number of calls to these methods under contention.
In order to improve the efficiency of the concurrent system, both the producer 110 and the consumer 120 may attempt to move one or more elements to the priority queue 101, when no consumer is waiting for processing a request in the priority queue 101 (i.e. when there is no contention).
On the other hand, when the contention level is high, i.e. when one or more consumers 120 are ready to extract units of work from the priority queue 101, the priority of the requests waiting in the priority queue 101 to be processed may be higher than the priority of the requests after they are picked up. Thus, the system allows the producers 110 to be blocked when attempting to add one or more elements to the priority queue 101, and allows the elements to remain unsorted in the FIFO queue 102, as long as there are consumers contending for the sequencer.
Subsequently, the units of work can be moved from the FIFO queue 102 to the priority queue 101, a later time when a future producer and/or a future consumer finds no contention, or until the units of work can be extracted by consumers 120 in the FIFO order, if the contention remains high.
Concurrent Thread Operations
Furthermore, a producer 310 can place a request in the FIFO buffer 302. Then, the request can be moved to the priority queue 301 using a put( )method call. Additionally, a consumer 320 can place a poll( )method call to retrieve a request from the priority queue 301. In order to improve the efficiency of the concurrent system 300, each of the producer 310 and consumer 320 may attempt to move one or more elements from the FIFO buffer 302 to the priority queue 301, e.g. by calling an addLoop( )method.
As shown in
In other words, the sequencer 311 permits a thread (either the producer 310 or the consumer 320) to have an exclusive access to the priority queue 301, when there are no threads calling the poll( )method and the addLoop( )method. Then, the thread can move one or more elements from the FIFO buffer 302 to the priority queue 301, e.g. using a priorityQueue.put( )method call.
In accordance with an embodiment of the invention, the system ensures that the elements (or units of work) can be moved lazily, or opportunistically, when there is no contention from the consumers 320. On the other hand, the consumers 320 can take precedence once they arrive, and the consumers 320 are allowed to extract elements from the FIFO buffer 302 without having all known requests sorted.
Thus, the concurrent system can behave similarly to a priority queue 301 with a lock biased towards the consumers 320. The system makes sure that the priority queue 301 is short and the cost of adding and removing elements from the priority queue 301 is minimized. For example, at high contention levels, the priority queue 301 becomes completely empty, while the requests in the concurrent system 300 may be processed in the FIFO order.
At step 601, which is at the beginning of each iteration in the loop, the thread can check whether the FIFO buffers are empty. If the FIFO buffers are empty, at step 602, the system determines that the thread has nothing to do. Accordingly, at step 605, the thread returns and terminates the loop. On the other hand, at step 603, if the FIFO buffers are not empty, the thread can check whether there are consumers waiting, e.g. by checking the state of the consumer sequencer and the consumer ticketing system (i.e., if acquired consumer ticket>consumer sequencer current ticket).
At step 604, the system can determine that there are consumers waiting. Accordingly, at step 605, the thread returns and terminates the loop. This guarantees that producers step out of the way under high contention. In effect, the queue lock is biased towards consumers, which permits the complex structure of priority queue to be emptied quickly and permits the subsequent add operations to be performed quickly or to be completely eliminated.
Then, at step 606, the thread can claim one consumer ticket. This is made possible only if no consumers have arrived and are ready to perform dequeue operations. Furthermore, at step 607, the thread can move the first request from the FIFO buffer into the priority queue, which may have amortized logarithmic cost.
Finally, at step 608, the thread can advance the FIFO buffer sequencer, which allows the concurrent producers to reuse the emptied buffer cell, before finishing the iteration in the loop and proceeding to the next iteration by returning to step 601.
An Exemplary Implementation
For example, the FIFO buffer 702 can be implemented using an array of Objects, q, and two sequencers, such as a readerS sequencer 722 and a writerS sequencer 721. Additionally, the priority queue 701 can be supported using a popperS sequencer 711.
As shown in
Additionally, the consumer 720 can acquire a ticket, p_t 713, from the ticketing system, popper_tkt 712, e.g. using an atomic increment popper_tkt.getAndIncrement( )method call, and await on the popperS sequencer 711, e.g. via the popperS.await( )function call. Then, after removing an element from the priority queue 701 or the FIFO buffer 702, the consumer 720 may attempt to move one or more elements from the FIFO buffer 702 to the Priority Queue 701.
As shown in
First, a thread, either the producer 710 or the consumer 720, can check whether the popperS sequencer 711 permits the thread to move one or more elements from the FIFO buffer 702 to the priority queue 701. For example, the thread can compare the value of the acquired ticket, p_t 713, with the value of the current ticket, popper_tkt 712.
Here, the popperS sequencer 711 may only allow a thread to move one or more elements from the FIFO buffer 702 to the priority queue 701, when there are no threads calling the poll( )method and the add Loop( )method. Additionally, the last thread that exits these methods can advance the popperS sequencer 711.
Otherwise, the thread, which corresponds to the current ticket, popper_tkt 712, is behind an existing thread in a poll( )method or an addLoop( )method. In such a case, there is no need to move elements from the FIFO buffer 702 to the priority queue 701, since doing so may either interfere with a consumer 720 extracting an element, or interfere with a thread that has already started moving elements from the FIFO buffer 702 to the priority queue 701.
Accordingly, the popperS sequencer 711 may not allow a thread to move one or more elements from the FIFO buffer 702 to the priority queue 701, when there is contention (i.e. when one or more consumers 720 are ready to extract units of work from the priority queue 701). Thus, the units of work in the FIFO buffer 702 can remain unsorted until a later thread, either a producer 710 or a consumer 720, finds a suitable time with no contention, or until the units of work are extracted by the consumers 720, if the contention remains high.
Furthermore, if popperS sequencer 711 permits progress for the current ticket, popper_tkt 712, the thread may attempt to atomically acquire this ticket, e.g. using a popper_tkt.compareAndSet(p_t, p_t+1) function call. This may succeed only if there is no thread attempting to acquire the same ticket in a concurrent call to poll( )or addLoop( )
On the other hand, when there are one or more concurrent threads, the system can guarantee that only one of the concurrent threads can successfully acquire the ticket. For example, this guarantee can be implemented via the atomic compareAndSet operation and the atomic getAndIncrement operation used by the addLoop( )method call and the poll( )ethod call, respectively. Thus, if the thread in a addLoop( )method call fails to acquire the ticket, there is no need to move elements, since, otherwise, the thread may either interfere with a consumer 720 extracting an element, or interfere with a thread that has already been moving elements from the FIFO buffer 702 to the priority queue 701.
In accordance with an embodiment of the invention, after successfully acquiring the ticket, the thread can execute a loop, in which the thread can move one unit of work at a time from the FIFO queue 702 to the priority queue 701. For example, since the thread can have exclusive access to the priority queue 701 (e.g. having progressed past popperS.await( )method call with a successfully acquired ticket), the thread can add the removed element to priority queue 701 using a priorityQueue.put( )method call.
Then, the thread can proceed to the next iteration of the loop. The loop continues until one or more consumers arrives at poll( )and waits to extract elements from the queue. The loop also terminates as soon as the FIFO buffer 702 becomes empty. After the loop terminates, the thread can advance the popperS sequencer 711 to permit the consumer 720 who has been waiting, or a future consumer 720, to proceed past popperS.await( )
Additionally, at the end of each iteration (or at the beginning of the next iteration), the thread can monitor the state of the ticketing system, popper_tkt 711, to detect a contender. The contender may only be a customer thread 720 in a poll( )method call, which can acquire a ticket unconditionally. Here, the thread entering the addLoop( )method call may detect that popperS sequencer 711 does not permit progress, and decide to exit without attempting to acquire a ticket.
For example, the detection of contention can be done by comparing the value of a successfully acquired ticket, p_t 713, with the value of a current ticket, popper_tkt 712. If popper_tkt >p_t, then the other thread must have incremented the current ticket, popper_tkt 711. Furthermore, the other thread can be waiting for proceeding past popperS.await( ) which is a blocking call to popperS sequencer 711 that force the other thread to wait until the ticket acquired by the thread is permitted to proceed. On the other hand, if popper_tkt==p_t, then no contenders have arrived, and the thread can move one unit of work fro FIFO queue 702 into priority queue 701 if FIFO queue 702 is not empty.
Here, in order to determine whether the FIFO queue 702 is empty, the thread can compare the acquired ticket, adder_r 724, with the current ticket, adder_tkt 723. If adder_tkt adder_r, then the FIFO queue must be empty. Otherwise, the FIFO queue 702 is not empty when adder_tkt>adder_r. Thus, the thread can move one element from the FIFO buffer 702 to the priority queue 701.
Furthermore, the thread can wait on the readerS sequencer 722, e.g. using a readerS.await(adder_r) method call. Then, the thread can proceed to work out the index of the array for the unit of work that is corresponding to the adder_r ticket 724. Additionally, the thread can advance the writers sequencer 721, e.g. using releaseWriters(adder_r), in order to permit concurrent producers 710 to use the array cell that was recently emptied.
The present invention may be conveniently implemented using one or more conventional general purpose or specialized digital computer, computing device, machine, or microprocessor, including one or more processors, memory and/or computer readable storage media programmed according to the teachings of the present disclosure. Appropriate software coding can readily be prepared by skilled programmers based on the teachings of the present disclosure, as will be apparent to those skilled in the software art.
In some embodiments, the present invention includes a computer program product which is a storage medium or computer readable medium (media) having instructions stored thereon/in which can be used to program a computer to perform any of the processes of the present invention. The storage medium can include, but is not limited to, any type of disk including floppy disks, optical discs, DVD, CD-ROMs, microdrive, and magneto-optical disks, ROMs, RAMs, EPROMs, EEPROMs, DRAMs, VRAMs, flash memory devices, magnetic or optical cards, nanosystems (including molecular memory ICs), or any type of media or device suitable for storing instructions and/or data.
The foregoing description of the present invention has been provided for the purposes of illustration and description. It is not intended to be exhaustive or to limit the invention to the precise forms disclosed. Many modifications and variations will be apparent to the practitioner skilled in the art. The modification and variation include any relevant combination of the described features. The embodiments were chosen and described in order to best explain the principles of the invention and its practical application, thereby enabling others skilled in the art to understand the invention for various embodiments and with various modifications that are suited to the particular use contemplated. It is intended that the scope of the invention be defined by the following claims and their equivalence.
Number | Name | Date | Kind |
---|---|---|---|
5109384 | Tseung | Apr 1992 | A |
6449614 | Marcotte | Sep 2002 | B1 |
6874144 | Kush | Mar 2005 | B1 |
6895590 | Yadav | May 2005 | B2 |
6938085 | Belkin et al. | Aug 2005 | B1 |
7046676 | Goetzinger et al. | May 2006 | B2 |
7554993 | Modi et al. | Jun 2009 | B2 |
7685391 | Cholleti et al. | Mar 2010 | B1 |
7761617 | Seigneret et al. | Jul 2010 | B2 |
7876677 | Cheshire | Jan 2011 | B2 |
7991904 | Melnyk et al. | Aug 2011 | B2 |
8130776 | Sundararajan | Mar 2012 | B1 |
8131860 | Wong et al. | Mar 2012 | B1 |
8255914 | Joyce et al. | Aug 2012 | B1 |
8347302 | Vincent et al. | Jan 2013 | B1 |
8504691 | Tobler et al. | Aug 2013 | B1 |
8539486 | Cain et al. | Sep 2013 | B2 |
8578033 | Mallart | Nov 2013 | B2 |
8850441 | Allen | Sep 2014 | B2 |
8863136 | Allen | Oct 2014 | B2 |
8918791 | Chudgar et al. | Dec 2014 | B1 |
8930584 | Otenko et al. | Jan 2015 | B2 |
20010034753 | Hildebrand | Oct 2001 | A1 |
20020114338 | Craig | Aug 2002 | A1 |
20020143847 | Smith | Oct 2002 | A1 |
20020174136 | Cameron et al. | Nov 2002 | A1 |
20030014480 | Pullara et al. | Jan 2003 | A1 |
20030053469 | Wentink | Mar 2003 | A1 |
20030078958 | Pace et al. | Apr 2003 | A1 |
20030110232 | Chen | Jun 2003 | A1 |
20030120822 | Langrind et al. | Jun 2003 | A1 |
20040177126 | Maine | Sep 2004 | A1 |
20040205771 | Sudarshan et al. | Oct 2004 | A1 |
20050021354 | Brendle et al. | Jan 2005 | A1 |
20050038801 | Colrain et al. | Feb 2005 | A1 |
20050094577 | Ashwood-Smith | May 2005 | A1 |
20050102412 | Hirsimaki | May 2005 | A1 |
20050262215 | Kirov et al. | Nov 2005 | A1 |
20050283577 | Sivaram et al. | Dec 2005 | A1 |
20060015600 | Piper | Jan 2006 | A1 |
20060015700 | Burka | Jan 2006 | A1 |
20060031846 | Jacobs et al. | Feb 2006 | A1 |
20060143525 | Kilian | Jun 2006 | A1 |
20060176884 | Fair | Aug 2006 | A1 |
20060209899 | Cucchi et al. | Sep 2006 | A1 |
20060230411 | Richter et al. | Oct 2006 | A1 |
20060294417 | Awasthi et al. | Dec 2006 | A1 |
20070118601 | Pacheco | May 2007 | A1 |
20070156869 | Galchev et al. | Jul 2007 | A1 |
20070198684 | Mizushima | Aug 2007 | A1 |
20070203944 | Batra et al. | Aug 2007 | A1 |
20070263650 | Subramania et al. | Nov 2007 | A1 |
20080044141 | Willis et al. | Feb 2008 | A1 |
20080098458 | Smith | Apr 2008 | A2 |
20080140844 | Halpern | Jun 2008 | A1 |
20080286741 | Call | Nov 2008 | A1 |
20090034537 | Colrain et al. | Feb 2009 | A1 |
20090150647 | Mejdrich et al. | Jun 2009 | A1 |
20090172636 | Griffith | Jul 2009 | A1 |
20090182642 | Sundaresan | Jul 2009 | A1 |
20090327471 | Astete et al. | Dec 2009 | A1 |
20100082855 | Accapadi | Apr 2010 | A1 |
20100100889 | Labrie et al. | Apr 2010 | A1 |
20100198920 | Wong et al. | Aug 2010 | A1 |
20100199259 | Quinn | Aug 2010 | A1 |
20100278190 | Yip et al. | Nov 2010 | A1 |
20110029812 | Lu et al. | Feb 2011 | A1 |
20110055510 | Fritz et al. | Mar 2011 | A1 |
20110071981 | Ghosh et al. | Mar 2011 | A1 |
20110119673 | Bloch et al. | May 2011 | A1 |
20110153992 | Srinivas et al. | Jun 2011 | A1 |
20110161457 | Sentinelli | Jun 2011 | A1 |
20110231702 | Allen et al. | Sep 2011 | A1 |
20120023557 | Bevan | Jan 2012 | A1 |
20120054472 | Altman et al. | Mar 2012 | A1 |
20120066400 | Reynolds | Mar 2012 | A1 |
20120066460 | Bihani | Mar 2012 | A1 |
20120158684 | Lowenstein et al. | Jun 2012 | A1 |
20120218891 | Sundararajan | Aug 2012 | A1 |
20120239730 | Revanuru | Sep 2012 | A1 |
20130004002 | Duchscher | Jan 2013 | A1 |
20130132970 | Miyoshi | May 2013 | A1 |
20130145373 | Noro | Jun 2013 | A1 |
20130304848 | Lyle et al. | Nov 2013 | A1 |
Number | Date | Country |
---|---|---|
2012084835 | Jun 2012 | WO |
Entry |
---|
Baldwin, Richard G., “The ByteBuffer Class in Java”, Aug. 20, 2012, 14 pages. Retrieved from : <http://www.developer.com/author/Richard-G.-Baldwin-64720.htm>. |
European Patent Office, International Searching Authority, International Search Report and Written Opinion dated Mar. 6, 2014 for International Application No. PCT/US2013/067106, 11 pages. |
United States Patent and Trademark Office, Office Action Dated May 9, 2016 for U.S. Appl. No. 13/781,500, 14 pages. |
United States Patent and Trademark Office, Office Action Dated Dec. 16, 2016 for U.S. Appl. No. 13/781,500, 15 Pages. |
Number | Date | Country | |
---|---|---|---|
20150212794 A1 | Jul 2015 | US |