473,465 Members | 1,651 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Queues, prioritization, changing priorities and algorithms

Hi,

I have to implement(or possibly acquire) a queue that manages
priorities. Low priority elements cannot get lost in the queue
indefinitely if there is a sustained, constant flow of high priority
messages.I am thinking the best way to do this is to up the priority
of lower priority items after a defined time period, eg. with a
TimerTask.

I have looked at using multiple LinkedLists, one for each priority,
but the cost of adding and removing items every time a priority
changes would be too high. ie. the suppliers to the queue are
multithreaded. The synchronization/locking would be too costly if the
queues also need to be locked every time an item's priority changes.
So I'm thinking of using a single linked list. This means there is no
need to synchronize the list when a priority changes. However, this
means that the consumer of the queue must iterate across the queue
every time it consumes. If the high priority items happen to be near
the back of the queue, this could get costly.

Has anyone any experience, advice or info on this.

Thanks in advance,

Al
Jul 17 '05 #1
5 3332
This problem has been around for over 35 years and there
are lots of papers etc. available in the literature, and many
viable techniques. Search the web.
"AlanR" <al***********@yahoo.com> wrote in message
news:3a**************************@posting.google.c om...
Hi,

I have to implement(or possibly acquire) a queue that manages
priorities. Low priority elements cannot get lost in the queue
indefinitely if there is a sustained, constant flow of high priority
messages.I am thinking the best way to do this is to up the priority
of lower priority items after a defined time period, eg. with a
TimerTask.

I have looked at using multiple LinkedLists, one for each priority,
but the cost of adding and removing items every time a priority
changes would be too high. ie. the suppliers to the queue are
multithreaded. The synchronization/locking would be too costly if the
queues also need to be locked every time an item's priority changes.
So I'm thinking of using a single linked list. This means there is no
need to synchronize the list when a priority changes. However, this
means that the consumer of the queue must iterate across the queue
every time it consumes. If the high priority items happen to be near
the back of the queue, this could get costly.

Has anyone any experience, advice or info on this.

Thanks in advance,

Al

Jul 17 '05 #2
AlanR wrote:
I have looked at using multiple LinkedLists, one for each priority,
but the cost of adding and removing items every time a priority
changes would be too high. ie. the suppliers to the queue are
multithreaded. The synchronization/locking would be too costly if the
queues also need to be locked every time an item's priority changes.
So I'm thinking of using a single linked list. This means there is no
need to synchronize the list when a priority changes. However, this
means that the consumer of the queue must iterate across the queue
every time it consumes. If the high priority items happen to be near
the back of the queue, this could get costly.

Has anyone any experience, advice or info on this.


Yes, you need a data structure called a "priority queue". These have
been around for decades -- you should find all sorts of hits if you do a
web search on this topic.

Basically, what you want to do is to enqueue items based on their
priority, as opposed to just sticking them at the back. In this way,
you don't have to scan the queue each time you need to consume an item
-- just take the item at the front.

Brad BARCLAY

--
=-=-=-=-=-=-=-=-=
From the OS/2 WARP v4.5 Desktop of Brad BARCLAY.
The jSyncManager Project: http://www.jsyncmanager.org


Jul 17 '05 #3
Seems like all techniques would require synchronization,
so if that is too slow, I guess you're screwed.
If you are on Linux or UNIX you can have separate processes,
one for each priority and let UNIX take care of modulating
the priority of each process to prevent starvation.

"AlanR" <al***********@yahoo.com> wrote in message
news:3a**************************@posting.google.c om...
Had already looked at priority queues and done some research.
It is quite difficult to find something efficient where priorities get
increased after a certain time period to prevent starvation.
ie. Priority is not so efficient where priorities change. ie. I would
need to monitor the queue for "expired priorities" and then pop them
from the queue, and push them back on when the priority changes. In a
multithreaded environment the locking/synchronization of the data
structure would really slow things down.

Brad BARCLAY <bb******@jsyncmanager.org> wrote in message

news:<Kq******************@news04.bloor.is.net.cab le.rogers.com>...
AlanR wrote:
I have looked at using multiple LinkedLists, one for each priority,
but the cost of adding and removing items every time a priority
changes would be too high. ie. the suppliers to the queue are
multithreaded. The synchronization/locking would be too costly if the
queues also need to be locked every time an item's priority changes.
So I'm thinking of using a single linked list. This means there is no
need to synchronize the list when a priority changes. However, this
means that the consumer of the queue must iterate across the queue
every time it consumes. If the high priority items happen to be near
the back of the queue, this could get costly.

Has anyone any experience, advice or info on this.


Yes, you need a data structure called a "priority queue". These have
been around for decades -- you should find all sorts of hits if you do a
web search on this topic.

Basically, what you want to do is to enqueue items based on their
priority, as opposed to just sticking them at the back. In this way,
you don't have to scan the queue each time you need to consume an item
-- just take the item at the front.

Brad BARCLAY

Jul 17 '05 #4
al***********@yahoo.com (AlanR) wrote in message news:<3a**************************@posting.google. com>...

http://www.cs.ukc.ac.uk/projects/ofa/jcsp/
( a method for verifiably correct parallel thread processing)
maybe one possible soultion
read the sections on Alternative --> fairSelect
( for real time prioritization )
read PriParallel --> insertProcessAt
( for native Java Threads )

maw
Jul 17 '05 #5
AlanR wrote:
Hi,

I have to implement(or possibly acquire) a queue that manages
priorities. Low priority elements cannot get lost in the queue
indefinitely if there is a sustained, constant flow of high priority
messages.I am thinking the best way to do this is to up the priority
of lower priority items after a defined time period, eg. with a
TimerTask.

I have looked at using multiple LinkedLists, one for each priority,
but the cost of adding and removing items every time a priority
changes would be too high. ie. the suppliers to the queue are
multithreaded. The synchronization/locking would be too costly if the
queues also need to be locked every time an item's priority changes.
So I'm thinking of using a single linked list. This means there is no
need to synchronize the list when a priority changes. However, this
means that the consumer of the queue must iterate across the queue
every time it consumes. If the high priority items happen to be near
the back of the queue, this could get costly.

Has anyone any experience, advice or info on this.


First, I suggest forgetting about using Lists. Instead use a SortedSet
(e.g. TreeSet) and a custom Comparator than compares based on priority.

When your timer task wants to play around with priorities, use the
following technique to minimize lock time. Lock the set and make a
copy. Unlock the original set. Iterate through the copy and determine
what needs to be done. Lock the original set and make the needed
changes. Note: when you change the priority of an object, first remove
it from the set, change the priority and then add it back in. This is
necessary because of the custom Comparator. Otherwise your set will get
quite screwed up.

Another approach; create a custom Comparator that takes into account
priority AND how long the request has been waiting. Now we are back to
lists. Use the Collections.binarySearch() method to insert new
requests. Periodically sort the list based on the custom Comparator.
Enjoy,
Ray

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Anand Pillai | last post by:
The standard Python Queue module, allows to generate queues that have no size limit, by passing the size argument as <= 0. q = Queue(0) In a multithreaded application, these queues could be...
0
by: Aki Niimura | last post by:
Hello everyone. I'm trying to control a program from a Python program using IPC. Although using a socket is a common choice for such applications, I would like to use SysV message queues...
0
by: badtemper | last post by:
Is there any way to use perl or any other programming language to perform a "qchk -A" from a web page and see the listing? My problem is that I manage the network for a medical facility that is...
6
by: Der Andere | last post by:
Are priority queues implemented in the STL in Visual Studio 6? If no, which is the easiest way to simulate them? Multisets? BTW: The container contains pointers to instances of a class. The...
1
by: saleem | last post by:
Dear friends, I am working on the problem which deals with the data management of requests and how should we match the responses for the requests to compare the correct Response. my problem...
8
by: Vmz | last post by:
HI, I got two queues, I need to write void function that would check both queues and remove from first queue all nodes that matches second queue. Each node has two pointers that shows to previous...
1
by: Safalra | last post by:
A long time ago when I used a browser that didn't support the shift or unshift methods of the array object, I came up with an implementation of queues that guaranteed amortised constant time...
0
by: brianbass | last post by:
I am having a perplexing issue and am wondering if anyone can see the flaw in my setup. I have 3 windows services and 3 message queues. Each service resides in the same directory and they all...
3
by: John Nagle | last post by:
There's no way to set thread priorities within Python, is there? We have some threads that go compute-bound, and would like to reduce their priority slightly so the other operations, like...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.