Changeset: ff15d286b58d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ff15d286b58d
Modified Files:
monetdb5/mal/Tests/recycle01.mal
monetdb5/mal/mal.h
monetdb5/mal/mal_interpreter.c
monetdb5/mal/mal_profiler.h
monetdb5/mal/mal_recycle.c
monetdb5/mal/mal_recycle.h
monetdb5/modules/mal/recycle.c
monetdb5/modules/mal/trader.c
monetdb5/optimizer/opt_recycler.c
tools/mserver/mserver5.c
Branch: default
Log Message:
More code reductions on recycler.
diffs (truncated from 816 to 300 lines):
diff --git a/monetdb5/mal/Tests/recycle01.mal b/monetdb5/mal/Tests/recycle01.mal
--- a/monetdb5/mal/Tests/recycle01.mal
+++ b/monetdb5/mal/Tests/recycle01.mal
@@ -12,6 +12,7 @@ barrier i:= 0:oid;
bat.append(b,i);
redo i:= iterator.next(1:oid,11:oid);
exit i;
+ io.print(tid);
return tid:= b;
end tid;
@@ -29,14 +30,18 @@ function sql.bind(mvc:int, s:str,t:str,c
bat.insert(b,9@0,9);
bat.insert(b,10@0,10);
bat.insert(b,11@0,11);
+ io.print(b);
return bind:=b;
end bind;
function qry(low:int, hgh:int);
m:= sql.mvc();
x:bat[:oid,:oid] := sql.tid(m,"sys","tbl");
+ io.print(x);
b:bat[:oid,:int]:= sql.bind(m,"sys","tbl","col",0);
+ io.print(b);
s:= algebra.subselect(b,x,low,hgh,true,true,false);
+ io.print(s);
end qry;
optimizer.recycler("user","qry");
diff --git a/monetdb5/mal/mal.h b/monetdb5/mal/mal.h
--- a/monetdb5/mal/mal.h
+++ b/monetdb5/mal/mal.h
@@ -68,6 +68,7 @@ mal_export char *mal_trace; /*
enable
#define GRPperformance (JOINPROPMASK | DEADBEEFMASK)
#define GRPoptimizers (OPTMASK)
#define GRPforcemito (FORCEMITOMASK)
+#define GRPrecycler (1<<30)
/*
* @-
* @node Execution Engine, Session Scenarios, MAL Synopsis , Design Overview
diff --git a/monetdb5/mal/mal_interpreter.c b/monetdb5/mal/mal_interpreter.c
--- a/monetdb5/mal/mal_interpreter.c
+++ b/monetdb5/mal/mal_interpreter.c
@@ -547,9 +547,7 @@ str runMALsequence(Client cntxt, MalBlkP
}
runtimeProfileBegin(cntxt, mb, stk, stkpc, &runtimeProfile, 1);
- if (pci->recycle > 0)
- clk = GDKms();
- if (!RECYCLEentry(cntxt, mb, stk, pci, stkpc)){
+ if ( (clk =RECYCLEentry(cntxt, mb, stk, pci, stkpc)) ){
/* The interpreter loop
* The interpreter is geared towards execution a MAL
* procedure together with all its decendant
@@ -769,7 +767,7 @@ str runMALsequence(Client cntxt, MalBlkP
/* If needed recycle intermediate result */
if (pci->recycle > 0) {
- RECYCLEexit(cntxt, mb, stk, pci, stkpc,
clk);
+ RECYCLEexit(cntxt, mb, stk, pci, stkpc,
GDKms()- clk);
}
/* general garbage collection */
diff --git a/monetdb5/mal/mal_profiler.h b/monetdb5/mal/mal_profiler.h
--- a/monetdb5/mal/mal_profiler.h
+++ b/monetdb5/mal/mal_profiler.h
@@ -43,18 +43,14 @@ typedef struct RECSTAT {
int recycled0; /* recycled statements per query */
lng time0; /* time per query */
int curQ; /* index of current query in Qry Patterns array*/
- int recent; /* the most recent entry in RP touched by current
query */
+ int recent; /* the most recent entry in Recycler Pool touched by
current query */
int recycleMiss; /* DBG:count of misses due to cache eviction */
int recycleRem; /* DBG:count of removed entries */
lng ccCalls; /* Number of calls to cleanCache */
lng ccInstr; /* Number of instructions evicted by eviction policy*/
lng crdInstr; /* Number of instructions not admited in RP by CRD */
- int trans; /* Number of data transfer instructions */
- lng transKB; /* Size in KB of transferred data */
- int recTrans; /* Number of recycled data transfer instructions */
- lng recTransKB; /* Size in KB of recycled transferred data */
- int RPadded0; /* Number of instructions added to RP per query */
- int RPreset0; /* Number of instructions evicted from RP by reset()
due to updates*/
+ int RPadded0; /* Number of instructions added to Recycler Pool per
query */
+ int RPreset0; /* Number of instructions evicted from Recycler Pool
by reset() due to updates*/
} *RecPtr, RecStat;
#define PROFevent 0
diff --git a/monetdb5/mal/mal_recycle.c b/monetdb5/mal/mal_recycle.c
--- a/monetdb5/mal/mal_recycle.c
+++ b/monetdb5/mal/mal_recycle.c
@@ -76,14 +76,11 @@ MalBlkPtr recycleBlk = NULL;
#define getbit(x,i) ( x & ((lng)1 << i) )
#define neg(x) ( (x)?FALSE:TRUE)
-static void RECYCLEexitImpl(Client cntxt,MalBlkPtr mb, MalStkPtr stk, InstrPtr
p, int pc, lng ticks);
/* ADM_ALL: infinite case, admission of all instructions subject to cache
limits*/
lng recycleTime = 0;
lng recycleSearchTime = 0; /* cache search time in ms*/
-lng msFindTime = 0; /* multi-subsume measurements */
-lng msComputeTime = 0;
int recycleMaxInterest = REC_MAX_INTEREST;
/* REUSE_COVER: exploit potential range overlap */
@@ -92,7 +89,6 @@ int reusePolicy = REUSE_COVER;
/* evict items with smallest profit= weight * cost / lifetime adds aging
to the benefit policy */
int recycleCacheLimit=0; /* No limit by default */
-lng recycleMemory=0; /* Units of memory permitted */
/*
* Monitoring the Recycler
@@ -127,15 +123,8 @@ int monitorRecycler = 0;
#define recycleLife(X) ((GDKusec() - recycleBlk->profiler[X].rbytes)/ 1000.0)
#define recycleProfit(X) (recycleCost(X) * recycleW(X) / recycleLife(X))
-
-#define setIPtr(q,i,cst,c)
\
- do {
\
- VALset(&cst,TYPE_int,&i);
\
- c = defConstant(recycleBlk,TYPE_int, &cst); \
- q = pushArgument(recycleBlk,q,c);
\
- setVarUsed(recycleBlk,c);
\
- } while (0)
-
+static str octopusRef = 0, bindRef = 0, bind_idxRef = 0, sqlRef = 0;
+static str subselectRef = 0, thetasubselectRef = 0, like_subselectRef = 0;
/*
* The recycler keeps a catalog of query templates
* with statistics about number of calls, global/local reuses,
@@ -153,6 +142,14 @@ void RECYCLEinitRecyclePool(int sz)
recyclePool->ptrn = (QryStatPtr *) GDKzalloc(sz *
sizeof(QryStatPtr));
recyclePool->sz = sz;
}
+ octopusRef = putName("octopus",7);
+ sqlRef = putName("sql",3);
+ bindRef = putName("bind",4);
+ bind_idxRef = putName("bind_idxbat",11);
+ subselectRef = putName("subselect",9);
+ thetasubselectRef = putName("thetasubselect",14);
+ like_subselectRef= putName("like_subselect",14);
+ recycleCacheLimit=HARDLIMIT_STMT;
MT_lock_unset(&recycleLock, "recycle");
}
}
@@ -222,12 +219,12 @@ int RECYCLEnewQryStat(MalBlkPtr mb)
return idx;
}
+/*
static void updateQryStat(int qidx, bit gluse, int i)
{
QryStatPtr qs;
if ( qidx < 0 || qidx >= recyclePool->cnt){
- /* fprintf(stderr, "Query pattern %d does not exist\n",qidx);*/
return;
}
qs = recyclePool->ptrn[qidx];
@@ -238,6 +235,7 @@ static void updateQryStat(int qidx, bit
}
else qs->lreuse++;
}
+*/
static void emptyRecyclePool(RecyclePool q)
{
@@ -429,7 +427,7 @@ static void RECYCLEcleanCache(Client cnt
lng oldclk, wr;
dbl minben, ben;
bte *used;
- lng memLimit = recycleMemory?recycleMemory:HARDLIMIT_MEM;
+ lng memLimit = monet_memory;
if (!recycleBlk)
return;
@@ -519,8 +517,7 @@ newpass:
#ifdef _DEBUG_CACHE_
- mnstr_printf(cntxt->fdout,"\n#RECYCLEcleanCache: policy=PROFIT
mem="LLFMT" usedmem="LLFMT"\n",
- recycleMemory,recyclerMemoryUsed);
+ mnstr_printf(cntxt->fdout,"\n#RECYCLEcleanCache: policy=PROFIT
usedmem="LLFMT"\n", recyclerMemoryUsed);
mnstr_printf(cntxt->fdout,"#Target memory "LLFMT"KB Available
"LLFMT"KB\n", wr,memLimit-recyclerMemoryUsed);
mnstr_printf(cntxt->fdout,"#Candidates for eviction\n#(#
LRU\t\tTicks\tLife\tSZ\tCnt\tWgt\tBen\tProf)\n");
for (l = 0; l < ltop; l++)
@@ -658,19 +655,8 @@ RECYCLEinterest(InstrPtr p){
bit
isBindInstr(InstrPtr p)
{
- static str sqlRef = 0, bindRef = 0, binddbatRef = 0, bindidxRef = 0;
-
- if (sqlRef == 0) {
- sqlRef = putName("sql",3);
- bindRef = putName("bind",4);
- binddbatRef = putName("bind_dbat",9);
- bindidxRef = putName("bind_idxbat",11);
- }
-
if ( getModuleId(p) != sqlRef ) return 0;
- return ( bindRef == getFunctionId(p) ||
- binddbatRef == getFunctionId(p) ||
- bindidxRef == getFunctionId(p));
+ return ( bindRef == getFunctionId(p) || bind_idxRef ==
getFunctionId(p));
}
#ifdef _DEBUG_CACHE_
@@ -717,14 +703,9 @@ setSelectProp(InstrPtr q)
ptr nilptr = NULL;
int (*cmp) (const void *, const void *) = NULL;
- static str subselectRef = 0, thetasubselectRef = 0;
int tlbProp = PropertyIndex("tlb");
int tubProp = PropertyIndex("tub");
- if (subselectRef == 0)
- subselectRef = putName("subselect",9);
- if (thetasubselectRef == 0)
- thetasubselectRef = putName("thetasubselect",14);
if ( ((getFunctionId(q) == subselectRef ) || (getFunctionId(q) ==
thetasubselectRef )) &&
@@ -805,40 +786,24 @@ setSelectProp(InstrPtr q)
}
static void
-RECYCLEkeep(Client cntxt, MalBlkPtr mb, MalStkPtr s, InstrPtr p, int pc, lng
rd, lng wr, lng ticks)
+RECYCLEkeep(Client cntxt, MalBlkPtr mb, MalStkPtr s, InstrPtr p, int pc, lng
rd, lng wr, lng clk)
{
int i, j, c;
ValRecord *v;
ValRecord cst;
InstrPtr q;
lng memLimit;
- lng cacheLimit;
- static str octopusRef = 0, bindRef = 0, bindidxRef = 0;
- if (octopusRef == 0)
- octopusRef = putName("octopus",7);
- if (bindRef == 0)
- bindRef = putName("bind",4);
- if (bindidxRef == 0)
- bindidxRef = putName("bind_idxbat",11);
+ (void) mb;
+ (void) pc;
-/* (void) rd; */
RECYCLEspace();
- cacheLimit = recycleCacheLimit?recycleCacheLimit:HARDLIMIT_STMT;
- if ( recycleSize >= cacheLimit)
+ if ( recycleSize >= recycleCacheLimit)
return ; /* no more caching */
- memLimit = recycleMemory?recycleMemory:HARDLIMIT_MEM;
+ memLimit = monet_memory;
if ( recyclerMemoryUsed + wr > memLimit)
return ; /* no more caching */
-#ifdef _DEBUG_RECYCLE_
- mnstr_printf(cntxt->fdout,"#RECYCLE keep ");
- printTraceCall( cntxt->fdout,mb, s, getPC(mb,p),LIST_MAL_ALL);
- mnstr_printf(cntxt->fdout," Tolls %d\n",p->recycle);
-#else
- (void) cntxt;
- (void) mb;
-#endif
/*
* The instruction is copied and the variables are
* all assigned to the symbol table. This means the
@@ -852,7 +817,7 @@ RECYCLEkeep(Client cntxt, MalBlkPtr mb,
VALcopy(&cst,v);
c = fndConstant(recycleBlk, &cst, recycleBlk->vtop);
#ifdef _DEBUG_RECYCLE_
- printf("#CONSTANT %s %d\n", getVarName(mb,j), c);
+ //printf("#CONSTANT %s %d\n", getVarName(mb,j), c);
#endif
if (c<0)
c = defConstant(recycleBlk, v->vtype, &cst);
@@ -862,20 +827,19 @@ RECYCLEkeep(Client cntxt, MalBlkPtr mb,
setArg(q,i,c);
}
#ifdef _DEBUG_RECYCLE_
- mnstr_printf(cntxt->fdout,"#RECYCLE kept ");
- printInstruction( cntxt->fdout,recycleBlk, 0, q,LIST_MAL_ALL);
- mnstr_printf(cntxt->fdout,"\n");
+ mnstr_printf(cntxt->fdout,"#RECYCLE [%d] ",recycleBlk->stop);
+ printInstruction( cntxt->fdout,recycleBlk, 0, q,LIST_MAL_STMT);
+#else
+ (void) cntxt;
#endif
- setIPtr(q,pc,cst,c);
q->recycle = cntxt->rcc->curQ;
/* use the field to refer to the query-owner index in the query
pattern table */
pushInstruction(recycleBlk,q);
i = recycleBlk->stop-1;
-/* recycleBlk->profiler[i].rbytes = recycleBlk->profiler[i].clk =
GDKusec(); */
- recycleBlk->profiler[i].clk = GDKusec();
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list