Home All Groups Group Topic Archive Search About

What is SQL Server version of Oracle's CPU_PER_CALL, or how do I restrict max. exec. time of a query

Author
9 Sep 2005 2:29 PM
TheSak
I'm developing the SQL Server version of an application in which I need
to be able to set the maximum amount of CPU time a query may use before
it will return an error.  With Oracle, I set the CPU_PER_CALL parameter
for the user to the maximum amount of CPU time a query can use before
the server will return an error.  I use this to queue long-running
queries to execute in a seperate process.

Any ideas?

Thanks in advance.
Paul Schofield

Author
9 Sep 2005 2:33 PM
David Portas
Per connection:
SET QUERY_GOVERNOR_COST_LIMIT

Or per server:
sp_configure 'query governor cost limit'

--
David Portas
SQL Server MVP
--
Author
9 Sep 2005 8:23 PM
TheSak
Many thanks for the quick response!

Paul Schofield
Consultant
Software Architects
Author
9 Sep 2005 9:00 PM
Gert-Jan Strik
Note that the query governor only allows or disallows a query to start
executing (based on estimates). Once the query execution has started,
the query governor will not stop it, regardless of the actual CPU use.

Gert-Jan


TheSak wrote:
Show quote
>
> Many thanks for the quick response!
>
> Paul Schofield
> Consultant
> Software Architects
Author
9 Sep 2005 10:28 PM
Andrew J. Kelly
And keep in mind it is a global setting not per individual user.

--
Andrew J. Kelly  SQL MVP


Show quote
"Gert-Jan Strik" <sorry@toomuchspamalready.nl> wrote in message
news:4321F7F6.80DE0CF0@toomuchspamalready.nl...
> Note that the query governor only allows or disallows a query to start
> executing (based on estimates). Once the query execution has started,
> the query governor will not stop it, regardless of the actual CPU use.
>
> Gert-Jan
>
>
> TheSak wrote:
>>
>> Many thanks for the quick response!
>>
>> Paul Schofield
>> Consultant
>> Software Architects
Author
14 Sep 2005 2:31 PM
Paul Schofield
I need to be able to configure one user to be able to run queries
without a limitation on execution time, but I need to limit execution
time on another user.  Is there any way to accomplish this?

Regards,
Paul Schofield
Consultant
Software Architects

*** Sent via Developersdex http://www.developersdex.com ***
Author
15 Sep 2005 1:23 AM
Andrew J. Kelly
Each connection has it's own ability to set the Timeout for that connection.
So change the connection string, DSN etc. on that client to some amount
other than unlimited.

--
Andrew J. Kelly  SQL MVP


Show quote
"Paul Schofield" <pnschofi***@yahoo.com> wrote in message
news:%23$UxwjTuFHA.3236@TK2MSFTNGP14.phx.gbl...
>I need to be able to configure one user to be able to run queries
> without a limitation on execution time, but I need to limit execution
> time on another user.  Is there any way to accomplish this?
>
> Regards,
> Paul Schofield
> Consultant
> Software Architects
>
> *** Sent via Developersdex http://www.developersdex.com ***
Author
15 Sep 2005 2:49 PM
Paul Schofield
Does anyone know how to set this option in the querystring?  I tried
adding "QUERY_GOVERNOR_COST_LIMIT=1" to the querystring, but I got an
error:

System.ArgumentException: Keyword not supported:
'query_governor_cost_limit'.

I can't find any documentation for changing these sorts of settings from
the connection string.

Thanks in advance,
Paul Schofield
Consultant
Software Architects

*** Sent via Developersdex http://www.developersdex.com ***
Author
15 Sep 2005 7:36 PM
Paul Schofield
Why did I say "querystring"?  I meant connection string, of course!

*** Sent via Developersdex http://www.developersdex.com ***
Author
15 Sep 2005 10:17 PM
Andrew J. Kelly
Paul,

It is not the query governor.  That is used for something else and will
affect everyone not just that one connection.  I am not at a place to look
up the answer at the moment but if you state which driver you are using to
connect I can look it up.

--
Andrew J. Kelly  SQL MVP


Show quote
"Paul Schofield" <pnschofi***@yahoo.com> wrote in message
news:%23gw16SguFHA.360@TK2MSFTNGP12.phx.gbl...
> Does anyone know how to set this option in the querystring?  I tried
> adding "QUERY_GOVERNOR_COST_LIMIT=1" to the querystring, but I got an
> error:
>
> System.ArgumentException: Keyword not supported:
> 'query_governor_cost_limit'.
>
> I can't find any documentation for changing these sorts of settings from
> the connection string.
>
> Thanks in advance,
> Paul Schofield
> Consultant
> Software Architects
>
> *** Sent via Developersdex http://www.developersdex.com ***
Author
16 Sep 2005 2:27 PM
Paul Schofield
Hi Andrew,

We're using the default driver included with the System.Data.SqlClient
namespace in the .NET Framework v1.1.

Paul Schofield

*** Sent via Developersdex http://www.developersdex.com ***
Author
16 Sep 2005 3:25 PM
Andrew J. Kelly
You should look in the VS help for "ConnectionString" property.  These are
the ones in particular you are interested in:

      Connect Timeout
      -or-
      Connection Timeout
      The length of time (in seconds) to wait for a connection to the server
before terminating the attempt and generating an error.



--
Andrew J. Kelly  SQL MVP


Show quote
"Paul Schofield" <pnschofi***@yahoo.com> wrote in message
news:uIxPOrsuFHA.1252@TK2MSFTNGP09.phx.gbl...
> Hi Andrew,
>
> We're using the default driver included with the System.Data.SqlClient
> namespace in the .NET Framework v1.1.
>
> Paul Schofield
>
> *** Sent via Developersdex http://www.developersdex.com ***
Author
16 Sep 2005 8:37 AM
Erland Sommarskog
Paul Schofield (pnschofi***@yahoo.com) writes:
> I need to be able to configure one user to be able to run queries
> without a limitation on execution time, but I need to limit execution
> time on another user.  Is there any way to accomplish this?

How does the user submit his queries?

SQL Server as such does not have this concept. However, you can set up
a command timeout from all client APIs. In fact most APIs has a default
timeout of 30 seconds. Note that this is wallclock time and nothing else,
and it is measured until the first piece of data comes back from SQL Server.

How you set this up varies a little from API to API, but I can't recall
that any API exposes this in the connection string. Typically, you define
this timeout on some command object. So depending on how your applicaiton
looks like, it can be a lot of work for you to implement this.



--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
Author
19 Sep 2005 2:51 PM
Paul Schofield
Queries will initially be submitted through a web or mainframe
interface.  If it is determined that the time to execute the query will
exceed a configurable threshold, the query will terminate and the use
will have the option to execute the query in "batch mode".  Under the
batch mode scenario, the query information is queued in the database and
a dedicated Windows service will re-run the queries, persisting the
results into a table in the database.

When a query is performed through the web and mainframe interfaces, any
long-running queries need to time out and stop executing.  When the
Windows service runs the query, it needs to be able to execute a query
of any duration without failing.

Paul Schofield
Consultant
Software Architects

*** Sent via Developersdex http://www.developersdex.com ***
Author
19 Sep 2005 9:57 PM
Erland Sommarskog
Paul Schofield (pnschofi***@yahoo.com) writes:
> Queries will initially be submitted through a web or mainframe
> interface.  If it is determined that the time to execute the query will
> exceed a configurable threshold, the query will terminate and the use
> will have the option to execute the query in "batch mode".  Under the
> batch mode scenario, the query information is queued in the database and
> a dedicated Windows service will re-run the queries, persisting the
> results into a table in the database.
>
> When a query is performed through the web and mainframe interfaces, any
> long-running queries need to time out and stop executing.  When the
> Windows service runs the query, it needs to be able to execute a query
> of any duration without failing.

As I understand it, the client code for the user and for the Windows
service will be entirely different, so you will just set the command
timeout differently in the two applications.

That is, this problem is best solved outside SQL Server.

Note though that a query could run into a command timeout without executing
for a second, if gets blocked by some long-running transaction.
--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp

AddThis Social Bookmark Button