首页 > 数据库技术 > 详细

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

时间:2016-06-19 19:51:55      阅读:299      评论:0      收藏:0      [点我收藏+]

我使用三台SQL Server 2012 搭建分布式数据库,将一年的1.4亿条数据大致均匀存储在这三台Server中,每台Server 存储4个月的数据,Physical Server的配置基本相同,内存16G,双核 CPU 3.6GHz。

1,创建的分区视图,Linked Server的Alias是db2 和 db3,Catalog 是 tdw(test data warehouse)。

CREATE TABLE [dbo].[Commits]
(
    [CommitID] [bigint] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
    [AuthorID] [bigint] NOT NULL,
    [CreatedDate] [datetime2](7) NOT NULL,
    [CreatedDateKey] [int] NOT NULL,
 CONSTRAINT [PK__Commits_CommitID] PRIMARY KEY CLUSTERED 
(
    [CommitID] ASC,
    [CreatedDateKey] ASC
)
) ON [PRIMARY]
GO


CREATE view [dbo].[view_commits]
as

select [CommitID]
      ,[AuthorID]
      ,[CreatedDate]
      ,[CreatedDateKey]
from dbo.commits c with(nolock)
where c.[CreatedDateKey] between 20150900 and 20160000

union ALL
select [CommitID]
      ,[AuthorID]
      ,[CreatedDate]
      ,[CreatedDateKey]
from db3.tdw.dbo.commits c with(nolock)
where c.[CreatedDateKey] between 20150000 and 20150500

union ALL
select [CommitID]
      ,[AuthorID]
      ,[CreatedDate]
      ,[CreatedDateKey]
from db2.tdw.dbo.commits c with(nolock)
where c.[CreatedDateKey] between 20150500 and 20150900
WITH check OPTION;
GO

2,查询性能测试

Test1,使用Basic Table测试,cost:16s

select count(0)
from dbo.commits_total c  with(nolock)
where day(c.[CreatedDate])=1

技术分享

 

Test2,使用分区视图测试,cost=136s,跟Test1有明显的差距。

select count(0)
from dbo.view_commits c  with(nolock)
where day(c.[CreatedDate])=1

技术分享

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,
    Nselect 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,
    Nselect count(0) as cnt
    from dbo.commits c  with(nolock)
    where day(c.[CreatedDate])=1) as p
) as t

cost:106s,还是很高

 

 

 

参考doc:

Top 3 Performance Killers For Linked Server Queries

[翻译]——SQL Server使用链接服务器的5个性能杀手

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

原文:http://www.cnblogs.com/ljhdo/p/5598558.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!