X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id EBD27D1B4A6 for ; Thu, 4 Dec 2003 21:26:19 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 28396-03 for ; Thu, 4 Dec 2003 17:25:49 -0400 (AST) Received: from lerami.lerctr.org (lerami.lerctr.org [207.158.72.11]) by svr1.postgresql.org (Postfix) with ESMTP id 073D7D1B491 for ; Thu, 4 Dec 2003 17:25:43 -0400 (AST) Received: from lerlaptop-red.iadfw.net ([207.136.3.72]) by lerami.lerctr.org with asmtp (Exim 4.30) id 1AS0yf-0004Vv-85; Thu, 04 Dec 2003 15:25:37 -0600 Date: Thu, 04 Dec 2003 15:25:36 -0600 From: Larry Rosenman To: Vivek Khera , "Matthew T. O'Connor" Cc: pgsql-performance@postgresql.org Subject: Re: autovacuum daemon stops doing work after about an Message-ID: <401840000.1070573136@lerlaptop-red.iadfw.net> In-Reply-To: <16335.42262.196435.193875@yertle.int.kciLink.com> References: <16332.63508.196365.801418@yertle.int.kciLink.com> <1070516326.1455.11.camel@zedora.zeut.net> <2348.66.106.27.14.1070571171.squirrel@matth.zeut.net> <16335.42262.196435.193875@yertle.int.kciLink.com> X-Mailer: Mulberry/3.1.0 (Linux/x86) X-PGP-Info: All other keys are old/dead. X-PGP-Key: 0x3c49bdd6 X-PGP-Fingerprint: D0D1 3C11 F42F 6B29 FA67 6BF3 AD13 4685 3C49 BDD6 MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="==========1B86D33B13306EE04F08==========" X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/102 X-Sequence-Number: 4962 --==========1B86D33B13306EE04F08========== Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline --On Thursday, December 04, 2003 16:20:22 -0500 Vivek Khera=20 wrote: >>>>>> "MTO" =3D=3D Matthew T O'Connor writes: > > MTO> Could this be the recently reported bug where time goes backwards on > MTO> FreeBSD? Can anyone who knows more about this problem chime in, I > know it MTO> was recently discussed on Hackers. > > > Time does not go backwards -- the now and then variables are properly > incrementing in time as you see from the debugging output. > > The error appears to be with the computation of the "diff". It is > either a C programming error, or a compiler error. I'm not a C "cop" > so I can't tell you which it is. > > Witness this program, below, compiled as "cc -g -o t t.c" and the > output here: > > % ./t > seconds =3D 3509 > seconds1 =3D 3509000000 > useconds =3D -452486 > stepped diff =3D 3508547514 > seconds2 =3D -785967296 > seconds3 =3D 3509000000 > diff =3D -786419782 > long long diff =3D 3508547514 > % > > apperantly, if you compute (now.tv_sec - then.tv_sec) * 1000000 all at > once, it overflows since the RHS is all computed using longs rather > than long longs. Fix is to cast at least one of the values to long > long on the RHS, as in the computation of seconds3 below. compare > that to the computation of seconds2 and you'll see that this is the > cause. > > I'd be curious to see the output of this program on other platforms > and other compilers. I'm using gcc 2.95.4 as shipped with FreeBSD > 4.8+. this is with the UnixWare compiler: $ cc -O -o testvk testvk.c $ ./testvk seconds =3D 3509 seconds1 =3D 3509000000 useconds =3D -452486 stepped diff =3D 3508547514 seconds2 =3D -785967296 seconds3 =3D 3509000000 diff =3D -786419782 long long diff =3D 3508547514 $ I think this is a C bug. > > That all being said, you should never sleep less than the base time, > and never for more than a max amount, perhaps 1 hour? > > > --cut here-- ># include ># include > > int > main() > { > struct timeval now, then; > long long diff =3D 0; > long long seconds, seconds1, seconds2, seconds3, useconds; > > now.tv_sec =3D 1070565077L; > now.tv_usec =3D 216477L; > > then.tv_sec =3D 1070561568L; > then.tv_usec =3D 668963L; > > seconds =3D now.tv_sec - then.tv_sec; > printf("seconds =3D %lld\n",seconds); > seconds1 =3D seconds * 1000000; > printf("seconds1 =3D %lld\n",seconds1); > useconds =3D now.tv_usec - then.tv_usec; > printf("useconds =3D %lld\n",useconds); > > diff =3D seconds1 + useconds; > printf("stepped diff =3D %lld\n",diff); > > /* this appears to be the culprit... it should be same as seconds1 */ > seconds2 =3D (now.tv_sec - then.tv_sec) * 1000000; > printf("seconds2 =3D %lld\n",seconds2); > > /* seems we need to cast long's to long long's for this computation */ > seconds3 =3D ((long long)now.tv_sec - (long long)then.tv_sec) * 1000000; > printf("seconds3 =3D %lld\n",seconds3); > > > diff =3D (now.tv_sec - then.tv_sec) * 1000000 + (now.tv_usec - > then.tv_usec); printf ("diff =3D %lld\n",diff); > > diff =3D ((long long)now.tv_sec - (long long)then.tv_sec) * 1000000 + > (now.tv_usec - then.tv_usec); printf ("long long diff =3D %lld\n",diff); > > exit(0); > } > > > --cut here-- > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) > --=20 Larry Rosenman http://www.lerctr.org/~ler Phone: +1 972-414-9812 E-Mail: ler@lerctr.org US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749 --==========1B86D33B13306EE04F08========== Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (FreeBSD) iD8DBQE/z6ZQrRNGhTxJvdYRAizdAKCJrroU/PruGlADjJEybSh+IhRHwQCffnpM rZH61B7ilXl1WNXE+fvLmCA= =SdUH -----END PGP SIGNATURE----- --==========1B86D33B13306EE04F08==========--