XYPlot performance issue (iterateToFindDomainBounds,iterate

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
dereal
Posts: 4
Joined: Wed Mar 18, 2015 7:44 pm
antibot: No, of course not.

XYPlot performance issue (iterateToFindDomainBounds,iterate

Post by dereal » Wed Mar 18, 2015 8:05 pm

Hello,

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 _ =>
    }
  }
I try not to notify until I add the last item to the dataset but I don't think it helps so maybe I misunderstand the api.

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

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: XYPlot performance issue (iterateToFindDomainBounds,iter

Post by paradoxoff » Thu Mar 19, 2015 1:46 pm

This is Scala, right? Unfortunately, I am not familiar with it.
It seems that if the call to timeSeries.add() throws an exception, you are using ts.addOrUpdate(), and this will always fire a SeriesChangeEvent, which should in the end call the DatasetUtilities methods you mentioned.
How often the above timeSeries call fails or succeeds, is not clear from the code snippet you have posted.

dereal
Posts: 4
Joined: Wed Mar 18, 2015 7:44 pm
antibot: No, of course not.

Re: XYPlot performance issue (iterateToFindDomainBounds,iter

Post by dereal » Thu Mar 19, 2015 2:07 pm

Scala indeed. The call to add fails rarely, most of the the time it succeeds, but either way, at each cycle after adding the data to all timeseries I call add with notify=true once to refresh the chart. I've tried changing to only notify once every 2 seconds which seems to have imrproved performance, but my concern is that whenever add is called with notify true, its performance depends on the number of elements in the dataset which after a few hours may be quite big which has significant negative impact on performance.

Thanks,
D.

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: XYPlot performance issue (iterateToFindDomainBounds,iter

Post by paradoxoff » Fri Mar 20, 2015 5:07 pm

And how often dou you make the call with notify true? You are right that this will trigger a series of change event which finally lead to a repaint of the chart. In this context, the mentioned DatasetUtilities method will be called. This method determines the smallest and largest value in the dataset to calculate a suitabale range for the respective axis.
However, I am surprised to see that these methods are called at all. You are apparently using a TimeSeriesCollection, and this dataset implements the XYRangeInfo interface. If the DatasetUtilities method has to handle an XYDataset of this type, it does not call the various iterate Methods, but simply retrieves the bounds from the dataset.
Can you show a larger piece of code?

dereal
Posts: 4
Joined: Wed Mar 18, 2015 7:44 pm
antibot: No, of course not.

Re: XYPlot performance issue (iterateToFindDomainBounds,iter

Post by dereal » Fri Mar 20, 2015 6:02 pm

previously I was making the call with true at least once a second, but up to 5 times per second, now I've changed it to be called onces every two seconds to repaint. You're right about TimeSeriesCollection implementing XYRangeInfo, just that it does on current version 1.0.19 where we're using 1.0.13 where it doesn't. Sounds like an upgrade would make this issue go away?

Thanks,
D.

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: XYPlot performance issue (iterateToFindDomainBounds,iter

Post by paradoxoff » Fri Mar 20, 2015 7:15 pm

Yep, an upgrade might help indeed.

dereal
Posts: 4
Joined: Wed Mar 18, 2015 7:44 pm
antibot: No, of course not.

Re: XYPlot performance issue (iterateToFindDomainBounds,iter

Post by dereal » Fri Mar 20, 2015 7:17 pm

ok, will try. Thanks for your help!

Locked