protected void scheduleViewTask(long eventId) { if (minViewAfterInsert <= 0 || maxViewAfterInsert <= 0) return; int delay = (minViewAfterInsert + random.Next(maxViewAfterInsert - minViewAfterInsert)); // implement warp-drive... if (timingSpeedup > 1) delay = (int)(delay / timingSpeedup); EventViewTask viewEvent = new EventViewTask(this, eventId); //queryExecutor.schedule(new EventViewTask(this, eventId), (long) delay, TimeUnit.SECONDS); queryExecutor.schedule(viewEvent, delay * Millis); appLog.info("Scheduled EventViewTask for now+{0}", delay); }
/** * Start the controller. * * @throws InterruptedException */ public void run() { long start = wallTimer.ElapsedMilliseconds; long endTime = start + runTime; long now; double currentRate = 0.0; long averageSleep = (long) (Millis2Seconds / averageRate); totalEvents = 0; wallTimer.Start(); double burstRate = 0.0; int burstSize = 0; // ensure that first sample time is different from start time... int settleTime = 2 * Millis; appLog.info("Settling for {0}: ", settleTime); Thread.Sleep(settleTime); // just run some queries if (queryOnly) { appLog.info("Query-Only..."); long eventId = 1; while (wallTimer.ElapsedMilliseconds < endTime) { EventViewTask viewTask = new EventViewTask(this, eventId++); //queryExecutor.schedule(new EventViewTask(this, eventId++), 2, TimeUnit.MILLISECONDS); queryExecutor.schedule(viewTask, 2); totalEvents++; double wallTime = (1.0 * wallTimer.ElapsedTicks) / Stopwatch.Frequency; double queryTime = (1.0 * totalQueryTime) / Stopwatch.Frequency; appLog.info("Processed {0:N} events containing {1:N} records in {2:F2} secs" + "\n\tThroughput:\t{3:F2} events/sec at {4:F2} ips;" + "\n\tSpeed:\t\t{5:N} inserts in {6:F2} secs = {7:F2} ips" + "\n\tQueries:\t{8:N} queries got {9:N} records in {10:F2} secs at {11:F2} qps", totalEvents, totalInserts, wallTime, (totalEvents / wallTime), 0, totalInserts, 0, 0, totalQueries, totalQueryRecords, queryTime, (totalQueries / queryTime)); //if (((ThreadPoolExecutor) queryExecutor).getQueue().size() > 10) { if (totalEvents + 10 > totalQueries) { appLog.info("{0} queries waiting - sleeping", totalEvents - totalQueries); Thread.Sleep(200); } } return; } do { EventGenerator generator = new EventGenerator(this, unique++); //insertExecutor.execute(new EventGenerator(this, unique++)); insertExecutor.execute(generator); totalEvents++; //int queueSize = ((ThreadPoolExecutor) insertExecutor).getQueue().size()); //Int64 queueSize = totalScheduled - totalEvents; long queueSize = insertExecutor.QueueSize(); appLog.info("Event scheduled. Queue size={0}", queueSize); now = wallTimer.ElapsedMilliseconds; currentRate = (Millis2Seconds * totalEvents) / (now - start); appLog.info("now={0}; endTime={1}; elapsed={2}; time left={3}", now, endTime, now - start, endTime - now); // randomly create a burst if (burstSize == 0 && burstProbability > 0 && Percent * random.NextDouble() <= burstProbability) { burstSize = minBurst + random.Next(maxBurst - minBurst); appLog.info("Creating burst of {0}", burstSize); } if (burstSize > 0) { burstSize--; } else { if (averageRate > 0) { int sleepTime = (int) (averageSleep * (currentRate / averageRate)); if (now + sleepTime > endTime) sleepTime = 1 * Millis; appLog.info("Current Rate= {0:F2}; sleeping for {1:N} ms", currentRate, sleepTime); if (timingSpeedup > 1) { sleepTime = (int)(sleepTime / timingSpeedup); appLog.info("Warp-drive: speedup {0:F}; sleeping for {1} ms", timingSpeedup, sleepTime); } Thread.Sleep(sleepTime); } //queueSize = ((ThreadPoolExecutor) insertExecutor).getQueue().size(); //queueSize = totalScheduled = totalInserts; while (maxQueued >= 0 && insertExecutor.QueueSize() > maxQueued) { //queueSize = totalScheduled = totalInserts; queueSize = insertExecutor.QueueSize(); appLog.info("Queue size {0} is over limit {1} - sleeping", queueSize, maxQueued); Thread.Sleep(1 * Millis / (queueSize > 1 ? 2 : 20)); if (insertExecutor.QueueSize() > maxQueued) { appLog.info("Queue still has {0} items; there are {1} active SqlSessions", insertExecutor.QueueSize(), SqlSession.activeSessions()); } } // queueSize = ((ThreadPoolExecutor) insertExecutor).getQueue().size(); //queueSize = totalScheduled - totalInserts; queueSize = insertExecutor.QueueSize(); appLog.info("Sleeping done. Queue size={0}", queueSize); } //wallTime = Environment.TickCount - start; double wallTime = 1.0 * wallTimer.ElapsedTicks / Stopwatch.Frequency; double insertTime = (1.0 * totalInsertTime) / Stopwatch.Frequency; double queryTime = (1.0 * totalQueryTime) / Stopwatch.Frequency; appLog.info("Processed {0:N0} events containing {1:N0} records in {2:F2} secs" + "\n\tThroughput:\t{3:F2} events/sec at {4:F2} ips;" + "\n\tSpeed:\t\t{5:N0} inserts in {6:F2} secs = {7:F2} ips" + "\n\tQueries:\t{8:N0} queries got {9:N} records in {10:F2} secs at {11:F2} qps", totalEvents, totalInserts, wallTime, (totalEvents / wallTime), (totalInserts / wallTime), totalInserts, (insertTime), (totalInserts / insertTime), totalQueries, totalQueryRecords, totalQueryTime, (totalQueries / queryTime)); } while (wallTimer.ElapsedMilliseconds < endTime); }