SQL Server分布式数据库性能测试

发表于:2016-6-24 13:37

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:悦光阴    来源:51Testing软件测试网采编

  3,使用OpenQuery查询,OpenQuery将查询语句直接在Linked Server上执行,返回查询的结果。
OpenQuery Executes the specified pass-through query on the specified linked server.
select sum(t.cnt) as cnt
from
(
select count(0) as cnt
from dbo.commits c  with(nolock)
where day(c.[CreatedDate])=1
UNION all
select p.cnt
from openquery(db2,
N'select count(0) as cnt
from dbo.commits c  with(nolock)
where day(c.[CreatedDate])=1') as p
UNION all
select p.cnt
from openquery(db3,
N'select count(0) as cnt
from dbo.commits c  with(nolock)
where day(c.[CreatedDate])=1') as p
) as t
cost:105s,还是很高.
  4,使用C# 多线程编程,创建三个Task同时运行在三台Server上,Cost:28s
static void Main(string[] args)
{
List<Task> tasks = new List<Task>();
int c1=0, c2=0, c3=0;
Task t1 = new Task(()=>
{
c1= GetCount("xxx");
});
Task t2 = new Task(() =>
{
c2=  GetCount("xxx");
});
Task t3 = new Task(() =>
{
c3= GetCount("xxx");
});
tasks.Add(t1);
tasks.Add(t2);
tasks.Add(t3);
Stopwatch sw = new Stopwatch();
sw.Start();
t1.Start();
t2.Start();
t3.Start();
Task.WaitAll(tasks.ToArray());
int sum = c1 + c2 + c3;
sw.Stop();
Console.Read();
}
static int GetCount(string str)
{
using (SqlConnection con = new SqlConnection(str))
{
con.Open();
var cmd = con.CreateCommand();
cmd.CommandText = @" select count(0) as cnt
from dbo.commits c  with(nolock)
where day(c.[CreatedDate]) = 1";
int count = (int)cmd.ExecuteScalar();
con.Close();
return count;
}
}
  5,结论
  · 将数据水平切分,分布式部署在不同的SQL Server上,其查询性能并不一定比单一DB性能更好。
  · 使用OpenQuery函数将查询语句在Remote Server上执行,返回查询结果,能够优化Linked Server 的查询性能。
  · 在使用分布式数据库查询数据时,针对特定的应用,编写特定的代码,这需要fore-end 更多的参与。
22/2<12
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号