Question

This question is an follow-up of an previous asked question.

I've written an simple program who looks like this.

string s;
do
{
  using (SqlConnection conn = new SqlConnection("POOLEDCONN"))
  {
    using (SqlCommand cmd = new SqlCommand("", conn))
    {
        s = (string) cmd.ExecuteScalar();
        Code2IncrementPerfomanceCounter
    }
  }    
} while (!string.IsNullOrEmpty(s))

The query returns an string(nvarchar(max), current maximum size 9k), there is a lot of latency between SQL Server and .NET. The SQL Profiler says that the query has an duration of 0 ms, so I think it isn't the database. The network is responding in less than 1 ms so it shouldn't be the network.

If I run this code on our testserver(VMWare, SQL isn't virtualized) there will be a max of 600 loops per second. The application doesn't consume more than 5 % cpu. Why isn't it going faster? Must I use streaming to get the data from SQL or something else?

Thanx in advance

Was it helpful?

Solution

600 calls per second is one call per 1.7 ms. If your latency is 1 ms, and Sql Server adds a little to that, that seems like a plausible result?

OTHER TIPS

I have three different things you need to look at:

  1. Is your web server connecting to the DB Server with the TCP/IP or are you using a different protocol?
  2. How busy is the network on the machine running the dtoNet process?
  3. Does the performance go above 600 processes/second if you remove the SQL call and leave only the performance counter logging?

Opening and closing the SQL connection is expensive. Can you just do that once instead?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top