[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qexo-general] Speed of execution
From: |
Eric Safern |
Subject: |
Re: [Qexo-general] Speed of execution |
Date: |
Sun, 19 Jan 2003 15:07:10 -0800 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2a) Gecko/20020910 |
Per Bothner wrote:
Eric Safern wrote:
With the full linux fortune data as its input (> 100,000 lines), the
servlet takes 4 - 7 seconds on my test box, which strikes me as too long
for an impatient web surfer. On a far smaller subset of data (4,000
lines), response time comes in at 1 - 2 seconds, which is still longer
than I'd like.
Are you using a servlet? My guess is that the 1-2 seconds is
start-up time, and using a servlet can help with that, if you're
not already using it.
If you *are using a servlet, then the next step may be to pre-calculate
document("/var/www/html/fortunes.xml")/fortunes/address@hidden/cookie
for each $type, assuming there is only a small number of types. You
could either save this in separate files, or do this pre-calculation
at server init type. (The latter requires some Java programming,
or at least some Scheme programming, since I don't think you can
(currentlty do it in XQuery). Or just pre-read the
document("/var/www/html/fortunes.xml") in the server init
code.
Well, before I spent too much time on coding, I ran a simple test to
see if the optimization would help - and it didn't seem to make much
difference.
Here's what I did. The current code loads a block of fortunes of a
given type,
counts them, then generates a random number between 1 and (count), then
selects a specific fortune.
$cookies :=
document("/var/www/html/fortunes.xml")/fortunes/address@hidden/cookie,
$min := 1,
$max := count($cookies)
return $cookies [ Rand($min,$max) ]
Per's suggestion is to pre-calculate the counts for the different types,
so that
we can generate a random number between one and $count, and load only
one fortune -
the specific one we wish to display. So, as a test, I tried zeroing in
on a specific fortune -
the fifth one (in my input data, no fortune type has less than 5
fortunes, so this should be
safe for testing).
$cookies :=
document("/var/www/html/fortunes.xml")/fortunes/address@hidden/cookie[5],
return $cookies
Note this test should run *faster* than the final code - I'm not loading
the count data, or
generating the random number.
Unfortunately, it takes more or less the same time (six to eight
seconds) to run the
servlet and display the results. That is, of course, the time for the
second and subsequent
runs - the first time is much longer, for obvious reasons.
So it doesn't seem like changing the algorithm will help much. Am I
missing something?
I'm not sure I understood your final suggestion. If I pre-read the
entire document in the server
init code, can I tell XQuery to run the query against the document *in
memory*? How
would that work?
Thanks,
Eric Safern