dovecot-2.2: pgsql: Log a warning if DNS lookup takes too long. ...

dovecot at dovecot.org dovecot at dovecot.org
Fri May 15 10:09:29 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/db41043041cb
changeset: 18697:db41043041cb
user:      Timo Sirainen <tss at iki.fi>
date:      Fri May 15 13:07:27 2015 +0300
description:
pgsql: Log a warning if DNS lookup takes too long. Don't include it in connect timeout.

diffstat:

 src/lib-sql/driver-pgsql.c |  17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diffs (50 lines):

diff -r 55bcb0e792fc -r db41043041cb src/lib-sql/driver-pgsql.c
--- a/src/lib-sql/driver-pgsql.c	Fri May 15 12:48:07 2015 +0300
+++ b/src/lib-sql/driver-pgsql.c	Fri May 15 13:07:27 2015 +0300
@@ -3,12 +3,15 @@
 #include "lib.h"
 #include "array.h"
 #include "ioloop.h"
+#include "time-util.h"
 #include "sql-api-private.h"
 
 #ifdef BUILD_PGSQL
 #include <stdlib.h>
 #include <libpq-fe.h>
 
+#define PGSQL_DNS_WARN_MSECS 500
+
 struct pgsql_db {
 	struct sql_db api;
 
@@ -195,9 +198,14 @@
 static int driver_pgsql_connect(struct sql_db *_db)
 {
 	struct pgsql_db *db = (struct pgsql_db *)_db;
+	struct timeval tv_start;
+	int msecs;
 
 	i_assert(db->api.state == SQL_DB_STATE_DISCONNECTED);
 
+	io_loop_time_refresh();
+	tv_start = ioloop_timeval;
+
 	db->pg = PQconnectStart(db->connect_string);
 	if (db->pg == NULL) {
 		i_fatal("%s: PQconnectStart() failed (out of memory)",
@@ -210,6 +218,15 @@
 		driver_pgsql_close(db);
 		return -1;
 	}
+	/* PQconnectStart() blocks on host name resolving. Log a warning if
+	   it takes too long. Also don't include time spent on that in the
+	   connect timeout (by refreshing ioloop time). */
+	io_loop_time_refresh();
+	msecs = timeval_diff_msecs(&ioloop_timeval, &tv_start);
+	if (msecs > PGSQL_DNS_WARN_MSECS) {
+		i_warning("%s: DNS lookup took %d.%03d s",
+			  pgsql_prefix(db), msecs/1000, msecs % 1000);
+	}
 
 	/* nonblocking connecting begins. */
 	if (PQsetnonblocking(db->pg, 1) < 0)


More information about the dovecot-cvs mailing list