自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

淺談SQL Server數(shù)據(jù)庫并發(fā)測試方法

運維 數(shù)據(jù)庫運維 SQL Server
本文將為大家介紹SQL Server數(shù)據(jù)庫并發(fā)測試方法,包括利用測試工具模擬多個最終用戶進(jìn)行并發(fā)測試、利用測試工具編寫腳本,直接連接數(shù)據(jù)庫進(jìn)行并發(fā)測試等等方法。

1. 利用測試工具模擬多個最終用戶進(jìn)行并發(fā)測試;

這種測試方法的缺點:最終用戶往往并不是直接連接到數(shù)據(jù)庫上,而是要經(jīng)過一個和多個中間服務(wù)程序,所以并不能保證訪問數(shù)據(jù)庫時還是并發(fā)。其次,這種測試方法需要等到客戶端程序、服務(wù)端程序全部完成才能進(jìn)行;

2. 利用測試工具編寫腳本,直接連接數(shù)據(jù)庫進(jìn)行并發(fā)測試;

這種方法可以有效的保證并發(fā)操作,而且在數(shù)據(jù)庫訪問程序完成即可測試,可以大大縮短測試時間,而且測試效果更好。

下面通過一個演示程序,演示使用Robot使用第二種測試方法進(jìn)行數(shù)據(jù)庫的并發(fā)測試。

***步:創(chuàng)建演示程序

打開SQL SERVER查詢分析器,在SQL SERVER測試數(shù)據(jù)庫中執(zhí)行下列腳本(腳本執(zhí)行操作:創(chuàng)建表testtable,并插入一條記錄;創(chuàng)建存儲過程test): 

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Test]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)

drop procedure [dbo].[Test]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[testtable]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table [dbo].[testtable]

GO

CREATE TABLE [dbo].[testtable] (

[testid] [int] NULL ,

[counts] [int] NULL

) ON [PRIMARY]

GO

insert into testtable (testid,counts) values (1,0)

GO

SET QUOTED_IDENTIFIER ON

GO

SET ANSI_NULLS ON

GO

CREATE Procedure dbo.Test

as

declare @count int

begin tran TEST

select @count=countsfrom testtable where testid=1

update testtable setcounts=@count+1

if (@@error >0) begin

rollback tran TEST

end else begin

commit tran TEST

end

GO

SET QUOTED_IDENTIFIER OFF

GO

SET ANSI_NULLS ON

GO

第二步:創(chuàng)建測試腳本

在Robot中新建VU腳本,輸入以下內(nèi)容:

 #include 

{

push Timeout_scale = 200; /* Set timeouts to 200% of maximum response time */

push Think_def = "LR";

Min_tmout = 120000; /* Set minimum Timeout_val to 2 minutes*/

push Timeout_val = Min_tmout;

ser=sqlconnect("server","sa","888","192.168.0.99","sqlserver");

set Server_connection = ser;

push Think_avg = 0;

sync_point "logon";

sqlexec ["sql_1000"] "testdb..test";

sqldisconnect (ser);

}

說明:

ser=sqlconnect("server","sa","888","192.168.0.99","sqlserver")

sa為數(shù)據(jù)庫用戶名,888為sa密碼,192.168.0.99數(shù)據(jù)庫IP地址

以上三項按實際的測試數(shù)據(jù)庫設(shè)置更改,其他兩項不用修改

sqlexec ["sql_1000"] "testdb..test"

testdb為新建存儲過程test所在的數(shù)據(jù)庫,按實際的數(shù)據(jù)庫修改

第三步:執(zhí)行測試

運行上一步創(chuàng)建的腳本(運行時自動創(chuàng)建Suite),在Run Suite窗口中的"Number of users"上輸入20。運行完腳本,打開數(shù)據(jù)庫查看counts的數(shù)值。把counts值改為零多次運行腳本,觀察每次運行后counts的結(jié)果。

測試說明:

1. 測試示例程序的目的是,存儲過程test每執(zhí)行一次,表testtable中的counts字段增加一;

2. 第三步的測試可以發(fā)現(xiàn)每次執(zhí)行后counts結(jié)果并不相同,而且不等于20,這說明這個程序是在并發(fā)時是問題的;

3. 將存儲過程中的select @count=countsfrom testtable where testid=1修改為select @count=countsfrom testtable with (UPDLOCK) where testid=1。再次進(jìn)行并發(fā)測試,每次的結(jié)果應(yīng)該都是20。

以上演示程序,僅僅演示了測試的方法。在實際的數(shù)據(jù)庫并發(fā)測試中,首先要確定存在哪些并發(fā)情況、哪些數(shù)據(jù)受到并發(fā)影響,然后編寫腳本,設(shè)置suite進(jìn)行并發(fā)測試。

【編輯推薦】

  1. 用并行查詢讓SQL Server加速運行
  2. 減少SQL Server數(shù)據(jù)庫死鎖的方法
  3. MySQL***高并發(fā)網(wǎng)站實戰(zhàn)攻略
責(zé)任編輯:彭凡 來源: 51CTO論壇
相關(guān)推薦

2009-03-19 09:44:07

SQL Server數(shù)據(jù)庫遷移數(shù)據(jù)庫

2010-09-14 09:53:52

sql server還

2010-07-15 17:28:50

SQL Server

2011-06-24 15:57:35

SQL AzureDAC

2011-03-30 15:36:31

SQL Server

2011-03-29 09:40:31

SQL Server數(shù)據(jù)庫鏈接

2009-03-30 10:56:58

SQL Server數(shù)據(jù)庫死鎖數(shù)據(jù)庫

2009-01-27 21:00:00

服務(wù)器數(shù)據(jù)庫SQL Server

2009-05-04 13:43:16

SQL Server置疑數(shù)據(jù)庫恢復(fù)

2010-10-26 15:54:02

連接oracle數(shù)據(jù)庫

2011-08-25 16:13:31

SQL Server批量替換數(shù)據(jù)

2010-07-08 11:05:14

SQL Server數(shù)

2021-05-17 06:57:34

SQLServer數(shù)據(jù)庫

2010-09-13 15:31:14

sql server數(shù)

2010-09-13 15:55:17

SQL Server數(shù)

2010-09-03 11:00:47

SQL刪除

2011-03-28 14:29:46

SQL Server數(shù)主鍵列

2010-11-08 14:02:40

SQL Server系

2010-11-08 16:04:06

SQL SERVER連

2010-09-06 09:53:41

SQL Server語句
點贊
收藏

51CTO技術(shù)棧公眾號