Is DMBS_LOCK.REQUEST First-In First-Out? [message #285772] |
Wed, 05 December 2007 10:04 |
annagel
Messages: 220 Registered: April 2006
|
Senior Member |
|
|
I am attempting to set up a queuing system for certain types of request so only one of a certain set of requests will run at a time.
My thought here was just set up a lock, the process needs to hold the lock to run pretty simple solution to implement...but is it fair? Does Oracle's implementation of DMBS_LOCK.REQUEST use a FIFO type queue? Or is it free for all? Or does it maybe depend on the OS?
|
|
|
|
Re: Is DMBS_LOCK.REQUEST First-In First-Out? [message #285777 is a reply to message #285773] |
Wed, 05 December 2007 10:23 |
annagel
Messages: 220 Registered: April 2006
|
Senior Member |
|
|
anacedent wrote on Wed, 05 December 2007 10:09 | What have you learned from your own benchmark tests?
|
I have not implemented yet, I am trying to make a decision as to whether I should go with a simple and easy to implement solution where only a lock is involved or a more complex solution in which I build a queue table.
I do not have experience with Oracle's locking mechanism and some quick Google searches on the subject were unfortunately less than helpful since locks are commonly used in developing queue and FIFO is a popular search term with regard to queuing. In other words I got a whole bunch of results which talked about queue and dbms_lock, but could not find anything on whether the locking mechanism itself uses queuing of any kind.
Quote: | What happens if/when somebody here says it works one way & you latter learn that it works another?
|
I do not really understand what you are implying by the question, I was hoping someone here might have done what I am about to do and that perhaps I could benefit from any knowledge they may have gained in their experience. I am not expecting anyone here to be infallible, but any experience users out there have had would certainly be helpful in making a decision on which direction I want to go, if no one knows one way or another that is OK to I just thought checking to see if someone else had knowledge I did not yet possess would be a good idea.
|
|
|
|
|
Re: Is DMBS_LOCK.REQUEST First-In First-Out? [message #287589 is a reply to message #285772] |
Wed, 12 December 2007 17:41 |
|
Kevin Meade
Messages: 2103 Registered: December 1999 Location: Connecticut USA
|
Senior Member |
|
|
Let us be clear what we mean so I am not confused. I think the suggestion that DBMS_LOCK uses FIFO is misleading (at least I am messed up by it) so let me clarify my understanding and you guys can beat me up on it.
The most common scenario when using user defined locks aka. DBMS_LOCK package, is to create a serialized resource. This means the following:
You create a lock with some name to represent the "thing" to searialize on, using DBMS_LOCK.ALLOCATE_UNIQUE.
You aquire an exclusive mode lock using DBMS_LOCK.REQUEST, thus only one transaction at a time can hold the lock on your named resource.
When you request a lock, you choose to not wait for the lock if you cannot get it right away. This means you will imediately recieve a timeout error if you cannot get the lock.
Under this most common scenario of using DBMS_LOCK, (99% rule I would say), there is no such thing as FIFO. There is no list of people waiting to acquire a lock on your named resource, and the guy who currenly owns it is by definition the first in (and only one in).
Your use of FIFO makes me think maybe you are trying to queue up users by making them wait to acquire a common resource. Using DBMS_LOCK to create a group of users waiting to acquire a specific lock and thus to serialize their activity, works just fine. I have done this myself.
I also have never seen anything in documentation though, that says this group of waiters will be serviced in FIFO order. Michel, is there any way to verify this? Just curious. I have seen hints to this affect in ASKTOMHOME, but Tom has never said so.
In any event, if you don't want to use DBMS_LOCK, you can revert to a new version of an old trick.
update aonerowtable set anumbercolumn = anumbercolumn + 1 returning anumbercolumn into l_your_variable;
do your worst;
commit;
Everyone executing this same code at the same time will queue on the row. I would just go with DBMS_LOCK myself.
This is an interesting question you ask. May I ask, why do you care about this little detail? What kind of application are you creating that FIFO via a lock queue would be so important.
Kevin
|
|
|
|
|
|
Re: Is DMBS_LOCK.REQUEST First-In First-Out? [message #287768 is a reply to message #285772] |
Thu, 13 December 2007 07:07 |
annagel
Messages: 220 Registered: April 2006
|
Senior Member |
|
|
Kevin,
To your question of why I would need to ensure FIFO, the answer is that I don't, the information was more for myself to know how the locking mechanism would respond in high volume situations, so that if for example I got a call from a user asking why some process, that is going to be effected by this lock, is taking so long to complete I can give them (if it is FIFO) or not give them (if it isn't FIFO) a reasonable answer on how much longer it will be before they are at the front of the line.
So it is not a mission critical requirement just a piece of information that could be useful in determining queue times.
Andrew
|
|
|
|