diff --git a/lib/modules/Sql.pmod/pgsql.h b/lib/modules/Sql.pmod/pgsql.h index 67d8301899df71c846370c9b4979a3fe6c8750d9..e2fb97ef9f004675135845299d2ecfb01cb79832 100644 --- a/lib/modules/Sql.pmod/pgsql.h +++ b/lib/modules/Sql.pmod/pgsql.h @@ -30,6 +30,7 @@ #define QUERYTIMEOUT 4095 // Queries running longer than this number // of seconds are canceled automatically #define PORTALBUFFERSIZE (32*1024) // Approximate buffer per portal +#define MINPINGINTERVAL 4 // minimum seconds between ping()s #define BACKOFFDELAY 1 #define PGSQL_DEFAULT_PORT 5432 diff --git a/lib/modules/Sql.pmod/pgsql.pike b/lib/modules/Sql.pmod/pgsql.pike index d968066088fa1cc4e044baa0e2dc4322dcc96fa4..948a6707f94fe2b83d55ccf2ef19d28d7488e563 100644 --- a/lib/modules/Sql.pmod/pgsql.pike +++ b/lib/modules/Sql.pmod/pgsql.pike @@ -80,6 +80,7 @@ private int portalbuffersize = PORTALBUFFERSIZE; private int timeout = QUERYTIMEOUT; private array connparmcache; private int reconnected; +private int lastping = time(1); protected string _sprintf(int type) { string res; @@ -253,9 +254,15 @@ protected void create(void|string host, void|string database, //! @seealso //! @[is_open()] /*semi*/final int ping() { + int t, ret; waitauthready(); - return is_open() - && !catch(proxy.c->start()->sendcmd(FLUSHSEND)) ? !!reconnected : -1; + if ((ret = is_open()) + // Pinging more frequently than MINPINGINTERVAL seconds + // is suppressed to avoid artificial TCP-ACK latency + && (t = time(1)) - lastping > MINPINGINTERVAL + && (ret = !catch(proxy.c->start()->sendcmd(FLUSHSEND)))) + lastping = t; + return ret ? !!reconnected : -1; } //! Cancels all currently running queries in this session.