Topic: Advice for speed

Hello,

For the record, I am brand new to Ruby and web development in general.  I am running a webpage based on a ruby script embedded in html.  There are four graphs of data (amcharts) on the page, and each is driven by its own script, for log file parsing and graph building.  The scripts each take about 2-3 seconds just to initialize:

#!/usr/bin/ruby -w
require 'cgi'
require 'erb'
require 'rexml/document'
include REXML

With about 8 scripts running, this means the page takes over 16 seconds to load, and this is wayyy too long, considering the data must refresh every minute.  Is there any way to initialize the scripts globally, so I don't have to initialize for each script?  Or is there another way to make this faster (precompiling, perhaps)?

Re: Advice for speed

OK, your scripts will be run serially, and if they are processing log file data to produce the graphs, then it is most likely I/O time that is killing you, not 'initialisation' time.

Do each of the scripts process the same log file to produce the graphs? Are you reading the whole thing 8 times? How big is it? 2 seconds per script might be quite reasonable under the circumstances.

Re: Advice for speed

It parses the log file one time per graph.  I doubt it's an I/O time issue (unless there is a large overhead), because my log file is VERY small, about 10 lines.  I will look into it though, thanks for the tip.

Re: Advice for speed

I used the Time class and determined it is in fact the initialization code I posted that is taking forever, so I'm still at square one.

Re: Advice for speed

Any chance of making it one script with a method that gets called 8 times? Then at least you'd only take the hit of initialisation once...