Re: Global data concurrent access ?
- From: "Michael Petrotta" <mpetrotta@xxxxxxxxx>
- Date: 7 Jan 2007 16:06:03 -0800
Jon wrote:
Next in line: how expensive is making a database connection these days?
That may have been a rhetorical question, but I happen to have just
written a little test to figure out how pooled versus unpooled
connections performed. The code below is executing the same simple
stored procedure 1000 times, from a 3.4GHz Xeon box to a 3.6GHz Xeon
box about four network hops away.
No pooling 1000 iterations. Elapsed time: 00:00:12.9217096
Pooling 1000 iterations. Elapsed time: 00:00:01.0624864
That's about 12ms per round-trip for a non-pooled connection, and 1ms
per for a pooled connection (I was trying to prove that pooling didn't
produce an order of magnitude performance improvement, and I was
obviously wrong).
using System;
using System.Data.SqlClient;
using System.Data;
namespace PoolSpeedTest
{
class Program
{
static string server = XXX
static string database = XXX
static string connStringPooling = "Data Source={0};Initial
Catalog={1};Integrated Security=True";
static string connStringNoPooling = "Data Source={0};Initial
Catalog={1};Integrated Security=True;Pooling=false";
static void Main(string[] args)
{
TwoByOne(1000);
Console.ReadLine();
}
static private void TwoByOne(int iterations)
{
// preload
for (int i = 0; i < 10; i++)
{
using (SqlConnection conn = new
SqlConnection(String.Format(connStringPooling, server, database)))
{
DoSomething(conn);
}
}
for (int i = 0; i < 10; i++)
{
using (SqlConnection conn = new
SqlConnection(String.Format(connStringNoPooling, server, database)))
{
DoSomething(conn);
}
}
//
DateTime start;
DateTime end;
start = DateTime.Now;
for (int i = 0; i < iterations; i++)
{
using (SqlConnection conn = new
SqlConnection(String.Format(connStringNoPooling, server, database)))
{
DoSomething(conn);
}
}
end = DateTime.Now;
Console.WriteLine(String.Format("No pooling {0} iterations. Elapsed
time: {1}", iterations, end - start));
start = DateTime.Now;
for (int i = 0; i < iterations; i++)
{
using (SqlConnection conn = new
SqlConnection(String.Format(connStringPooling, server, database)))
{
DoSomething(conn);
}
}
end = DateTime.Now;
Console.WriteLine(String.Format(" Pooling {0} iterations. Elapsed
time: {1}", iterations, end-start));
}
private static void DoSomething(SqlConnection conn)
{
SqlCommand command = new SqlCommand("XXX", conn);
command.CommandType = CommandType.StoredProcedure;
conn.Open();
using (IDataReader dr =
command.ExecuteReader(CommandBehavior.CloseConnection))
{
while (dr.Read())
{
string x= dr["XXX"].ToString();
}
}
}
}
}
.
- Follow-Ups:
- Re: Global data concurrent access ?
- From: Jon Skeet [C# MVP]
- Re: Global data concurrent access ?
- References:
- Global data concurrent access ?
- From: Kunal
- Re: Global data concurrent access ?
- From: Chris Mullins [MVP]
- Re: Global data concurrent access ?
- From: Jon Skeet [C# MVP]
- Re: Global data concurrent access ?
- From: Chris Mullins [MVP]
- Re: Global data concurrent access ?
- From: Jon Skeet [C# MVP]
- Global data concurrent access ?
- Prev by Date: Re: ASP Web Project
- Next by Date: Passing class through using P invoke
- Previous by thread: Re: Global data concurrent access ?
- Next by thread: Re: Global data concurrent access ?
- Index(es):
Relevant Pages
|