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/hgTables/rangeHistogram.c src/hg/hgTables/rangeHistogram.c index 415c5c6..2b59710 100644 --- src/hg/hgTables/rangeHistogram.c +++ src/hg/hgTables/rangeHistogram.c @@ -1,105 +1,105 @@ /* ranges - display value ranges and histograms on fields. */ #include "common.h" #include "linefile.h" #include "hash.h" #include "htmshell.h" #include "cheapcgi.h" #include "cart.h" #include "jksql.h" #include "hgTables.h" #include "bedCart.h" static char const rcsid[] = "$Id: rangeHistogram.c,v 1.6 2009/05/20 20:59:56 mikep Exp $"; static void printValueHistogram(char *db, char *table, char *field) /* Print very simple-minded text histogram. */ { double maxHist = 60; double scale = -1.0; -struct sqlConnection *conn = sqlConnect(db); +struct sqlConnection *conn = hAllocConn(db); struct sqlResult *sr; char **row; char query[256]; safef(query, sizeof(query), "select %s, count(*) as count from %s group by %s order by count desc", field, table, field); sr = sqlGetResult(conn, query); hTableStart(); hPrintf(""); hPrintf("value"); hPrintf("count"); hPrintf("graph"); hPrintf(""); while ((row = sqlNextRow(sr)) != NULL) { char *name = htmlEncode(row[0]); int count = atoi(row[1]); int starCount; if (scale < 0) scale = (maxHist)/count; hPrintf("%s", name); hPrintf("%d", count); hPrintf(""); starCount = round(scale*count); if (starCount > 0) starOut(stdout, starCount); else hPrintf(" "); hPrintf("\n"); freeMem(name); } // hPrintf(""); hTableEnd(); -sqlDisconnect(&conn); +hFreeConn(&conn); } void doValueHistogram(char *field) /* Put up value histogram. */ { char *db = cartString(cart, hgtaDatabase); char *table = cartString(cart, hgtaHistoTable); htmlOpen("Value histogram for %s.%s.%s", db, table, field); printValueHistogram(db, table, field); htmlClose(); } static void printValueRange(char *db, char *table, char *field) /* Print min/max/mean. */ { -struct sqlConnection *conn = sqlConnect(db); +struct sqlConnection *conn = hAllocConn(db); struct sqlResult *sr; char **row; char query[256]; safef(query, sizeof(query), "select min(%s), max(%s), avg(%s) from %s", field, field, field, table); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { hPrintf("min: %s max: %s average: %s\n", row[0], row[1], row[2]); } -sqlDisconnect(&conn); +hFreeConn(&conn); } void doValueRange(char *field) /* Put up value histogram. */ { char *db = cartString(cart, hgtaDatabase); char *table = cartString(cart, hgtaHistoTable); boolean showItemRgb = FALSE; showItemRgb=bedItemRgb(findTdbForTable(db, curTrack, table, ctLookupName)); // should we expect itemRgb instead of "reserved" if (showItemRgb && sameWord(field, "reserved")) htmlOpen("Value range for %s.%s.itemRgb", db, table); else htmlOpen("Value range for %s.%s.%s", db, table, field); printValueRange(db, table, field); htmlClose(); }