コード例 #1
0
        /// <summary>
        /// Executes Read Commands
        /// </summary>
        void OnRunClick(object sender, EventArgs e)
        {
            try
            {
                //string ReadCommand;
                string WriteCommand;
                lock (StopLock)
                {
                    Stopped = false;
                }

                WriteCommand = "DECLARE @packagetypeid int = 7; EXEC dbo.report @packagetypeid";
                this.ErrorMessages.Clear();

                ThreadParams tp = new ThreadParams(Program.REQUEST_COUNT, Program.TRANSACTION_COUNT, Program.ROW_COUNT, WriteCommand);
                for (int j = 0; j < Program.THREAD_COUNT; j++)
                {
                    int Threads = RunningThreads.Count();
                    // Create a thread with parameters.
                    ParameterizedThreadStart pts = new ParameterizedThreadStart(ThreadWorker);
                    RunningThreads.Add(new Thread(pts));
                    RunningThreads.ElementAt(Threads).Start(tp);
                }
                ThreadStart ts1 = new ThreadStart(ThreadMonitor);
                this.MonitorThread = new Thread(ts1);
                this.MonitorThread.Start();
            }
            catch (Exception ex) { ShowThreadExceptionDialog("OnRunClick", ex); }
        }
コード例 #2
0
        /// <summary>
        /// Executes Write/Read Commands
        /// </summary>
        void OnRunClick(object sender, EventArgs e)
        {
            try
            {
                string ReadCommand;
                string WriteCommand;
                lock (StopLock)
                {
                    Stopped = false;
                }

                WriteCommand = "EXEC BatchInsertReservations @ServerTransactions, @RowsPerTransaction, @ThreadID";
                ReadCommand  = "EXEC ReadMultipleReservations @ServerTransactions, @RowsPerTransaction, @ThreadID";
                this.ErrorMessages.Clear();

                ThreadParams tp = new ThreadParams(Program.REQUEST_COUNT, Program.TRANSACTION_COUNT, Program.ROW_COUNT,
                                                   Program.READS_PER_WRITE, ReadCommand, WriteCommand);
                for (int j = 0; j < Program.THREAD_COUNT; j++)
                {
                    int Threads = RunningThreads.Count();
                    // Create a thread with parameters.
                    ParameterizedThreadStart pts = new ParameterizedThreadStart(ThreadWorker);
                    RunningThreads.Add(new Thread(pts));
                    RunningThreads.ElementAt(Threads).Start(tp);
                }
                ThreadStart ts1 = new ThreadStart(ThreadMonitor);
                this.MonitorThread = new Thread(ts1);
                this.MonitorThread.Start();
            }
            catch (Exception ex) { ShowThreadExceptionDialog("OnRunClick", ex); }
        }
コード例 #3
0
        /// <summary>
        /// Executes Transactions on the target server
        /// </summary>
        void ThreadWorker(object tp)
        {
            ////////////////////////////////////////////////////////////////////////////////
            // Connect to the data source.
            ////////////////////////////////////////////////////////////////////////////////

            System.Data.SqlClient.SqlConnection conn = new SqlConnection(Program.CONN_STR);

            ThreadParams MyTP     = (ThreadParams)tp;
            SqlCommand   WriteCmd = new SqlCommand();

            WriteCmd.Connection     = conn;
            WriteCmd.CommandTimeout = 600;
            WriteCmd.CommandText    = MyTP.WriteCommandText;
            WriteCmd.Parameters.Add("@ServerTransactions", SqlDbType.Int, 4).Value = (int)MyTP.serverTransactions;
            WriteCmd.Parameters.Add("@RowsPerTransaction", SqlDbType.Int, 4).Value = (int)MyTP.rowsPerTransaction;
            WriteCmd.Parameters.Add("@ThreadID", SqlDbType.Int, 4).Value           = (int)Thread.CurrentThread.ManagedThreadId;

            SqlCommand ReadCmd = new SqlCommand();

            ReadCmd.Connection     = conn;
            ReadCmd.CommandTimeout = 600;
            ReadCmd.CommandText    = MyTP.ReadCommandText;
            ReadCmd.Parameters.Add("@ServerTransactions", SqlDbType.Int, 4).Value = (int)MyTP.serverTransactions;
            ReadCmd.Parameters.Add("@RowsPerTransaction", SqlDbType.Int, 4).Value = (int)MyTP.rowsPerTransaction;
            ReadCmd.Parameters.Add("@ThreadID", SqlDbType.Int, 4).Value           = (int)Thread.CurrentThread.ManagedThreadId;

            // Executing transactions on the target server
            try
            {
                conn.Open();
                for (int i = 0; i < MyTP.requestsPerThread; i++)
                {
                    lock (StopLock)
                    {
                        if (Stopped)
                        {
                            break;
                        }
                    }
                    WriteCmd.ExecuteNonQuery();
                    for (int j = 0; j < MyTP.readsPerWrite && !Stopped; j++)
                    {
                        ReadCmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                lock (this.ErrorLock)
                {
                    this.AddText(ex.Message + " " + Thread.CurrentThread.ManagedThreadId.ToString());
                }
            }
            finally
            {
                conn.Close();
            }
        }
コード例 #4
0
        /// <summary> 
        /// Executes Write/Read Commands
        /// </summary> 
        void OnRunClick(object sender, EventArgs e)
        {
            try
            {
                string ReadCommand;
                string WriteCommand;
                lock (StopLock)
                {
                    Stopped = false;
                }

                WriteCommand = "EXEC BatchInsertReservations @ServerTransactions, @RowsPerTransaction, @ThreadID";
                ReadCommand = "EXEC ReadMultipleReservations @ServerTransactions, @RowsPerTransaction, @ThreadID";
                this.ErrorMessages.Clear();

                ThreadParams tp = new ThreadParams(Program.REQUEST_COUNT, Program.TRANSACTION_COUNT, Program.ROW_COUNT,
                    Program.READS_PER_WRITE, ReadCommand, WriteCommand);
                for (int j = 0; j < Program.THREAD_COUNT; j++)
                {
                    int Threads = RunningThreads.Count();
                    // Create a thread with parameters.
                    ParameterizedThreadStart pts = new ParameterizedThreadStart(ThreadWorker);
                    RunningThreads.Add(new Thread(pts));
                    RunningThreads.ElementAt(Threads).Start(tp);
                }
                ThreadStart ts1 = new ThreadStart(ThreadMonitor);
                this.MonitorThread = new Thread(ts1);
                this.MonitorThread.Start();
            }
            catch (Exception ex) { ShowThreadExceptionDialog("OnRunClick", ex); }
        }