I'm observing severe performance issues with the following scenario and despearately seeking some help
I have a TimeSeriesCollection with a number of time series in it, which is being added every second a number of data points. In general the data points are sorted by time.
I'm using XYPlot with an XYLineAndShapeRenderer for some of the timeseries and XYLineAndShapeRenderer for others, in total, on the same chart there are 7 graphs corresponding to these timeseries instances. The chart is showing a range of between 5 minutes to 8 hours (rolling). When profiling this, I see most time is spent in iterateToFindDomainBounds, iterateToFindRangeBounds in DatasetUtilities.
To illustrate:
Code: Select all
val ds1= new TimeSeriesCollection
val ds2= new TimeSeriesCollection
val ds3= new TimeSeriesCollection
val ds4= new TimeSeriesCollection
val ds5= new TimeSeriesCollection
val yAxis = new NumberAxis(name)
yAxis.setAutoRangeIncludesZero(false)
val plot = new XYPlot
plot.setDomainAxis(new DateAxis("Time"))
val noLinesRenderer = new XYLineAndShapeRenderer(false, true)
noLinesRenderer.setSeriesShape(0, new Ellipse2D.Double(-2.0, -2.0, 4.0, 4.0))
noLinesRenderer.setBaseShapesFilled(false)
val someRenderer1 = new XYLineAndShapeRenderer(false, true) {
...
}
someRenderer1.setSeriesPaint(0, Color.BLUE)
...
val xyStepRenderer = new XYStepRenderer
xyStepRenderer.setSeriesPaint(0, Color.GRAY)
xyStepRenderer.setSeriesPaint(1, Color.RED)
xyStepRenderer.setSeriesPaint(2, Color.GREEN)
xyStepRenderer.setSeriesPaint(3, Color.BLUE)
xyStepRenderer.setSeriesPaint(4, Color.BLACK)
plot.setRenderer(0, xyStepRenderer)
plot.setRenderer(1, noLinesRenderer)
plot.setRenderer(2, someRenderer1)
plot.setRenderer(3, someRenderer2)
plot.setRenderer(4, someRenderer3)
plot.setRangeAxis(yAxis)
plot.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT)
plot.setDataset(0, ds1)
plot.setDataset(1, ds2)
plot.setDataset(2, ds3)
plot.setDataset(3, ds4)
plot.setDataset(4, ds5)
val ch = new ChartPanel((new JFreeChart(plot)))
Then every second (up to 5 times a second) whenever updates are received for a dataset I do the following:
def addDataPoint(dataset: TimeSeriesCollection, time: FixedMillisecond, key: String, value: Double, notify: Boolean) = {
val ts = getOrAddTimeSeries(dataset, key)
Try(ts.add(time, value, notify)) match {
case Failure(e) => ts.addOrUpdate(time, value)
case _ =>
}
}
relatively quickly the cpu goes to 3-4% and later to 10% and more and the ui becomes unresponsive, whenever there are more updates to the chart.
Any idea why this is so inefficient or how I can improve it?
Thanks,
D