Generating dynamic graphs
I'm building a web applicatio开发者_开发百科n in Django and I'm looking to generate dynamic graphs based on the data.
Previously I was using the Google Image Charts, but I ran into significant limitations with the api, including the URL length constraint.
I've switched to using matplotlib to create my charts. I'm wondering if this will be a bad decision for future scaling - do any production sites use matplotlib? It takes about 100ms to generate a single graph (much longer than querying the database for the data), is this simply out of the question in terms of scaling/handling multiple requests?
You may be able to scale matplotlib for charting if you can render the charts outside the request/response cycle with something like Celery. You would have to manage the storage of the rendered chart as well as invaliding it when the data changes. This would really depend on how often the data changes and how often it is viewed.
However, I tend to stick with client-side libraries for graphing such as either jqplot or highcharts.
For this kind of functionality you should look into message queues, ZeroMQ for instance. This allows you to use async graph generation that doesn't block web server processes (if implemented correctly).
If performance is such an issue and you don't need fancy graphs, you may be able to get by with not creating images at all. Render explicitly sized and colored divs for a simple bar chart in html. Apply box-shadow and/or a gradient background for eye candy.
I did this in some report web pages, displaying a small 5-bar (quintiles) chart in each row of a large table, with huge speed and almost no server load. The users love it for the early and succinct feedback.
Using canvas and javascript you could improve on this scheme for other chart types. I don't know if you could use Google's charting code for this without going through their API, but a few lines or circle segments should be easy to paint yourselves if not.
精彩评论