Browse Source

ckdb - db load limit userstats/poolstats to last 24hrs since we don't need them yet

master
kanoi 10 years ago
parent
commit
b903c9536e
  1. 2
      src/ckdb.h
  2. 119
      src/ckdb_dbio.c

2
src/ckdb.h

@ -52,7 +52,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "0.9.6" #define DB_VERSION "0.9.6"
#define CKDB_VERSION DB_VERSION"-0.800" #define CKDB_VERSION DB_VERSION"-0.802"
#define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__ #define WHERE_FFL_HERE __FILE__, __func__, __LINE__

119
src/ckdb_dbio.c

@ -4550,25 +4550,66 @@ bool poolstats_fill(PGconn *conn)
PGresult *res; PGresult *res;
K_ITEM *item; K_ITEM *item;
int n, i; int n, i;
struct tm tm;
time_t now_t;
char tzinfo[16], stamp[128];
POOLSTATS *row; POOLSTATS *row;
char *field; char *field;
char *sel; char *sel = NULL;
size_t len, off;
int fields = 8; int fields = 8;
long minoff, hroff;
char tzch;
bool ok; bool ok;
LOGDEBUG("%s(): select", __func__); LOGDEBUG("%s(): select", __func__);
sel = "select " // Temoprarily ... load last 24hrs worth
"poolinstance,elapsed,users,workers,hashrate,hashrate5m," now_t = time(NULL);
"hashrate1hr,hashrate24hr" now_t -= 24 * 60 * 60;
localtime_r(&now_t, &tm);
minoff = tm.tm_gmtoff / 60;
if (minoff < 0) {
tzch = '-';
minoff *= -1;
} else
tzch = '+';
hroff = minoff / 60;
if (minoff % 60) {
snprintf(tzinfo, sizeof(tzinfo),
"%c%02ld:%02ld",
tzch, hroff, minoff % 60);
} else {
snprintf(tzinfo, sizeof(tzinfo),
"%c%02ld",
tzch, hroff);
}
snprintf(stamp, sizeof(stamp),
"'%d-%02d-%02d %02d:%02d:%02d%s'",
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec,
tzinfo);
APPEND_REALLOC_INIT(sel, off, len);
APPEND_REALLOC(sel, off, len,
"select "
"poolinstance,elapsed,users,workers,hashrate,"
"hashrate5m,hashrate1hr,hashrate24hr"
SIMPLEDATECONTROL SIMPLEDATECONTROL
" from poolstats"; " from poolstats where createdate>");
APPEND_REALLOC(sel, off, len, stamp);
res = PQexec(conn, sel, CKPQ_READ); res = PQexec(conn, sel, CKPQ_READ);
rescode = PQresultStatus(res); rescode = PQresultStatus(res);
if (!PGOK(rescode)) { if (!PGOK(rescode)) {
PGLOGERR("Select", rescode, conn); PGLOGERR("Select", rescode, conn);
PQclear(res); PQclear(res);
return false; ok = false;
goto clean;
} }
n = PQnfields(res); n = PQnfields(res);
@ -4576,7 +4617,8 @@ bool poolstats_fill(PGconn *conn)
LOGERR("%s(): Invalid field count - should be %d, but is %d", LOGERR("%s(): Invalid field count - should be %d, but is %d",
__func__, fields + SIMPLEDATECOUNT, n); __func__, fields + SIMPLEDATECOUNT, n);
PQclear(res); PQclear(res);
return false; ok = false;
goto clean;
} }
n = PQntuples(res); n = PQntuples(res);
@ -4656,7 +4698,8 @@ bool poolstats_fill(PGconn *conn)
LOGDEBUG("%s(): built", __func__); LOGDEBUG("%s(): built", __func__);
LOGWARNING("%s(): loaded %d poolstats records", __func__, n); LOGWARNING("%s(): loaded %d poolstats records", __func__, n);
} }
clean:
free(sel);
return ok; return ok;
} }
@ -4961,26 +5004,68 @@ bool userstats_fill(PGconn *conn)
PGresult *res; PGresult *res;
K_ITEM *item; K_ITEM *item;
int n, i; int n, i;
struct tm tm;
time_t now_t;
char tzinfo[16], stamp[128];
USERSTATS *row; USERSTATS *row;
tv_t statsdate; tv_t statsdate;
char *field; char *field;
char *sel; char *sel = NULL;
size_t len, off;
int fields = 10; int fields = 10;
long minoff, hroff;
char tzch;
bool ok; bool ok;
LOGDEBUG("%s(): select", __func__); LOGDEBUG("%s(): select", __func__);
sel = "select " // Temoprarily ... load last 24hrs worth
"userid,workername,elapsed,hashrate,hashrate5m,hashrate1hr," now_t = time(NULL);
"hashrate24hr,summarylevel,summarycount,statsdate" now_t -= 24 * 60 * 60;
localtime_r(&now_t, &tm);
minoff = tm.tm_gmtoff / 60;
if (minoff < 0) {
tzch = '-';
minoff *= -1;
} else
tzch = '+';
hroff = minoff / 60;
if (minoff % 60) {
snprintf(tzinfo, sizeof(tzinfo),
"%c%02ld:%02ld",
tzch, hroff, minoff % 60);
} else {
snprintf(tzinfo, sizeof(tzinfo),
"%c%02ld",
tzch, hroff);
}
snprintf(stamp, sizeof(stamp),
"'%d-%02d-%02d %02d:%02d:%02d%s'",
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec,
tzinfo);
APPEND_REALLOC_INIT(sel, off, len);
APPEND_REALLOC(sel, off, len,
"select "
"userid,workername,elapsed,hashrate,hashrate5m,"
"hashrate1hr,hashrate24hr,summarylevel,summarycount,"
"statsdate"
SIMPLEDATECONTROL SIMPLEDATECONTROL
" from userstats"; " from userstats where statsdate>");
APPEND_REALLOC(sel, off, len, stamp);
res = PQexec(conn, sel, CKPQ_READ); res = PQexec(conn, sel, CKPQ_READ);
rescode = PQresultStatus(res); rescode = PQresultStatus(res);
if (!PGOK(rescode)) { if (!PGOK(rescode)) {
PGLOGERR("Select", rescode, conn); PGLOGERR("Select", rescode, conn);
PQclear(res); PQclear(res);
return false; ok = false;
goto clean;
} }
n = PQnfields(res); n = PQnfields(res);
@ -4988,7 +5073,8 @@ bool userstats_fill(PGconn *conn)
LOGERR("%s(): Invalid field count - should be %d, but is %d", LOGERR("%s(): Invalid field count - should be %d, but is %d",
__func__, fields + SIMPLEDATECOUNT, n); __func__, fields + SIMPLEDATECOUNT, n);
PQclear(res); PQclear(res);
return false; ok = false;
goto clean;
} }
n = PQntuples(res); n = PQntuples(res);
@ -5092,7 +5178,8 @@ bool userstats_fill(PGconn *conn)
LOGDEBUG("%s(): built", __func__); LOGDEBUG("%s(): built", __func__);
LOGWARNING("%s(): loaded %d userstats records", __func__, n); LOGWARNING("%s(): loaded %d userstats records", __func__, n);
} }
clean:
free(sel);
return ok; return ok;
} }

Loading…
Cancel
Save