private void WriteDataSet() { TimeSpan ts = TimeSpan.Parse(maxtimespan); TimeSpan ts2 = TimeSpan.Parse(variabletimespan); TimeSpan ts3 = TimeSpan.Parse(clienttimespan); double max_ts = Math.Max(ts.TotalSeconds, Math.Max(ts2.TotalSeconds, ts3.TotalSeconds)); double t_add = (double)1 / writefrequency; int iterat = (int)(max_ts / t_add); int max_v = Math.Max(maxvariables, clientvariables); var sw_one = new System.Diagnostics.Stopwatch(); DateTime time = DateTime.UtcNow; time = time.Subtract(new TimeSpan(0, 0, (int)max_ts)); var org_time = time; adapter.SetStartTime(time); System.Console.WriteLine("Write data for: " + max_v + " over " + max_ts + " seconds"); for (int i = 0; i < iterat; i++) { try { adapter.PrepareWriteDataWithTime(max_v, time); adapter.Send(ref sw_one); } catch (System.Exception e) { System.Console.WriteLine(e.Message); i--; continue; } if (i != (iterat - 1)) { time = time.AddSeconds(t_add); } } System.Console.WriteLine("Data written"); DateTime endtime = DateTime.UtcNow; adapter.SetNowTime(endtime); var t = System.DateTime.Now.Add(filltime); while (t.Subtract(System.DateTime.Now).TotalSeconds > 0) { try { adapter.PrepareWriteData(max_v); adapter.Send(ref sw_one); System.Threading.Thread.Sleep(900); } catch (System.Exception e) { continue; } } if (filltime.TotalSeconds == 0) { System.Console.WriteLine("Start waiting"); adapter.PrepareWriteDataWithTime(max_v, time); System.Threading.Thread.Sleep(60000); while (true) { bool x = adapter.CheckInsert(); if (x) { break; } System.Threading.Thread.Sleep(1); } } }
public void Produce(object arg) { Params p = (Params)arg; using (produce_outputfile = new System.IO.StreamWriter(p.Path + "\\produce.txt")) { produce_outputfile.WriteLine("Database: " + Program.Database + "\t Variables: " + p.Variables + "\t Iterations: " + p.Iterations + "\t WriteFrequency: " + p.writefrequency + "\t InitIterations: " + p.inititerations); produce_outputfile.WriteLine("Insert duration\tFinal duration\tRead back\tSpeed"); telemetry_p = new Telemetry(Program.VmName, p.Path, p.Variables, adapter); telemetry_p.InitTelemetryCollection("produce"); System.Diagnostics.Stopwatch onevariable_watch = new System.Diagnostics.Stopwatch(); var w_mock = new System.Diagnostics.Stopwatch(); int sleep = (int)((1.0f / (double)p.writefrequency) * 1000); while (p_mRunning) { System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); var startime = System.DateTime.Now; var endtime = startime.Add(p.timeSpan); while (System.DateTime.Now.Subtract(endtime).TotalSeconds <= 0) { if (!p_mRunning) { break; } sw.Restart(); adapter.PrepareWriteData(p.Variables); adapter.Send(ref onevariable_watch); sw.Stop(); int wait = sleep - (int)sw.ElapsedMilliseconds; if (wait > 0) { System.Threading.Thread.Sleep(wait); } } while (p.Variables < max_var) { var percent = p.Iterations / 100; for (int j = 0; j < p.Iterations; j++) { if (!p_mRunning) { break; } sw.Restart(); if (p.writefrequency > 1) { for (int i = 1; i < p.writefrequency; i++) { var st0 = System.Diagnostics.Stopwatch.StartNew(); adapter.PrepareWriteData(p.Variables); adapter.Send(ref w_mock); double elap0 = st0.Elapsed.TotalSeconds; int wait0 = sleep - (int)(elap0 * 1000); if (wait0 > 0) { System.Threading.Thread.Sleep(wait0); } } } adapter.PrepareWriteData(p.Variables); adapter.Send(ref onevariable_watch); var check1 = sw.Elapsed.TotalSeconds; while (true) { bool x = adapter.CheckInsert(); if (x) { break; } if (!p_mRunning) { break; } } onevariable_watch.Stop(); sw.Stop(); double elap = sw.Elapsed.TotalSeconds; float speed = (float)(p.Variables / elap); try { produce_outputfile.WriteLine(check1 + "\t" + elap + "\t" + onevariable_watch.Elapsed.TotalSeconds + "\t" + speed); } catch (System.ObjectDisposedException) { } onevariable_watch.Reset(); if (j % percent == 0) { System.Console.WriteLine("Producer: " + j / percent + "% progress"); } int wait = sleep - (int)sw.ElapsedMilliseconds; if (wait > 0) { System.Threading.Thread.Sleep(wait); } } if (p_mRunning) { p.Variables += increament; //Increase updated variable count telemetry_p.CollectVariableRunTelemetry(p.Variables); if (p.Variables >= max_var) { p_mRunning = false; break; } try { produce_outputfile.WriteLine("New Variable count: " + p.Variables + "\t"); } catch (System.ObjectDisposedException) { } } } p_done = true; System.Console.WriteLine("Producer iterations finished"); telemetry_p.CollectVariableRunTelemetry(p.Variables); telemetry_p.mRunning = false; produce_outputfile.Flush(); produce_outputfile.Close(); produce_outputfile.Dispose(); System.Console.WriteLine("Producer start fill"); while (p_mRunning) { sw.Restart(); adapter.PrepareWriteData(p.Variables); adapter.Send(ref onevariable_watch); sw.Stop(); int wait = sleep - (int)(sw.ElapsedMilliseconds); if (wait > 0) { System.Threading.Thread.Sleep(wait); } } System.Console.WriteLine("Producer fill finished"); break; } System.Console.WriteLine("Producer ending"); } }
public static bool CheckInsert() { return(adapter.CheckInsert()); }