我在 RHEL5 上遇到了 Time::HiRes 的非常奇怪的行为。由于 Time::HiRes 位于 Perl 标准安装中,并且基本上是 gettimeofday 系统调用的包装器,因此我倾向于将问题归咎于操作系统,而不是模块,甚至是 perl。
这是我的示例代码:
#!/usr/bin/perl
use Time::HiRes;
use LWP::Simple;
for (1..10) {
my $started = [Time::HiRes::gettimeofday];
# do something that we can expect to take time, but not too much time
my $throwaway = get("http://localhost/");
my $elapsed = Time::HiRes::tv_interval($started);
print "$elapsed\n";
sleep(1);
}
在我的 Mac 上运行此程序得到了完全合理的结果:
0.025934
0.000642
0.000716
0.001003
0.001026
0.000733
0.000815
0.000646
0.000629
0.000793
但在我的 RHEL5 服务器上运行却产生了不合理的结果:
0.034182
0.015998
0.06415
0.015523
-0.000379
0
0
0
0
0
特别注意第五个结果!
为了以防万一,以下是服务器上 perl -V 的结果:
Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
Platform:
osname=linux, osvers=2.6.18-92.1.6.el5, archname=i686-linux
uname='linux 188186.sexton.article7.co.uk 2.6.18-92.1.6.el5 #1 smp fri jun 20 02:36:16 edt 2008 i686 athlon i386 gnulinux '
config_args='-des -Dprefix=/usr/local'
hint=previous, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2',
cppflags='-fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/local/include -fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
ccversion='', gccversion='4.1.2 20071124 (Red Hat 4.1.2-42)', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldl -lm -lcrypt -lutil -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
libc=/lib/libc-2.5.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.5'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: PERL_MALLOC_WRAP USE_LARGE_FILES USE_PERLIO
Built under linux
Compiled at Sep 15 2008 15:05:12
@INC:
/usr/local/perl/5.8.8/lib/5.8.8/i686-linux
/usr/local/perl/5.8.8/lib/5.8.8
/usr/local/perl/5.8.8/lib/site_perl/5.8.8/i686-linux
/usr/local/perl/5.8.8/lib/site_perl/5.8.8
/usr/local/perl/5.8.8/lib/site_perl
.
这是一个已知问题吗?非常感激接受任何想法。
答案1
答案2
您的系统速度如此之快,以至于在负时间内返回结果,您难道不为此感到高兴吗?:) 玩笑归玩笑,我们在虚拟化环境中遇到了 RHEL5 奇怪的时钟漂移问题;这与您的问题有关吗?