Home > Fluid Dynamics Search Engine > Help > 1113

How to display how long a search took

You can use the Perl times() function to show how long the search process took.

To do this, edit the script "search.pl" or "search.cgi" and find the lines that look like this:

print $Ads[2];
print &str_search_form($::const{'search_url'}) if ($::Rules{'ui: search form display'} > 1);
print $Ads[3];

(Code sample taken from FDSE v2.0.0.0071; the exact text of this anchor code may vary from version to version.)

This is at the very tail end of the search output. Replace that code with:

print $Ads[2];
print &str_search_form($::const{'search_url'}) if ($::Rules{'ui: search form display'} > 1);

my ($real_time, $user_time, $sys_time) = (time() - $::private{'script_start_time'}, times());
print "<P>User time: $user_time : system time: $sys_time : real time: $real_time.</P>\n";

print $Ads[3];

The output of your script will look like this:

Search output with times displayed

Note that on some Windows systems, times is not implemented or does not return valid data. On *NIX and with modern versions of Windows Perl, however, the times function can be trusted.

What is user time and system time? User time is the CPU usage time by a program running in user state (i.e. in a loop or a local function call with its Perl code) while system time is CPU usage by some lower-level system routine (i.e. opening a file or starting a process). If a Perl script opens a file and tests each line for a pattern, the act of opening the file is delegated to the system, and the more resource-intensive act of pattern matching each line is handled in user mode. FDSE should spend most of its time in user mode. If the sum of the user time and system time values is approximately equal to the total elapsed time, then that means that the server is devoting its entire resources to FDSE. If the total real elapsed time greatly exceeds the sum of the CPU time, then that means that FDSE is being made to wait, perhaps for access to shared files, or for network traffic to complete, or for other processes sharing the same CPU to finish.

The times function can also return the user and system times of child processes. FDSE generally does not use child processes. It will use them if xpdf is installed for indexing PDF files, and it will sometimes call sendmail as a child process for sending mail. Both tasks happen in admin mode only, and even then very rarely, so they are not included as part of the code sample above.

The times function does not measure the CPU work done by other processes that FDSE may call. If FDSE is configured to use mysql for searches, then the mysql CPU time will be handled by the mysql daemon and will not show up the times report.

Thanks to Ian Dobson for contributing this solution on the Discussion Forum; thank to Michael Schröpl for explaining user and system times.

    "How to display how long a search took"