long maxSize = conf.getLong("perf.maxSize");
int feedBatchSize = conf.getInt("perf.feed.batchsize", 100);
final LinedFileDataProvider dataProvider = new LinedFileDataProvider(inputFile, 0L);
dataProvider.setBatchSize(feedBatchSize);
dataProvider.setDataConsumer(testHandler.consumer);
testHandler.consumer.start();
final long start = System.currentTimeMillis();
Metric metric = null;
String name = "eventCount";
metric = Metrics.newGauge(ZoiePerf.class, name, new GaugeMetric<Long>() {
@Override
public Long value() {
return dataProvider.getEventCount();
}
});
monitoredMetrics.put(name, metric);
name = "amountConsumed";
metric = Metrics.newGauge(ZoiePerf.class, name, new GaugeMetric<Long>() {
@Override
public Long value() {
ZoiePerfVersion ver = ZoiePerfVersion.fromString(testHandler.consumer.getVersion());
return ver.offsetVersion;
}
});
monitoredMetrics.put(name, metric);
name = "consumeRateCount";
metric = Metrics.newGauge(ZoiePerf.class, name, new GaugeMetric<Long>() {
@Override
public Long value() {
long newTime = System.currentTimeMillis();
long newCount = dataProvider.getEventCount();
long timeDelta = newTime - start;
long countDelta = newCount;
if (timeDelta == 0) return 0L;
return countDelta * 1000 / timeDelta;
}
});
monitoredMetrics.put(name, metric);
name = "consumeRateMB";
metric = Metrics.newGauge(ZoiePerf.class, name, new GaugeMetric<Long>() {
@Override
public Long value() {
long newTime = System.currentTimeMillis();
ZoiePerfVersion ver = ZoiePerfVersion.fromString(testHandler.consumer.getVersion());
long newMB = ver.offsetVersion;
long timeDelta = newTime - start;
long mbdelta = newMB;
if (timeDelta == 0) return 0L;
return mbdelta * 1000 / timeDelta;
}
});
monitoredMetrics.put(name, metric);
name = "indexLatency";
metric = Metrics.newGauge(ZoiePerf.class, name, new GaugeMetric<Long>() {
@Override
public Long value() {
long newCount = dataProvider.getEventCount();
String currentReaderVersion = testHandler.queryHandler.getCurrentVersion();
long readerMarker = ZoiePerfVersion.fromString(currentReaderVersion).countVersion;
long countsBehind = newCount - readerMarker;
System.out.println("reader marker: " + readerMarker);
System.out.println("new count: " + newCount);
return countsBehind;
}
});
monitoredMetrics.put(name, metric);
// ConsoleReporter consoleReporter = new ConsoleReporter(System.out);
// consoleReporter.start(5, TimeUnit.SECONDS);
// JmxReporter jmxReporter = new JmxReporter(Metrics.defaultRegistry());
File csvOut = new File("csvout");
csvOut.mkdirs();
CsvReporter csvReporter = new CsvReporter(csvOut, Metrics.defaultRegistry());
// GangliaReporter csvReporter = new
// GangliaReporter(Metrics.defaultRegistry(),"localhost",8649,"zoie-perf");
int updateInterval = conf.getInt("perf.update.intervalSec", 2);
csvReporter.start(updateInterval, TimeUnit.SECONDS);
long maxEventsPerMin = conf.getLong("perf.maxEventsPerMin");
dataProvider.setMaxEventsPerMinute(maxEventsPerMin);
int numThreads = conf.getInt("perf.query.threads", 10);
SearchThread[] searchThreads = null;
if (doSearchTest) {
searchThreads = new SearchThread[numThreads];
for (int i = 0; i < numThreads; ++i) {
searchThreads[i] = new SearchThread();
}
} else {
searchThreads = new SearchThread[0];
}
dataProvider.start();
for (int i = 0; i < searchThreads.length; ++i) {
searchThreads[i].start();
}
ZoiePerfVersion perfVersion = ZoiePerfVersion.fromString(testHandler.consumer.getVersion());
long eventCount;
while ((eventCount = perfVersion.countVersion + 1) < maxSize) {
Thread.sleep(500);
perfVersion = ZoiePerfVersion.fromString(testHandler.consumer.getVersion());
}
dataProvider.stop();
testHandler.consumer.stop();
long end = System.currentTimeMillis();
for (int i = 0; i < searchThreads.length; ++i) {