Esempio n. 1
0
        public void Consume(object arg)
        {
            Params p = (Params)arg;

            using (consume_outputfile = new System.IO.StreamWriter(p.Path + "\\consume.txt"))
            {
                consume_outputfile.WriteLine("Database: " + Program.Database + "\t Variables: " + p.Variables + "\t Iterations: " + p.Iterations + "\t Timespan: " + p.timeSpan + "\t WriteFrequency: " + p.writefrequency + "\t InitIterations: " + p.inititerations);
                consume_outputfile.WriteLine("Variables\tDuration(ms)\tReadCount");

                int      variables          = p.Variables;
                TimeSpan variabletimespanTS = p.timeSpan;
                telemetry_c = new Telemetry(Program.VmName, p.Path, variables, adapter);
                telemetry_c.SetID("consume");
                telemetry_c.InitTelemetryCollection("consume");
                bool ex = false;
                while (c_mRunning)
                {
                    System.Diagnostics.Stopwatch sww = new System.Diagnostics.Stopwatch();
                    for (int ii = 0; ii < p.inititerations; ii++)
                    {
                        if (!c_mRunning)
                        {
                            break;
                        }
                        sww.Restart();
                        adapter.PrepareReadMultipleLatest(variables, variabletimespanTS);
                        adapter.ReadStatic(variables, variabletimespanTS);
                        sww.Stop();
                        int wait = 1000 - (int)sww.ElapsedMilliseconds;
                        if (wait > 0)
                        {
                            System.Threading.Thread.Sleep(wait);
                        }
                    }
                    var percent = p.Iterations / 100;
                    for (int i = 0; i < p.Iterations; i++)
                    {
                        if (!c_mRunning)
                        {
                            break;
                        }
                        adapter.PrepareReadMultipleLatest(variables, variabletimespanTS);
                        var sw = System.Diagnostics.Stopwatch.StartNew();
                        try
                        {
                            adapter.ReadStatic(variables, variabletimespanTS);
                        }catch (System.NullReferenceException e) { ex = true; continue; }

                        sw.Stop();
                        if (ex)
                        {
                            System.Console.WriteLine("Consumer: OK"); ex = false;
                        }
                        double elap = sw.Elapsed.TotalMilliseconds;
                        try
                        {
                            consume_outputfile.WriteLine(variables + "\t" + elap + "\t" + adapter.GetStaticReadCount());
                        }
                        catch (System.ObjectDisposedException) { }
                        if (i % percent == 0)
                        {
                            System.Console.WriteLine("Consumer: " + i / percent + "% progress");
                        }
                        int sleep = 1000 - (int)elap;
                        if (sleep > 0)
                        {
                            System.Threading.Thread.Sleep(sleep);
                        }
                    }
                    while (!p_done)
                    {
                        if (!c_mRunning)
                        {
                            break;
                        }
                        adapter.PrepareReadMultipleLatest(variables, variabletimespanTS);
                        try
                        {
                            adapter.ReadStatic(variables, variabletimespanTS);
                        }
                        catch (System.NullReferenceException e) { ex = true; continue; }
                    }

                    break;
                }
                System.Console.WriteLine("Consumer ending");
                telemetry_c.CollectVariableRunTelemetry(variables);
                telemetry_c.mRunning = false;
                consume_outputfile.Flush();
                consume_outputfile.Close();
                consume_outputfile.Dispose();
            }
        }
Esempio n. 2
0
        public void Run()
        {
            mRunning = true;
            #region WriteDataSet
            WriteDataSet();
            if (System.Threading.ThreadPool.SetMinThreads(300, 300))
            {
                System.Console.WriteLine("Set minimum was successful");
            }
            System.Threading.Thread.Sleep(5000);
            #endregion
            #region TimeSpan Test
            using (outputfile = new System.IO.StreamWriter(Path + "\\timespan_read_test.txt"))
            {
                outputfile.WriteLine("Database: " + Program.Database + "\t MaxTimeSpan: " + maxtimespan + "\t Iterations: " + timespaniterations + "\t WriteFrequency: " + writefrequency);
                outputfile.WriteLine("Timespan\tDuration(ms)");

                //TimepanRead-TestCase
                System.Console.WriteLine("Start TimepanRead-TestCase");
                TimeSpan timespanTS    = TimeSpan.Parse(timespaninitvalue);
                TimeSpan maxtimespanTS = TimeSpan.Parse(maxtimespan);
                telemetry = new Telemetry(Program.VmName, Path, (int)timespanTS.TotalMinutes, adapter);
                telemetry.SetID("timespan");
                telemetry.InitTelemetryCollection("timespan");
                while (mRunning)
                {
                    for (int i = 0; i < timespaniterations; i++)
                    {
                        PrepareReadOne(timespanTS);
                        var sw = System.Diagnostics.Stopwatch.StartNew();
                        ReadOne(timespanTS);
                        sw.Stop();
                        double elap    = sw.Elapsed.TotalMilliseconds;
                        string logtext = "Timespan: " + timespanTS + " Duration: " + elap;
                        System.Console.WriteLine(logtext);
                        try
                        {
                            outputfile.WriteLine(timespanTS + "\t" + elap);
                        }
                        catch (System.ObjectDisposedException) { }
                    }
                    telemetry.CollectVariableRunTelemetry((int)timespanTS.TotalMinutes);
                    timespanTS += TimeSpan.Parse(timespaninc);
                    if (timespanTS > maxtimespanTS)
                    {
                        break;
                    }
                    try { outputfile.WriteLine("New TimeSpan: " + timespanTS + "\t"); }
                    catch (System.ObjectDisposedException) { }
                }
                telemetry.CloseVMConnection();
            }
            #endregion
            #region Variable Test
            using (outputfile = new System.IO.StreamWriter(Path + "\\variable_read_test.txt"))
            {
                outputfile.WriteLine("Database: " + Program.Database + "\t MaxVariables: " + maxvariables + "\t Iterations: " + variableiterations + "\t Timespan: " + variabletimespan + "\t WriteFrequency: " + writefrequency);
                outputfile.WriteLine("Variables\tDuration(ms)");

                //VariableRead-TestCase
                System.Console.WriteLine("Start VariableRead-TestCase");
                int      variables          = variablesinitvalue;
                TimeSpan variabletimespanTS = TimeSpan.Parse(variabletimespan);
                telemetry = new Telemetry(Program.VmName, Path, variables, adapter);
                telemetry.SetID("variable");
                telemetry.InitTelemetryCollection("variable");
                while (mRunning)
                {
                    for (int i = 0; i < variableiterations; i++)
                    {
                        PrepareReadMultiple(variables, variabletimespanTS);
                        var sw = System.Diagnostics.Stopwatch.StartNew();
                        ReadMultiple(variables, variabletimespanTS);
                        sw.Stop();
                        double elap    = sw.Elapsed.TotalMilliseconds;
                        string logtext = "Variables: " + variables + " Duration: " + elap;
                        System.Console.WriteLine(logtext);
                        try
                        {
                            outputfile.WriteLine(variables + "\t" + elap);
                        }
                        catch (System.ObjectDisposedException) { }
                    }
                    telemetry.CollectVariableRunTelemetry(variables);
                    variables += variableinc;
                    if (variables > maxvariables)
                    {
                        break;
                    }
                    try { outputfile.WriteLine("New Variable count: " + variables + "\t"); }
                    catch (System.ObjectDisposedException) { }
                }
                telemetry.CloseVMConnection();
            }
            #endregion
            #region Client Test
            using (outputfile = new System.IO.StreamWriter(Path + "\\client_read_test.txt"))
            {
                outputfile.WriteLine("Database: " + Program.Database + "\t MaxClient: " + maxclients + "\t Iterations: " + clientiterations + "\t Timespan: " + clienttimespan + "\t Variables: " + clientvariables + "\t WriteFrequency: " + writefrequency);
                outputfile.WriteLine("Clients\tDuration(ms)");

                //ClientRead-TestCase
                System.Console.WriteLine("Start ClientRead-TestCase");
                int      clients          = clientsinitvalue;
                TimeSpan clienttimespanTS = TimeSpan.Parse(clienttimespan);
                Running = true;
                for (int i = 0; i < clients; i++)
                {
                    System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(ReadStaticC))
                    {
                        IsBackground = false
                    };
                    Params a = new Params(clientvariables, clienttimespanTS);
                    t.Start(a);
                    clientlist.Add(t);
                }
                System.Threading.Thread.Sleep(2000);
                PrepareReadMultiple(clientvariables, clienttimespanTS);
                telemetry = new Telemetry(Program.VmName, Path, clients, adapter);
                telemetry.SetID("client");
                telemetry.InitTelemetryCollection("client");
                while (mRunning)
                {
                    for (int i = 0; i < clientiterations; i++)
                    {
                        var sw = System.Diagnostics.Stopwatch.StartNew();
                        ReadStatic(clientvariables, clienttimespanTS);
                        sw.Stop();
                        double elap    = sw.Elapsed.TotalMilliseconds;
                        string logtext = "Clients: " + clients + " Duration: " + elap;
                        System.Console.WriteLine(logtext);
                        try
                        {
                            outputfile.WriteLine(clients + "\t" + elap);
                        }
                        catch (System.ObjectDisposedException) { }
                    }
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    GC.Collect();
                    telemetry.CollectVariableRunTelemetry(clients);
                    clients += clientinc;
                    if (clients > maxclients)
                    {
                        break;
                    }
                    System.Threading.ThreadPool.GetAvailableThreads(out int awt, out int acpt);
                    System.Console.WriteLine("Available: " + awt + " IO: " + acpt);
                    while (clientlist.Count <= clients)
                    {
                        System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(ReadStaticC))
                        {
                            IsBackground = false
                        };
                        Params a = new Params(clientvariables, clienttimespanTS);
                        t.Start(a);
                        clientlist.Add(t);
                        //System.Threading.Thread.Sleep(500);
                    }
                    System.Threading.ThreadPool.GetAvailableThreads(out int awt2, out int acpt2);
                    System.Console.WriteLine("After increase Available: " + awt2 + " IO: " + acpt2);
                    System.Threading.Thread.Sleep(2000);
                    try { outputfile.WriteLine("New Client count: " + clients + "\t"); }
                    catch (System.ObjectDisposedException) { }
                    System.Threading.Thread.Sleep(5000);
                }
                System.Console.WriteLine("ClientList.Count: " + clientlist.Count);
                foreach (var th in clientlist)
                {
                    if (!th.IsAlive)
                    {
                        System.Console.WriteLine("Client not alive");
                    }
                }
                Running = false;
                foreach (var t in clientlist)
                {
                    t.Join();
                }
                telemetry.CloseVMConnection();
            }
            #endregion
        }