views:

79

answers:

4

Is it possible to limit CPU usage at SqlBulkCopy?

When I execute my code (see below), CPU usage on SQL server jumps to 100%. I'd like to limit this to, let's say, 50%. Is this possible?

Code:

string connectionString = ConfigurationManager.ConnectionStrings["connectionString"].ToString();
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connectionString))
{
    bulkCopy.DestinationTableName = "dbo.CSVFile";
    bulkCopy.BulkCopyTimeout = 600;
    bulkCopy.BatchSize = 1000;
    bulkCopy.WriteToServer(tableCSV);
}

EDIT: This code is running on seperate machine from the db server.

Why I need to limit CPU usage: this SQL server has multiple databases, one of them is acceseed constantly from two computers, each of them does a couple of queries per second. This two computers operate two big machines, so every time one of this computer waits for his queries to execute, he stops his machine, waits for queries to execute and then runs his machine again. So every time I run something on SQL server that consumes a lot of CPU, that stops some machines in production.

+1  A: 

Why? You are asking the server to do work, it's doing the work. Making it twice as slow doesn't make sense. Leave it up to SQL Server to schedule its jobs, you can't do it yourself since you don't know what kind of jobs are active.

Hans Passant
I edited my question so you can see why I would need this.
_simon_
+1  A: 

You can use MAXDOP to temporarily use only one processor : http://msdn.microsoft.com/en-us/library/ms181007.aspx

If SQL CPU usage is a problem, you may move SqlServer to a dedicated server.

Guillaume
+1  A: 

Is the data you're updating affecting the results of the other machine's queries? If it is then it should block them, nothing to do with the CPU but because the records are locked for update. You want the operation to run as quickly as possible so max CPU is good.

If the two datasets are different then there is no reason why a well configured SQL server couldn't serve both, look into tuning options, how much memory is available etc

Chris
They are completely seperated databases. Regarding server, it is a VMWare virtual machine, with low resources though...
_simon_
Regardless, there should still be only a single instance of SQL Server running serving up the data from both. I'd look at performance tuning, if the CPU is maxing out I'd imagine its memory resources that are killing what you're trying to do not the CPU. If the data for the frequent query is being paged out in order to do the mass update then that would be the cause, not something that can be fixed by 'limiting the CPU'
Chris
A: 

You said :

They are completely seperated databases.

You can install a second instance of sql server with different CPU affinity/priority. You can also buy a second server.

Guillaume