Home All Groups Group Topic Archive Search About
Author
21 Jul 2006 4:32 PM
Lionstone
Is there a way to keep a stored procedure from executing more than once
simultaneously?  That is, if three commands to execute the procedure arrive
nearly simultaneously on different connections, how can I make the requests
queue up so that the procedure executes one at a time with no overlap, the
second starting when the first completes?

Author
21 Jul 2006 4:45 PM
Arnie Rowland
It would help if you could provide more information about 'why' you would
want to do that. It seems very odd to want to purposefully 'handicap' the
server. You must have a goal. If you share that, perhaps we can help you
find an appropriate way to accomplish your goal.

--
Arnie Rowland
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous


Show quote
"Lionstone" <HIDElionst***@HIDEhushmail.com> wrote in message
news:ecXnFMOrGHA.4960@TK2MSFTNGP04.phx.gbl...
> Is there a way to keep a stored procedure from executing more than once
> simultaneously?  That is, if three commands to execute the procedure
> arrive nearly simultaneously on different connections, how can I make the
> requests queue up so that the procedure executes one at a time with no
> overlap, the second starting when the first completes?
>
Author
21 Jul 2006 5:21 PM
Lionstone
Each instance of the procedure first finds the next record that needs to be
sent to our application for processing by a human being ("next" is defined
by a rather nasty query).  It retrieves the ID, then updates the record to
indicate that it has been sent to the application.  The problem is we
sometimes have several dozen connections request a new record within a few
milliseconds of each other.  All of them then retrieve the same ID and make
the same subsequent update.  If the procedure executions were to queue up,
then the last connection would probably be delayed less than half a second,
and the duplicate retrievals would stop.

Show quote
"Arnie Rowland" <ar***@1568.com> wrote in message
news:eNxZXUOrGHA.352@TK2MSFTNGP02.phx.gbl...
> It would help if you could provide more information about 'why' you would
> want to do that. It seems very odd to want to purposefully 'handicap' the
> server. You must have a goal. If you share that, perhaps we can help you
> find an appropriate way to accomplish your goal.
>
> --
> Arnie Rowland
> Most good judgment comes from experience.
> Most experience comes from bad judgment.
> - Anonymous
>
>
> "Lionstone" <HIDElionst***@HIDEhushmail.com> wrote in message
> news:ecXnFMOrGHA.4960@TK2MSFTNGP04.phx.gbl...
>> Is there a way to keep a stored procedure from executing more than once
>> simultaneously?  That is, if three commands to execute the procedure
>> arrive nearly simultaneously on different connections, how can I make the
>> requests queue up so that the procedure executes one at a time with no
>> overlap, the second starting when the first completes?
>>
>
>
Author
21 Jul 2006 5:43 PM
Tracy McKibben
Lionstone wrote:
> Each instance of the procedure first finds the next record that needs to be
> sent to our application for processing by a human being ("next" is defined
> by a rather nasty query).  It retrieves the ID, then updates the record to
> indicate that it has been sent to the application.  The problem is we
> sometimes have several dozen connections request a new record within a few
> milliseconds of each other.  All of them then retrieve the same ID and make
> the same subsequent update.  If the procedure executions were to queue up,
> then the last connection would probably be delayed less than half a second,
> and the duplicate retrievals would stop.
>

I just had another very long conversation with a fellow in this group
about how to do this very thing.  Look back through the posts from this
week, you'll find it...



--
Tracy McKibben
MCDBA
http://www.realsqlguy.com
Author
21 Jul 2006 4:49 PM
David Browne
"Lionstone" <HIDElionst***@HIDEhushmail.com> wrote in message
news:ecXnFMOrGHA.4960@TK2MSFTNGP04.phx.gbl...
> Is there a way to keep a stored procedure from executing more than once
> simultaneously?  That is, if three commands to execute the procedure
> arrive nearly simultaneously on different connections, how can I make the
> requests queue up so that the procedure executes one at a time with no
> overlap, the second starting when the first completes?

Start a transaction and acquire an appropriate lock, perform the work of the
procedure and commit.

You can use sp_getapplock to get an application-wide lock that functions
like a Mutex or Critical Section.


David
Author
21 Jul 2006 5:22 PM
Lionstone
"David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
message news:u4ifhWOrGHA.1852@TK2MSFTNGP03.phx.gbl...
> Start a transaction and acquire an appropriate lock, perform the work of
> the procedure and commit.
>
> You can use sp_getapplock to get an application-wide lock that functions
> like a Mutex or Critical Section.
>
>
> David

That sounds promising.  I'll open up BOL and see what I can see.
Thanks for the nudge in the right direction. :)
Author
24 Jul 2006 1:54 PM
Lionstone
Thank you again.
I would never have suspected anything like application locks existed.  It
worked exactly as I hoped.


Show quote
"David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
message news:u4ifhWOrGHA.1852@TK2MSFTNGP03.phx.gbl...
>
> "Lionstone" <HIDElionst***@HIDEhushmail.com> wrote in message
> news:ecXnFMOrGHA.4960@TK2MSFTNGP04.phx.gbl...
>> Is there a way to keep a stored procedure from executing more than once
>> simultaneously?  That is, if three commands to execute the procedure
>> arrive nearly simultaneously on different connections, how can I make the
>> requests queue up so that the procedure executes one at a time with no
>> overlap, the second starting when the first completes?
>
> Start a transaction and acquire an appropriate lock, perform the work of
> the procedure and commit.
>
> You can use sp_getapplock to get an application-wide lock that functions
> like a Mutex or Critical Section.
>
>
> David
>

AddThis Social Bookmark Button