Browse Source

ckdb - convert sharesummary workername to a ptr - reduce ram ... lots

master
kanoi 10 years ago
parent
commit
941cba9b3b
  1. 9
      src/ckdb.c
  2. 37
      src/ckdb.h
  3. 2
      src/ckdb_cmd.c
  4. 11
      src/ckdb_data.c
  5. 20
      src/ckdb_dbio.c

9
src/ckdb.c

@ -1057,6 +1057,11 @@ static void free_sharesummary_data(K_ITEM *item)
SHARESUMMARY *sharesummary; SHARESUMMARY *sharesummary;
DATA_SHARESUMMARY(sharesummary, item); DATA_SHARESUMMARY(sharesummary, item);
if (sharesummary->workername) {
LIST_MEM_SUB(sharesummary_free, sharesummary->workername);
free(sharesummary->workername);
sharesummary->workername = NULL;
}
SET_CREATEBY(sharesummary_free, sharesummary->createby, EMPTY); SET_CREATEBY(sharesummary_free, sharesummary->createby, EMPTY);
SET_CREATECODE(sharesummary_free, sharesummary->createcode, EMPTY); SET_CREATECODE(sharesummary_free, sharesummary->createcode, EMPTY);
SET_CREATEINET(sharesummary_free, sharesummary->createinet, EMPTY); SET_CREATEINET(sharesummary_free, sharesummary->createinet, EMPTY);
@ -1595,7 +1600,7 @@ static void summarise_blocks()
// Add up the sharesummaries, abort if any SUMMARY_NEW // Add up the sharesummaries, abort if any SUMMARY_NEW
looksharesummary.workinfoid = wi_finish; looksharesummary.workinfoid = wi_finish;
looksharesummary.userid = MAXID; looksharesummary.userid = MAXID;
looksharesummary.workername[0] = '\0'; looksharesummary.workername = EMPTY;
INIT_SHARESUMMARY(&ss_look); INIT_SHARESUMMARY(&ss_look);
ss_look.data = (void *)(&looksharesummary); ss_look.data = (void *)(&looksharesummary);
@ -2872,7 +2877,7 @@ static void compare_summaries(K_TREE *leftsum, char *leftname,
looksharesummary.workinfoid = confirm_first_workinfoid; looksharesummary.workinfoid = confirm_first_workinfoid;
looksharesummary.userid = -1; looksharesummary.userid = -1;
looksharesummary.workername[0] = '\0'; looksharesummary.workername = EMPTY;
INIT_SHARESUMMARY(&look); INIT_SHARESUMMARY(&look);
look.data = (void *)(&looksharesummary); look.data = (void *)(&looksharesummary);

37
src/ckdb.h

@ -52,7 +52,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "0.9.5" #define DB_VERSION "0.9.5"
#define CKDB_VERSION DB_VERSION"-0.647" #define CKDB_VERSION DB_VERSION"-0.648"
#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__
@ -347,15 +347,26 @@ enum cmd_values {
// The size strdup will allocate multiples of // The size strdup will allocate multiples of
#define MEMBASE 4 #define MEMBASE 4
#define LIST_MEM_ADD(_list, _fld) do { \
size_t __siz; \
__siz = strlen(_fld) + 1; \
if (__siz % MEMBASE) \
__siz += MEMBASE - (__siz % MEMBASE); \
_list->ram += (int)__siz; \
} while (0)
#define LIST_MEM_SUB(_list, _fld) do { \
size_t __siz; \
__siz = strlen(_fld) + 1; \
if (__siz % MEMBASE) \
__siz += MEMBASE - (__siz % MEMBASE); \
_list->ram -= (int)__siz; \
} while (0)
#define SET_POINTER(_list, _fld, _val, _def) do { \ #define SET_POINTER(_list, _fld, _val, _def) do { \
size_t _siz; \
if ((_fld) && ((_fld) != EMPTY) && ((_fld) != (_def))) { \ if ((_fld) && ((_fld) != EMPTY) && ((_fld) != (_def))) { \
if (_list) { \ if (_list) \
_siz = strlen(_fld) + 1; \ LIST_MEM_SUB(_list, _fld); \
if (_siz % MEMBASE) \
_siz += MEMBASE - (_siz % MEMBASE); \
_list->ram -= (int)_siz; \
} \
free(_fld); \ free(_fld); \
} \ } \
if (!(_val) || !(*(_val))) \ if (!(_val) || !(*(_val))) \
@ -364,12 +375,8 @@ enum cmd_values {
if (((_val) == (_def)) || (strcmp(_val, _def) == 0)) \ if (((_val) == (_def)) || (strcmp(_val, _def) == 0)) \
(_fld) = (_def); \ (_fld) = (_def); \
else { \ else { \
if (_list) { \ if (_list) \
_siz = strlen(_val) + 1; \ LIST_MEM_ADD(_list, _val); \
if (_siz % MEMBASE) \
_siz += MEMBASE - (_siz % MEMBASE); \
_list->ram += (int)_siz; \
} \
_fld = strdup(_val); \ _fld = strdup(_val); \
if (!(_fld)) \ if (!(_fld)) \
quithere(1, "malloc OOM"); \ quithere(1, "malloc OOM"); \
@ -936,7 +943,7 @@ extern K_STORE *shareerrors_store;
// SHARESUMMARY // SHARESUMMARY
typedef struct sharesummary { typedef struct sharesummary {
int64_t userid; int64_t userid;
char workername[TXT_BIG+1]; char *workername;
int64_t workinfoid; int64_t workinfoid;
double diffacc; double diffacc;
double diffsta; double diffsta;

2
src/ckdb_cmd.c

@ -3076,7 +3076,7 @@ static char *cmd_pplns(__maybe_unused PGconn *conn, char *cmd, char *id,
looksharesummary.workinfoid = workinfoid; looksharesummary.workinfoid = workinfoid;
looksharesummary.userid = MAXID; looksharesummary.userid = MAXID;
looksharesummary.workername[0] = '\0'; looksharesummary.workername = EMPTY;
INIT_SHARESUMMARY(&ss_look); INIT_SHARESUMMARY(&ss_look);
ss_look.data = (void *)(&looksharesummary); ss_look.data = (void *)(&looksharesummary);
K_RLOCK(sharesummary_free); K_RLOCK(sharesummary_free);

11
src/ckdb_data.c

@ -710,7 +710,7 @@ void workerstatus_ready()
// The last one // The last one
looksharesummary.userid = workerstatus->userid; looksharesummary.userid = workerstatus->userid;
STRNCPY(looksharesummary.workername, workerstatus->workername); looksharesummary.workername = workerstatus->workername;
looksharesummary.workinfoid = MAXID; looksharesummary.workinfoid = MAXID;
ss_look.data = (void *)(&looksharesummary); ss_look.data = (void *)(&looksharesummary);
K_RLOCK(sharesummary_free); K_RLOCK(sharesummary_free);
@ -1376,7 +1376,7 @@ bool workinfo_age(PGconn *conn, int64_t workinfoid, char *poolinstance,
// Find the first matching sharesummary // Find the first matching sharesummary
looksharesummary.workinfoid = workinfoid; looksharesummary.workinfoid = workinfoid;
looksharesummary.userid = -1; looksharesummary.userid = -1;
looksharesummary.workername[0] = '\0'; looksharesummary.workername = EMPTY;
ok = true; ok = true;
ss_tot = ss_already = ss_failed = shares_tot = shares_dumped = 0; ss_tot = ss_already = ss_failed = shares_tot = shares_dumped = 0;
@ -1607,7 +1607,7 @@ K_ITEM *find_sharesummary(int64_t userid, char *workername, int64_t workinfoid)
K_ITEM look; K_ITEM look;
sharesummary.userid = userid; sharesummary.userid = userid;
STRNCPY(sharesummary.workername, workername); sharesummary.workername = workername;
sharesummary.workinfoid = workinfoid; sharesummary.workinfoid = workinfoid;
INIT_SHARESUMMARY(&look); INIT_SHARESUMMARY(&look);
@ -1643,7 +1643,7 @@ void auto_age_older(PGconn *conn, int64_t workinfoid, char *poolinstance,
// Find the oldest 'unaged' sharesummary < workinfoid and >= prev_found // Find the oldest 'unaged' sharesummary < workinfoid and >= prev_found
looksharesummary.workinfoid = prev_found; looksharesummary.workinfoid = prev_found;
looksharesummary.userid = -1; looksharesummary.userid = -1;
looksharesummary.workername[0] = '\0'; looksharesummary.workername = EMPTY;
INIT_SHARESUMMARY(&look); INIT_SHARESUMMARY(&look);
look.data = (void *)(&looksharesummary); look.data = (void *)(&looksharesummary);
@ -1956,8 +1956,7 @@ void set_block_share_counters()
if (sharesummary->workinfoid <= pool.workinfoid) { if (sharesummary->workinfoid <= pool.workinfoid) {
// Skip back to the next worker // Skip back to the next worker
looksharesummary.userid = sharesummary->userid; looksharesummary.userid = sharesummary->userid;
STRNCPY(looksharesummary.workername, looksharesummary.workername = sharesummary->workername;
sharesummary->workername);
looksharesummary.workinfoid = -1; looksharesummary.workinfoid = -1;
ss_look.data = (void *)(&looksharesummary); ss_look.data = (void *)(&looksharesummary);
ss_item = find_before_in_ktree(sharesummary_root, &ss_look, ss_item = find_before_in_ktree(sharesummary_root, &ss_look,

20
src/ckdb_dbio.c

@ -2719,7 +2719,8 @@ bool _sharesummary_update(PGconn *conn, SHARES *s_row, SHAREERRORS *e_row, K_ITE
K_WUNLOCK(sharesummary_free); K_WUNLOCK(sharesummary_free);
DATA_SHARESUMMARY(row, item); DATA_SHARESUMMARY(row, item);
row->userid = userid; row->userid = userid;
STRNCPY(row->workername, workername); row->workername = strdup(workername);
LIST_MEM_ADD(sharesummary_free, row->workername);
row->workinfoid = workinfoid; row->workinfoid = workinfoid;
zero_sharesummary(row, sharecreatedate, diff); zero_sharesummary(row, sharecreatedate, diff);
row->inserted = false; row->inserted = false;
@ -2948,15 +2949,15 @@ late:
PQfinish(conn); PQfinish(conn);
// We keep the new item no matter what 'ok' is, since it will be inserted later // We keep the new item no matter what 'ok' is, since it will be inserted later
K_WLOCK(sharesummary_free);
if (new) { if (new) {
K_WLOCK(sharesummary_free);
sharesummary_root = add_to_ktree(sharesummary_root, item, cmp_sharesummary); sharesummary_root = add_to_ktree(sharesummary_root, item, cmp_sharesummary);
sharesummary_workinfoid_root = add_to_ktree(sharesummary_workinfoid_root, sharesummary_workinfoid_root = add_to_ktree(sharesummary_workinfoid_root,
item, item,
cmp_sharesummary_workinfoid); cmp_sharesummary_workinfoid);
k_add_head(sharesummary_store, item); k_add_head(sharesummary_store, item);
}
K_WUNLOCK(sharesummary_free); K_WUNLOCK(sharesummary_free);
}
return ok; return ok;
} }
@ -3010,6 +3011,7 @@ bool sharesummary_fill(PGconn *conn)
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
item = k_unlink_head(sharesummary_free); item = k_unlink_head(sharesummary_free);
DATA_SHARESUMMARY(row, item); DATA_SHARESUMMARY(row, item);
row->workername = NULL;
if (everyone_die) { if (everyone_die) {
ok = false; ok = false;
@ -3026,7 +3028,8 @@ bool sharesummary_fill(PGconn *conn)
PQ_GET_FLD(res, i, "workername", field, ok); PQ_GET_FLD(res, i, "workername", field, ok);
if (!ok) if (!ok)
break; break;
TXT_TO_STR("workername", field, row->workername); row->workername = strdup(field);
LIST_MEM_ADD(sharesummary_free, row->workername);
PQ_GET_FLD(res, i, "workinfoid", field, ok); PQ_GET_FLD(res, i, "workinfoid", field, ok);
if (!ok) if (!ok)
@ -3153,8 +3156,15 @@ bool sharesummary_fill(PGconn *conn)
tick(); tick();
} }
if (!ok) if (!ok) {
DATA_SHARESUMMARY(row, item);
if (row->workername) {
LIST_MEM_SUB(sharesummary_free, row->workername);
free(row->workername);
row->workername = NULL;
}
k_add_head(sharesummary_free, item); k_add_head(sharesummary_free, item);
}
PQclear(res); PQclear(res);

Loading…
Cancel
Save