![]() |
Languages »
VB.NET »
Samples
Intermediate
A simple VB.NET stress utility for SQL Server 2000By Alberto VendittiThis article describes a VB.NET tool to test the performances of a Microsoft SQL Server 2000 user database. |
VB, SQL.NET 1.1, Win2K, ASP.NET, VS.NET2003, DBA, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

As any developer knows, the tuning phase of any data access application development implies the analysis of the database response time, possibly followed by a refinement of some database design aspects (i.e. reviewing some poorly coded stored procedures or the adopted indexing strategies).
This kind of optimization can't be unaware of high load scenarios, so it's a good habit to test the application under "stressed" conditions. For example, an ASP.NET Web Application will be typically tested with stress tools like Microsoft Application Center Test (a.k.a. ACT), that allow you to simulate multiple simultaneous users requesting the web site's ASPX pages.
Under some circumstances, however, these stress test environments are not suitable to point out performance bottlenecks on the database side. With ACT, for example, you can take some measurements about the web server response times, on a page by page basis; but what you are measuring is the web server's response time, that consists of the time spent to process/render the web page plus the time spent in accessing data from the database server. And sometimes it is not simple to understand if the poor performance cause resides in the ASPX page code or in the involved database activity.
So, a new need arises: the need to measure the pure database response time. This is true especially during the development and testing of Web Applications (where you want to measure the database response time, without the noise introduced by the web server processing), but also in many other multi-tier situations, where you want to evaluate the database performance excluding the influences of upper software layers.
Of course, this kind of measurements on the database side can be collected through tools like Microsoft SQL Server Profiler while the web application pages are being hit by the ACT-simulated workload. But, if you collect measures in this way, you need to keep in mind that the database workload comes always from the web server, and this can be sometimes not realistic in case of differences in the web infrastructure between the test environment and the real environment. To make an example: suppose that your production architecture includes a web server farm that you don't have in the test environment; after observing the test environment performance, you can perhaps imagine how your web application will scale on production by the ASP.NET point of view, but it's hard to tell how the database will behave in production, where it will be exposed to the workload generated by multiple web servers.
The tool presented in this article, named DBstressUtil, is a simple database stress utility that tries to address these problems, focusing on the database performance analysis and keeping away any other application layer (data access, business logic, user interface components) that might add noise to the database response time measurement.
When I faced the problem of simulating a workload to stress a SQL Server database, someone suggested me to take a look of the Microsoft SQL Server 2000 Resource Kit. In fact, the Resource Kit contains a VB6 utility named Database Hammer, a tool to test the performance of a SQL Server 2000 instance: it creates its own work tables and then submits tons of INSERT/UPDATE statements on that tables, simulating concurrent users connected to the database. So you can observe if a particular installation of SQL Server performs well.
But my goal was different: I needed to test not a generic instance of SQL Server, but a specific database, with its indexes, stored procedures, triggers and so on. So, Database Hammer was not useful for me, but I liked the basic idea of simulating concurrent database users through a Windows Application. From there to conceive DBstressUtil, the step was short.
DBstressUtil is coded as a Windows Forms VB.NET application and it is designed to work on a SQL Server 2000 database (of course, using the SQL Server .NET Managed Provider classes of the System.Data.SqlClient namespace).
DBstressUtil simulates multiple database users submitting T-SQL scripts (executing stored procedures or simply sending DML commands). These scripts are taken from an input text file (that we'll call "test script" from now on), that has to be prepared in advance, with a simple text editor.
When you run DBstressUtil, on the main form, you can configure some execution options as:
txtInstances),
txtClientShift),
txtInterval). When you start the stress test, a number of concurrent threads are created and each of these begins the execution of the T-SQL commands taken from the "test script". Each command execution time (in milliseconds) is measured and recorded on a CSV output file, for an easy post-processing of collected data. During the test, you can monitor the number of currently running simulated client instances (see txtRunningInstances), and the number of the total executed commands (see txtDoneCommands).
A test run has to be considered over when the number of the total executed commands equals the number of client instances multiplied by the number of commands included in the "test script". At this time, you can inspect the CSV log file produced by DBstressUtil; this output file will contain records made up of these fields:
txtInstances value) of the simulated client instance that executed the command;
Each simulated client instance is an instance of the ClientProc class. The StartClientProcess method of this class is responsible for all the simulation processes of a single client, and it is invoked for each instance of ClientProc on a new thread by the main program, as shown here:
Dim i As Integer ' Counter of Client process instances
Dim x() As ClientProc ' Array of Client process instances
...
x(i) = New ClientProc
x(i).ConnectString = ...
x(i).WaitInterval = Convert.ToInt32(txtInterval.Text)
x(i).CommandFile = txtCommandFile.Text
x(i).LogFile = txtLogFile.Text
...
Dim t As New Thread(AddressOf x(i).StartClientProcess)
t.Start()
Steps of the StartClientProcess method are:
LoadCommandFile() private method);
SqlCommand.ExecuteNonQuery() method;
All the code accessing resources that are shared among multiple client instances is protected by a Mutex (for example: the output file access, or the update of UI elements of the MainForm).
EXEC stored_procedure @param=value command;
SELECT / INSERT / UPDATE / DELETE command;
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 14 Apr 2004 Editor: Nishant Sivakumar |
Copyright 2004 by Alberto Venditti Everything else Copyright © CodeProject, 1999-2009 Web15 | Advertise on the Code Project |