Fine tuning:
The site was becoming quite popular and I was concerned about performance.
Again two possible approaches - throw more CPU power at it, or tune everything to the edge first.
Adding CPU power does not usually solve the problem. It's been stated that development of the algorithms in the past 50 years has done more for speeding up computations than increasing raw power in the same time. And according to Moore's Law raw power had increased millions of times during that period.
Here is a list of optimization tricks I've used, in no particular order:
Everything is cached, at few levels.
Every computed track is stored in a database as numerical data, and reused for subsequent display at different zoom levels. Few boats in the same position will also share the data - this works only at the start.
The rendered png files are also stored in disk cache and served as static content if needed.
Carefully adjusted HTTP expiration headers switch the caching from server to client, further reducing CPU and bandwidth, and make the interactive response really smooth for the wind animation.
Some part of the work is done with client-side javascript - turning friends on and of and the wind display.
But not too much client-side javascript, as it tends to become sluggish at some point, as with the google maps api. Also no standard js libraries like prototype or jquery. They make the life of the developer easier at the price of slower performance. The code is self-contained in one 1000-line file.
Fast and light HHTP server. Apache tends to eat a lot of memory and CPU, and is not the best choice for loaded sites. I have used lighttpd, but there are other alternatives too.
The performance problem during Leg 7, described in the
About page was caused partly by lack of locking of the chart data. When everyone hit the reload button at 11:02 the site did not respond for some time, and then everyone wold hit reload again, adding new tasks to process. Adding some locking logic that prevents the same data being processed twice and that helped the response time to acceptable 20-30 seconds even during peak time.