views:

176

answers:

3

I have a Perl script that runs via a system() command from C. On a specific site (SunOS 5.10), when that script is run, it nearly always takes 6 seconds or more. On other sites, it runs pretty much instantly (0.1s). If I run the script manually, i.e. not from the C code, it also runs instantly. I eventually tracked the slowness down (by spitting out the time a whole bunch in a lot of different places), to a single require line. The file that it is requiring is another Perl script we wrote. The script consists of a single require (this file here), 3 scalars that are assigned integer values, and a handful of time/date conversion routines. The file ends with a 1;. That single require appears to take as much as 6 seconds on occasion, but as I said, not always even on the same machine. I'm absolutely stumped here. My only last thought is to turn on profiling, but the site doesn't have Devel::Profiler and my only other option (that I know of) would be to add it to the Perl command which would require me altering and recompiling the C code (doable but non-trivial).

Anybody have ANY idea what could be going on here? I don't think I can/want to put the entire date.pl that is being required, but it's pretty much exactly as I described; I could answer any questions about it that you have.

Thanks in advance.

+3  A: 

Six seconds is a long time. Have you checked what your network is doing during this? My first thought was that spawning the new process when using the system() command could be the problem, but six seconds is too long. I don't know much about perl, but I could imagine that for any reason, the access of the time module could invoke a call to a network time server. Just to get synchronized. Maybe this takes so long or maybe it is getting a time out. It could be that this only happens for a newly spawned process -- hence only when you use the system() command.

just wild guessing...

Ralf
Those are definitely some good thoughts, however the time that is spit out before the require matches the time that is spat out by the C app, which means that the system() command itself isn't taking long, it's just somehow altering the setup used when the script is run.
Morinar
I'll double check the network ideas though... unsure what it could be accessing, but seems reasonable.
Morinar
This seems reasonable to check: `require` will search all of `@INC` so, depending on what directories precede the one in which your file is finally found, it may take a very long time.
ephemient
Very wild stab in the dark: any of the directories in `@INC` on a network drive that might be unavailable?
jk
An automounter, even?
tsee
That all seems quite likely, but the `@INC` looks pretty straight forward and clean. No network should be hit at all as far as I can tell.
Morinar
+5  A: 

You might be interested in A Timely Start by Jean-Louis Leroy. He had a similar problem and tracked it down to a long and deep module search path where perl usually found the modules in the last entries in @INC.

brian d foy
That's a great article; thanks for the link. My @INC isn't anywhere even close to as big as what he had, but that all still seems semi-feasible.
Morinar
+1  A: 

So, this does nothing to answer your question directly, but please tell me that you're not actually running on perl 4? Assuming you're on perl 5, you could remove the entire file and replace the require with use POSIX qw(ctime) to get the version that comes with Perl.

If you do have to support perl4, I'll merely grumble something about version 5 being fifteen years old now and go away. :)

hobbs
We're not actually *running* Perl4, but the vast majority of our Perl code literally is over 15 years old. While a few of us new timers who have modern Perl skills have started converting things to Perl5 standards, most of the people here don't even know the difference. That is definitely a great tip though; I'll probably end up doing that regardless.
Morinar