From b74ae0f24e31dd364e6d7a7602a3f3e0d8ae1830 Mon Sep 17 00:00:00 2001 From: kanoi Date: Sat, 21 Mar 2015 14:40:46 +1100 Subject: [PATCH 1/3] ckdb - console warning log out of order shares only if more than 1 second --- src/ckdb.h | 2 +- src/ckdb_dbio.c | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/ckdb.h b/src/ckdb.h index a26a04ac..95a5791f 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -55,7 +55,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.0" -#define CKDB_VERSION DB_VERSION"-1.033" +#define CKDB_VERSION DB_VERSION"-1.034" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ diff --git a/src/ckdb_dbio.c b/src/ckdb_dbio.c index 5b3c1544..e5528df3 100644 --- a/src/ckdb_dbio.c +++ b/src/ckdb_dbio.c @@ -3438,10 +3438,16 @@ bool _sharesummary_update(PGconn *conn, SHARES *s_row, SHAREERRORS *e_row, K_ITE if (!new) { double td; td = tvdiff(sharecreatedate, &(row->firstshare)); - // don't LOGERR '=' in case shares come from ckpool with the same timestamp + // don't LOG '=' in case shares come from ckpool with the same timestamp if (td < 0.0) { char *tmp1, *tmp2; - LOGERR("%s(): %s createdate (%s) is < summary firstshare (%s)", + int level; + // DEBUG only for shares out of order up to 1 second + if (td < -1.0) + level = LOG_WARNING; + else + level = LOG_DEBUG; + LOGMSG(level, "%s(): OoO %s createdate (%s) is < summary firstshare (%s)", __func__, s_row ? "shares" : "shareerrors", (tmp1 = ctv_to_buf(sharecreatedate, NULL, 0)), (tmp2 = ctv_to_buf(&(row->firstshare), NULL, 0))); @@ -3452,14 +3458,20 @@ bool _sharesummary_update(PGconn *conn, SHARES *s_row, SHAREERRORS *e_row, K_ITE // Don't change lastdiffacc } td = tvdiff(sharecreatedate, &(row->lastshare)); - // don't LOGERR '=' in case shares come from ckpool with the same timestamp + // don't LOG '=' in case shares come from ckpool with the same timestamp if (td >= 0.0) { row->lastshare.tv_sec = sharecreatedate->tv_sec; row->lastshare.tv_usec = sharecreatedate->tv_usec; row->lastdiffacc = diff; } else { char *tmp1, *tmp2; - LOGERR("%s(): %s createdate (%s) is < summary lastshare (%s)", + int level; + // DEBUG only for shares out of order up to 1 second + if (td < -1.0) + level = LOG_WARNING; + else + level = LOG_DEBUG; + LOGMSG(level, "%s(): OoO %s createdate (%s) is < summary lastshare (%s)", __func__, s_row ? "shares" : "shareerrors", (tmp1 = ctv_to_buf(sharecreatedate, NULL, 0)), (tmp2 = ctv_to_buf(&(row->lastshare), NULL, 0))); From 2230bd6d65ced5fbaca68c648ba4a35b7c297955 Mon Sep 17 00:00:00 2001 From: kanoi Date: Sat, 21 Mar 2015 15:53:07 +1100 Subject: [PATCH 2/3] ckdb - stat the share OoO messages and increase the warning limit to 2s --- src/ckdb.h | 2 +- src/ckdb_dbio.c | 37 +++++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/ckdb.h b/src/ckdb.h index 95a5791f..ed9d615d 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -55,7 +55,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.0" -#define CKDB_VERSION DB_VERSION"-1.034" +#define CKDB_VERSION DB_VERSION"-1.035" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ diff --git a/src/ckdb_dbio.c b/src/ckdb_dbio.c index e5528df3..033112af 100644 --- a/src/ckdb_dbio.c +++ b/src/ckdb_dbio.c @@ -3313,6 +3313,11 @@ flail: return ok; } +/* Keep some simple stats on how often shares are out of order + * and how often they produce a WARNING due to OOOLIMIT */ +static int64_t ooof0, ooof, oool0, oool; +#define OOOLIMIT -2.0 + bool _sharesummary_update(PGconn *conn, SHARES *s_row, SHAREERRORS *e_row, K_ITEM *ss_item, char *by, char *code, char *inet, tv_t *cd, WHERE_FFL_ARGS) { @@ -3442,15 +3447,21 @@ bool _sharesummary_update(PGconn *conn, SHARES *s_row, SHAREERRORS *e_row, K_ITE if (td < 0.0) { char *tmp1, *tmp2; int level; - // DEBUG only for shares out of order up to 1 second - if (td < -1.0) + // DEBUG only for shares out of order up to OOOLIMIT seconds + if (td < OOOLIMIT) { level = LOG_WARNING; - else + ooof++; + } else { level = LOG_DEBUG; - LOGMSG(level, "%s(): OoO %s createdate (%s) is < summary firstshare (%s)", + ooof0++; + } + LOGMSG(level, "%s(): OoO %s createdate (%s) is < summary" + " firstshare (%s) (F%"PRId64":%"PRId64 + "/L%"PRId64":%"PRId64"/%.1f)", __func__, s_row ? "shares" : "shareerrors", (tmp1 = ctv_to_buf(sharecreatedate, NULL, 0)), - (tmp2 = ctv_to_buf(&(row->firstshare), NULL, 0))); + (tmp2 = ctv_to_buf(&(row->firstshare), NULL, 0)), + ooof, ooof0, oool, oool0, OOOLIMIT); free(tmp2); free(tmp1); row->firstshare.tv_sec = sharecreatedate->tv_sec; @@ -3466,15 +3477,21 @@ bool _sharesummary_update(PGconn *conn, SHARES *s_row, SHAREERRORS *e_row, K_ITE } else { char *tmp1, *tmp2; int level; - // DEBUG only for shares out of order up to 1 second - if (td < -1.0) + // DEBUG only for shares out of order up to OOOLIMIT seconds + if (td < OOOLIMIT) { level = LOG_WARNING; - else + oool++; + } else { level = LOG_DEBUG; - LOGMSG(level, "%s(): OoO %s createdate (%s) is < summary lastshare (%s)", + oool0++; + } + LOGMSG(level, "%s(): OoO %s createdate (%s) is < summary" + " lastshare (%s) (F%"PRId64":%"PRId64 + "/L%"PRId64":%"PRId64"/%.1f)", __func__, s_row ? "shares" : "shareerrors", (tmp1 = ctv_to_buf(sharecreatedate, NULL, 0)), - (tmp2 = ctv_to_buf(&(row->lastshare), NULL, 0))); + (tmp2 = ctv_to_buf(&(row->lastshare), NULL, 0)), + ooof, ooof0, oool, oool0, OOOLIMIT); free(tmp2); free(tmp1); } From eefbeef44b50375636e0b332c582b893cb74bfc2 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 22 Mar 2015 12:08:45 +1100 Subject: [PATCH 3/3] Only check user_instance under instance lock --- src/stratifier.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index 4f50c4cb..2b23c5e7 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -995,14 +995,15 @@ static void __disconnect_session(sdata_t *sdata, const stratum_instance_t *clien /* Removes a client instance we know is on the stratum_instances list and from * the user client list if it's been placed on it */ -static void __del_client(sdata_t *sdata, stratum_instance_t *client, user_instance_t *user) +static void __del_client(sdata_t *sdata, stratum_instance_t *client) { + user_instance_t *user = client->user_instance; + HASH_DEL(sdata->stratum_instances, client); if (user) { DL_DELETE(user->clients, client); __dec_worker(sdata, user); } - } static void drop_allclients(ckpool_t *ckp) @@ -1017,7 +1018,7 @@ static void drop_allclients(ckpool_t *ckp) int64_t client_id = client->id; if (!client->ref) { - __del_client(sdata, client, client->user_instance); + __del_client(sdata, client); __kill_instance(sdata, client); } else client->dropped = true; @@ -1250,11 +1251,10 @@ static stratum_instance_t *ref_instance_by_id(sdata_t *sdata, const int64_t id) return client; } -static void __drop_client(sdata_t *sdata, stratum_instance_t *client, user_instance_t *user, - bool lazily, char **msg) +static void __drop_client(sdata_t *sdata, stratum_instance_t *client, bool lazily, char **msg) { + user_instance_t *user = client->user_instance; - __del_client(sdata, client, user); if (client->workername) { if (user) { ASPRINTF(msg, "Client %"PRId64" %s %suser %s worker %s dropped %s", @@ -1269,6 +1269,7 @@ static void __drop_client(sdata_t *sdata, stratum_instance_t *client, user_insta ASPRINTF(msg, "Workerless client %"PRId64" %s dropped %s", client->id, client->address, lazily ? "lazily" : ""); } + __del_client(sdata, client); __kill_instance(sdata, client); } @@ -1276,7 +1277,6 @@ static void __drop_client(sdata_t *sdata, stratum_instance_t *client, user_insta static void _dec_instance_ref(sdata_t *sdata, stratum_instance_t *client, const char *file, const char *func, const int line) { - user_instance_t *user = client->user_instance; char_entry_t *entries = NULL; char *msg; int ref; @@ -1286,7 +1286,7 @@ static void _dec_instance_ref(sdata_t *sdata, stratum_instance_t *client, const /* See if there are any instances that were dropped that could not be * moved due to holding a reference and drop them now. */ if (unlikely(client->dropped && !ref)) { - __drop_client(sdata, client, user, true, &msg); + __drop_client(sdata, client, true, &msg); add_msg_entry(&entries, &msg); } ck_wunlock(&sdata->instance_lock); @@ -1434,7 +1434,6 @@ static void stratum_add_send(sdata_t *sdata, json_t *val, const int64_t client_i static void drop_client(sdata_t *sdata, const int64_t id) { char_entry_t *entries = NULL; - user_instance_t *user = NULL; stratum_instance_t *client; char *msg; @@ -1444,11 +1443,10 @@ static void drop_client(sdata_t *sdata, const int64_t id) client = __instance_by_id(sdata, id); if (client && !client->dropped) { __disconnect_session(sdata, client); - user = client->user_instance; /* If the client is still holding a reference, don't drop them * now but wait till the reference is dropped */ if (!client->ref) { - __drop_client(sdata, client, user, false, &msg); + __drop_client(sdata, client, false, &msg); add_msg_entry(&entries, &msg); } else client->dropped = true;