Satya's blog - Blog optimisations
The blog software I use
has been taking too long to generate my blog. So I optimised it a little.
Background: Each entry is kept as a text file. The files are kept in directories. The software runs through each directory and processes each file and produces HTML pages. At the end it also produces a database from which the tag directory works and the dynamic tag-based RSS feeds can be generated on demand. Each file processed opens an HTML::Template instance which opens and processes a template from disk. This is resource-intensive. Reading the docs, I found several cache options one of which is blind_cache. Setting this option caches the parsed template in memory, so the template module doesn't re-open and re-parse the file for each blog entry. At the end, the program creates a new SQLite database file and runs SQL INSERT statements -- a new query for each blog entry. Of course the statement handle is re-used but it still takes time. Googling (well, I used Amazon's A9 this time) for sqlite optimizations got me a recommendation to use BEGIN TRANSACTION and END TRANSACTION before and after my flurry of SQL. Without transactions and blind_cache: 15 wallclock secs ( 6.25 usr + 0.21 sys = 6.46 CPU) With transactions and HTML::Template's blind_cache: 3 wallclock secs ( 2.03 usr + 0.16 sys = 2.19 CPU) |
|