|
Zoomable chart |
Posted by Em on Mar-19-2012 07:24 |
|
When I zoom in and zoom out on zoomable chart (phpdemo/zoomscrolldemo.php), there is latency. What's the deciding factor for this latency? For my chart which I copied the implementation of zoomscrolldemo.php, this latency is 3 seconds, that's too much, I am trying to reduce it. |
Re: Zoomable chart |
Posted by Peter Kwan on Mar-19-2012 22:05 |
|
Hi Em,
When I tried the original "zoomscrolldemo.php" without modification in a computer with a server connected directly using LAN, the zooming and scrolling is quite fast. It should be less than 1 second.
There are many reasons for latency. The followings are some possibilities:
(a) The network is slow. It takes 2 HTTP requests to update the HTML and the image part of the chart when zoomed in. If the network requires 1 second for a HTTP transaction, just the network delay will be 2 seconds.
(b) The server is slow.
(c) If your actual code is using a database, the database can be slow if you have lots of data.
(d) The image map creates too much overhead. The image map is for making the chart clickable and to provide tooltips. If you have a large number of data points, the image map can consume much more resources than the chart itself. For example, ChartDirector can plot a chart with 20000 points very quickly, but the image map for 20000 points (with 20000 tooltips and 20000 clickable region definitions) can reach something like 2MB, which would be a significant overhead to the network and to the server. The original zoomscrolldemo.php will use data compression to reduce the image map size. This reduces the network overhead, but increases the CPU overhead to compress the data.
To check if the problem is related to the image map, you may consider to disable the image map (remove the line that calls getHTMLImageMap) to see if it makes any difference.
(e) The browser can become slow if there are too many tooltips and hot spots. If this is the case, removing the image map would make the browser much faster.
To diagnose the problem in detail, you may log the timestamp in each part of the code, and include them as part of the chart so that you can see them. One method I often used is like (in PHP):
$startTime = microtime();
... draw chart as usual ...
#make the chart and the image map
$c->makeChart3();
$imageMap = $c->getHTMLImageMap(....);
#now we can have the time required to generate the chart and the image map
$endTime = microtime();
#include the startTime and endTime as a custom text in the chart
$t = $c->addText(0, 0, $startTime + ", " + $endTime);
$t->setBackground(0xffff00);
#now remake the chart again to actually draw the startTime and endTime on the chart
$chartQuery = $c->makeSession($viewer->getId());
#output chart as usual
$viewer->setImageUrl(........);
$viewer->setImageMap(........);
$viewer->setChartMetrics(........);
With the above method, you can see the time used between $endTime and $startTime. By moving these two lines in your code, you can measure the database overhead, charting overhead, image map overhead, etc.. If you find that the overhead is quite small, but the latency is large, it may not be caused by the code or the server, but by the network.
Also, for testing, it is suggested you use a fast and idle server. If the server itself is very busy, it is hard to know the latency is due to the charting code, or due to the server being too busy.
One you have identify where is the cause of the latency, we can find ways to try to improve it.
Hope this can help.
Regards
Peter Kwan |
|