I should probably be able to find an answer to this but my Google-fu is weak today. When I have the same stored proc called multiple times by a web app, do the calls queue up or do they run independently?
They would run independently. If they queued up, that would cause some massive scalability problems if you had a busy system that used lots of stored procedures.
This assumes of course that the sprocs aren't locking resources in a way that would cause one call to have to wait for another to finish.
Depends on the isolation level of what the stored procedure is doing. If the isolation level is set to READ UNCOMMITTED for all the transactions in the SP, there is no protection, and multiple threads can be performing the same transaction at the same time.
If it's set to a higher isolation level, then other threads may be locked out of the resources that your SP is dealing with until the transaction is completed, effectively "queuing" the other SP threads.
There is no explicit stored procedure queue though. As long as your database has free connections and resources available, it will spawn threads to satisfy requests.
Both. Each invocation of a stored procedure (more precisesly each request sent by the client) creates a task in SQL, visible in sys.dm_os_tasks
. Tasks are assigned to schedulers (sys.dm_os_schedulers
) and wait until a worker (sys.dm_os_workers
) is available to run them. If the system is very busy then the tasks will queue up, and this is visible in the work_queue_count
column of sys.dm_os_schedulers
. For more details see Thread and Task Architecture.
Under normal operations though the queueing effect is not visible as the system immedeatly picks up the submitted tasks and start running them.
Clients can submit only one request per connection (MARS is the exception, not the rule). So from a client point of view, he must queue requests when using a connection, but this is hidden in the program control flow (ie. it must wait for a request to return before submitting a new one).