Re: droped out precise time calculations in src/interfaces/libpq/fe-connect.c - Mailing list pgsql-hackers
From | Joe Conway |
---|---|
Subject | Re: droped out precise time calculations in src/interfaces/libpq/fe-connect.c |
Date | |
Msg-id | 3DACA7CA.70509@joeconway.com Whole thread Raw |
In response to | Re: droped out precise time calculations in src/interfaces/libpq/fe-connect.c (Bruce Momjian <pgman@candle.pha.pa.us>) |
Responses |
Re: droped out precise time calculations in src/interfaces/libpq/fe-connect.c
|
List | pgsql-hackers |
Tom Lane wrote: > Joe Conway <mail@joeconway.com> writes: > >> The thing was that with the extra +1, I was repeatedly getting a >> wall-clock time of 2 seconds with a timeout set to 1 second. It seemed >> odd to have my 1 second timeout automatically turned into 2 seconds every >> time. > > That is odd; seems like you should get between 1 and 2 seconds. How were > you measuring the delay, exactly? OK. I got a little more scientific about my testing. I used a php script, running on the same machine, to connect/disconnect in a tight loop and timed successful and unsuccessful connection attempts using microtime(). Here are the results. First with current cvs code: current cvs libpq code ----------------------- good connect info, using unix socket, timeout = 1 second: ========================================================= unsuccessful 69 times: sum 0.41736388206482: avg 0.0060487519139829 successful 9931 times: sum 68.798981308937: avg 0.0069276992557584 good connect info, using hostaddr, timeout = 1 second ===================================================== unsuccessful 72 times: sum 0.37020063400269: avg 0.0051416754722595 successful 9928 times: sum 75.047878861427: avg 0.0075592142285886 current cvs libpq code - bad hostaadr, using hostaddr, timeout = 1 second ========================================================================= unsuccessful 100 times: sum 99.975758910179: avg 0.99975758910179 successful 0 times: sum 0: avg n/a Clearly not good. The timeout code is causing connection failures about 0.7% of the time. Next are the results using the attached patch. Per Bruce's suggestion, it only adds 1 if the timeout is set to 1. with patch libpq code --------------------- good connect info, using unix socket, timeout = 1 second ======================================================== unsuccessful 0 times: sum 0: avg n/a successful 10000 times: sum 68.95981669426: avg 0.006895981669426 with patch libpq code - good connect info, using hostaddr, timeout = 1 second ============================================================================= unsuccessful 0 times: sum 0: avg n/a successful 10000 times: sum 73.500863552094: avg 0.0073500863552094 with patch libpq code - good connect info, using hostaddr, timeout = 2 seconds ============================================================================== unsuccessful 0 times: sum 0: avg n/a successful 10000 times: sum 73.354710936546: avg 0.0073354710936546 with patch libpq code - bad hostaadr, using hostaddr, timeout = 1 second ======================================================================== unsuccessful 100 times: sum 149.98181843758: avg 1.4998181843758 successful 0 times: sum 0: avg n/a with patch libpq code - bad hostaadr, using hostaddr, timeout = 2 seconds ========================================================================= unsuccessful 100 times: sum 149.98445630074: avg 1.4998445630074 successful 0 times: sum 0: avg n/a with patch libpq code - bad hostaadr, using hostaddr, timeout = 3 seconds ========================================================================= unsuccessful 20 times: sum 59.842629671097: avg 2.9921314835548 successful 0 times: sum 0: avg n/a With the patch there were 0 failures on 30000 attempts using good connect information. If there are no objections, please apply the attached. Otherwise let me know if you'd like different tests or would like to try other approaches. Thanks, Joe Index: src/interfaces/libpq/fe-connect.c =================================================================== RCS file: /opt/src/cvs/pgsql-server/src/interfaces/libpq/fe-connect.c,v retrieving revision 1.210 diff -c -r1.210 fe-connect.c *** src/interfaces/libpq/fe-connect.c 15 Oct 2002 01:48:25 -0000 1.210 --- src/interfaces/libpq/fe-connect.c 15 Oct 2002 22:36:53 -0000 *************** *** 1066,1071 **** --- 1066,1073 ---- if (conn->connect_timeout != NULL) { remains.tv_sec = atoi(conn->connect_timeout); + if (remains.tv_sec == 1) + remains.tv_sec += 1; if (!remains.tv_sec) { conn->status = CONNECTION_BAD;
pgsql-hackers by date: