using System.IO;\r
using System.Threading;\r
using System.Data;\r
+using System.Data.SqlClient;\r
using Npgsql;\r
using System.Configuration;\r
using System.Diagnostics;\r
class dblt\r
{\r
public static string sServerDescription = (string)ConfigurationManager.AppSettings["ServerDescription"];\r
+ public static string sMode = (string)ConfigurationManager.AppSettings["Mode"];\r
public static int iClients = Convert.ToInt32(ConfigurationManager.AppSettings["Clients"]);\r
public static int iClientsScale = Convert.ToInt32(ConfigurationManager.AppSettings["ClientsScale"]);\r
public static int iClientsMax = Convert.ToInt32(ConfigurationManager.AppSettings["ClientsMax"]);\r
public static bool bVerboseScreen = Convert.ToBoolean(ConfigurationManager.AppSettings["VerboseScreen"]);\r
public static bool bOnFailureRetry = Convert.ToBoolean(ConfigurationManager.AppSettings["ConnectionRetry"]);\r
public static bool bConnPerIteration = Convert.ToBoolean(ConfigurationManager.AppSettings["ConnectionPerIteration"]);\r
- public static string sConn = (string)ConfigurationManager.AppSettings["PgConnectionString"];\r
+ public static string sConn = (string)ConfigurationManager.AppSettings["ConnectionString"];\r
public static string sTransactionsFile = (string)ConfigurationManager.AppSettings["TransactionsFile"];\r
public static int iSleepTime = Convert.ToInt32(ConfigurationManager.AppSettings["SleepTime"]);\r
- \r
+ private static List<string> lsValidModes = new List<string> { "pgsql", "mssql" };\r
+\r
public static Object oTransCounterLock = new Object();\r
public static Object oIterationCounterLock = new Object();\r
public static Object oTransDurationLock = new Object();\r
public static Object oLogLock = new Object();\r
\r
- //public static DataSet dsTransactions = readTransactionsFile(sTransactionsFile);\r
public static XmlDocument xmlTransactions = readTransactionsFile(sTransactionsFile);\r
- \r
\r
private static PerformanceCounter oCpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");\r
private static PerformanceCounter oSysCpuCounter = new PerformanceCounter("Processor", "% Privileged Time", "_Total");\r
\r
public static string timeStamp = "dd/MM/yyyy HH:mm";\r
public static string[] aLogArray = new string[10000000];\r
- //public static double[] aTransactionTimeArray = new double[iClientsMax * iIterations * dsTransactions.Tables[0].Columns.Count];\r
public static double[] aTransactionTimeArray = new double[iClientsMax * iIterations * xmlTransactions.SelectNodes("//transaction").Count]; \r
\r
public static int iLogIndex, iRunningAtMax, iRunningAtMin, iMaxRunning, iCompletedIterations, iCompletedTransactions;\r
\r
static void Main(string[] args)\r
{\r
+ if (!lsValidModes.Contains(sMode))\r
+ {\r
+ Console.WriteLine("Invalid operating mode '{0}': Supported modes are 'mssql' or 'pgsql'", sMode);\r
+ Environment.Exit(1);\r
+ }\r
if (iClients != 0)\r
{\r
MainWorker(iClients);\r
string sSql = "";\r
int iRandomStmt = 0;\r
int iRandomTran = 0;\r
+ SqlConnection msconn = null;\r
NpgsqlConnection conn = null;\r
if (!bConnPerIteration)\r
{\r
- conn = new NpgsqlConnection(sConn);\r
- conn.Open();\r
+ if (sMode == "pgsql") {\r
+ conn = new NpgsqlConnection(sConn);\r
+ conn.Open();\r
+ }\r
+ else if (sMode == "mssql")\r
+ {\r
+ msconn = new SqlConnection(sConn);\r
+ msconn.Open();\r
+ }\r
}\r
\r
for (int i = 0; i < iIterations; i++)\r
DateTime startTime = DateTime.Now;\r
if (bConnPerIteration)\r
{\r
- conn = new NpgsqlConnection(sConn);\r
- conn.Open();\r
+ if (sMode == "pgsql")\r
+ {\r
+ conn = new NpgsqlConnection(sConn);\r
+ conn.Open();\r
+ }\r
+ else if (sMode == "mssql")\r
+ {\r
+ msconn = new SqlConnection(sConn);\r
+ msconn.Open();\r
+ }\r
}\r
\r
- //foreach (DataRow transaction in dsTransactions.Tables[0].Rows)\r
iTransOn = 0;\r
foreach (XmlNode node in xmlTransactions.SelectNodes("//transaction"))\r
{\r
iRandomTran = random.Next(0, 2);\r
}\r
\r
- if (iRandomTran == 0)\r
- {\r
- NpgsqlTransaction tran = conn.BeginTransaction();\r
+ if (iRandomTran == 0)\r
+ {\r
+ NpgsqlTransaction tran = null;\r
+ SqlTransaction mstran = null;\r
+\r
+ if (sMode == "pgsql")\r
+ {\r
+ tran = conn.BeginTransaction();\r
+ }\r
+ else if (sMode == "mssql")\r
+ {\r
+ mstran = msconn.BeginTransaction();\r
+ }\r
+\r
DateTime beginTime = DateTime.Now;\r
\r
lock (oTransCounterLock)\r
iRunningTransactions++;\r
}\r
\r
- //foreach (DataColumn column in dsTransactions.Tables[0].Columns)\r
iSqlOn = 0;\r
foreach (XmlNode subnode in node.SelectNodes("//sql"))\r
{\r
if (iRandomStmt == 0)\r
{\r
sSql = subnode.InnerText;\r
- //NpgsqlCommand command = new NpgsqlCommand(transaction[column].ToString().Replace("#client_id#", iThread.ToString()), conn, tran);\r
- NpgsqlCommand command = new NpgsqlCommand(sSql.Replace("#client_id#", iThread.ToString()), conn, tran);\r
- NpgsqlDataReader dr = command.ExecuteReader();\r
\r
- iCompletedQueries++;\r
- while (dr.Read())\r
+ if (sMode == "pgsql")\r
{\r
- //Just pull the data back into our dataset (but we don't care about it)\r
+ NpgsqlCommand command = new NpgsqlCommand(sSql.Replace("#client_id#", iThread.ToString()), conn, tran);\r
+ NpgsqlDataReader dr = command.ExecuteReader();\r
+\r
+ iCompletedQueries++;\r
+ while (dr.Read())\r
+ {\r
+ //Just pull the data back into our dataset (but we don't care about it)\r
+ }\r
+\r
+ dr.Close();\r
+ }\r
+ else if (sMode == "mssql")\r
+ {\r
+ SqlCommand command = new SqlCommand(sSql.Replace("#client_id#", iThread.ToString()), msconn, mstran);\r
+ SqlDataReader dr = command.ExecuteReader();\r
+\r
+ iCompletedQueries++;\r
+ while (dr.Read())\r
+ {\r
+ //Just pull the data back into our dataset (but we don't care about it)\r
+ }\r
+\r
+ dr.Close();\r
}\r
\r
if (iLogLevel > 1)\r
}\r
}\r
\r
- tran.Commit();\r
+\r
+ if (sMode == "pgsql")\r
+ {\r
+ tran.Commit();\r
+ }\r
+ else if (sMode == "mssql")\r
+ {\r
+ mstran.Commit();\r
+ }\r
+\r
DateTime commitTime = DateTime.Now;\r
TimeSpan transactionDuration = commitTime - beginTime;\r
\r
\r
if (bConnPerIteration)\r
{\r
- conn.Close();\r
+ if (sMode == "pgsql")\r
+ {\r
+ conn.Close();\r
+ }\r
+ else if (sMode == "mssql")\r
+ {\r
+ msconn.Close();\r
+ }\r
}\r
\r
DateTime stopTime = DateTime.Now;\r
}\r
}\r
\r
- //public static DataSet readTransactionsFile(string sTransactionsFile)\r
public static XmlDocument readTransactionsFile(string sTransactionsFile)\r
{\r
DataSet ds = new DataSet();\r
XmlDocument transfile = new XmlDocument();\r
try\r
{\r
- //GA ds.ReadXml(sTransactionsFile, XmlReadMode.InferSchema);\r
transfile.Load(sTransactionsFile);\r
}\r
catch (Exception e)\r
{\r
Info("Error reading transaction file " + e.ToString(), iLogLevel, bVerboseScreen);\r
}\r
- //return ds;\r
return transfile;\r
}\r
}\r
\r
-}
\ No newline at end of file
+}\r