7fe80d37afd296f8db0058f3e444737ff88ff80e
markd
  Mon Jul 26 23:50:19 2010 -0700
address problem of hgTables consuming all available sockets before TIME_WAIT period by using the connection cache. Have hgTable log connection usage information to help ensure this is fixed
diff --git src/hg/lib/jksql.c src/hg/lib/jksql.c
index c98924c..d8f513a 100644
--- src/hg/lib/jksql.c
+++ src/hg/lib/jksql.c
@@ -33,6 +33,10 @@
 static char *indentStr = "                                                       ";
 static boolean sqlParanoid = FALSE;         /* extra squawking */
 
+/* statistics */
+static unsigned totalNumConnects = 0;
+static unsigned maxNumConnections = 0;
+
 struct sqlProfile
 /* a configuration profile for connecting to a server */
 {
@@ -66,7 +70,8 @@
     long fetchTime;                     /* cummulative time taken by row fetches for this result */
     };
 
-static struct dlList *sqlOpenConnections;
+static struct dlList *sqlOpenConnections = NULL;
+static unsigned sqlNumOpenConnections = 0;
 
 char *defaultProfileName = "db";                  // name of default profile
 static struct hash *profiles = NULL;              // profiles parsed from hg.conf, by name
@@ -518,6 +523,7 @@
 	freeMem(node);
 	}
     freez(pSc);
+    sqlNumOpenConnections--;
     }
 }
 
@@ -733,6 +739,10 @@
 deltaTime = monitorLeave();
 if (monitorFlags & JKSQL_TRACE)
     monitorPrint(sc, "SQL_TIME", "%0.3fs", ((double)deltaTime)/1000.0);
+sqlNumOpenConnections++;
+if (sqlNumOpenConnections > maxNumConnections)
+    maxNumConnections = sqlNumOpenConnections;
+totalNumConnects++;
 return sc;
 }
 
@@ -2580,3 +2590,11 @@
     sqlDumpConnection(connNode->val, fh);
 fprintf(fh, "%s\n", dashes);
 }
+
+void sqlPrintStats(FILE *fh)
+/* print statistic about the number of connections and other options done by
+ * this process. */
+{
+fprintf(fh, "sqlStats: connects: %d maxOpen: %d\n", totalNumConnects, maxNumConnections);
+}
+