Changeset: 943935814f46 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=943935814f46
Modified Files:
        monetdb5/mal/mal_runtime.c
        monetdb5/mal/mal_runtime.h
        sql/backends/monet5/sql_execute.c
Branch: sessions
Log Message:

Move idle state marker to SQL.execute


diffs (187 lines):

diff --git a/monetdb5/mal/mal_runtime.c b/monetdb5/mal/mal_runtime.c
--- a/monetdb5/mal/mal_runtime.c
+++ b/monetdb5/mal/mal_runtime.c
@@ -10,6 +10,7 @@
  * The MAL Runtime Profiler and system queue
  * This little helper module is used to perform instruction based profiling.
  * The QRYqueue is only update at the start/finish of a query. 
+ * It is also the place to keep track on the number of workers
  */
 
 #include "monetdb_config.h"
@@ -29,16 +30,6 @@ lng qtop;
 static lng qsize;
 static oid qtag= 1;            // A unique query identifier
 
-#define QRYreset(I)\
-               if (QRYqueue[I].query) GDKfree(QRYqueue[I].query);\
-               QRYqueue[I].cntxt = 0; \
-               QRYqueue[I].tag = 0; \
-               QRYqueue[I].query = 0; \
-               QRYqueue[I].status =0; \
-               QRYqueue[I].progress =0; \
-               QRYqueue[I].stk =0; \
-               QRYqueue[I].mb =0; \
-
 void
 mal_runtime_reset(void)
 {
@@ -49,7 +40,8 @@ mal_runtime_reset(void)
        qtag= 1;
 }
 
-static str isaSQLquery(MalBlkPtr mb){
+static str 
+isaSQLquery(MalBlkPtr mb){
        int i;
        InstrPtr p;
        if (mb)
@@ -58,7 +50,7 @@ static str isaSQLquery(MalBlkPtr mb){
                if ( getModuleId(p) && idcmp(getModuleId(p), "querylog") == 0 
&& idcmp(getFunctionId(p),"define")==0)
                        return getVarConstant(mb,getArg(p,1)).val.sval;
        }
-       return 0;
+       return NULL;
 }
 
 /*
@@ -80,15 +72,15 @@ runtimeProfileInit(Client cntxt, MalBlkP
                QRYqueue = (QueryQueue) GDKrealloc( QRYqueue, sizeof (struct 
QRYQUEUE) * (size_t) (qsize += 256));
        if ( QRYqueue == NULL){
                addMalException(mb,"runtimeProfileInit" MAL_MALLOC_FAIL);
-               GDKfree(tmp);                   /* may be NULL, but doesn't 
harm */
+               GDKfree(tmp);                   
                MT_lock_unset(&mal_delayLock);
                return;
        }
-       // check for recursive call
+       // check for recursive call, which does not change the number of workers
        for( i = 0; i < qtop; i++)
                if ( QRYqueue[i].mb == mb &&  stk->up == QRYqueue[i].stk){
                        QRYqueue[i].stk = stk;
-                       stk->tag = QRYqueue[i].tag;
+                       mb->tag = stk->tag = qtag++;
                        MT_lock_unset(&mal_delayLock);
                        return;
                }
@@ -97,7 +89,6 @@ runtimeProfileInit(Client cntxt, MalBlkP
        if (i == qtop) {
                QRYqueue[i].mb = mb;
                QRYqueue[i].tag = qtag++;
-               mb->tag = QRYqueue[i].tag;
                QRYqueue[i].stk = stk;                          // for status 
pause 'p'/running '0'/ quiting 'q'
                QRYqueue[i].start = time(0);
                QRYqueue[i].runtime = mb->runtime;      // the estimated 
execution time
@@ -105,13 +96,16 @@ runtimeProfileInit(Client cntxt, MalBlkP
                QRYqueue[i].query = q? GDKstrdup(q):0;
                QRYqueue[i].status = "running";
                QRYqueue[i].cntxt = cntxt;
+               QRYqueue[i].workers++;
+               stk->tag = mb->tag = QRYqueue[i].tag;
        }
-       stk->tag = QRYqueue[i].tag;
        qtop += i == qtop;
        MT_lock_unset(&mal_delayLock);
 }
 
-/* We should keep a short list of previously executed queries/client for 
inspection */
+/* We should keep a short list of previously executed queries/client for 
inspection.
+ * Returning from a recursive call does not change the number of workers.
+ */
 
 void
 runtimeProfileFinish(Client cntxt, MalBlkPtr mb, MalStkPtr stk)
@@ -129,24 +123,29 @@ runtimeProfileFinish(Client cntxt, MalBl
                if( stk->up){
                        // recursive call
                        QRYqueue[i].stk = stk->up;
+                       mb->tag = stk->tag;
                        MT_lock_unset(&mal_delayLock);
                        return;
                }
-               QRYqueue[i].mb->calls++;
-               QRYqueue[i].mb->runtime += (lng) ((lng)(time(0) - 
QRYqueue[i].start) * 1000.0/QRYqueue[i].mb->calls);
                QRYqueue[i].status = "finished";
-               QRYreset(i)
+               GDKfree(QRYqueue[i].query);
+               QRYqueue[i].cntxt = 0;
+               QRYqueue[i].tag = 0;
+               QRYqueue[i].query = 0;
+               QRYqueue[i].status =0;
+               QRYqueue[i].progress =0;
+               QRYqueue[i].stk =0;
+               QRYqueue[i].mb =0;
        }
 
        qtop = j;
        QRYqueue[qtop].query = NULL; /* sentinel for SYSMONqueue() */
-       cntxt->idle = time(0);
-       cntxt->lastcmd = 0;
-       QRYqueue[qtop].workers = 0;
+       QRYqueue[qtop].workers--;
        QRYqueue[qtop].memory= 0;
        MT_lock_unset(&mal_delayLock);
 }
 
+/* When the client connection is closed, then also the queue should be updated 
*/
 void
 finishSessionProfiler(Client cntxt)
 {
@@ -159,12 +158,11 @@ finishSessionProfiler(Client cntxt)
        if ( QRYqueue[i].cntxt != cntxt)
                QRYqueue[j++] = QRYqueue[i];
        else  {
-               //reset entry
-               if (QRYqueue[i].query)
-                       GDKfree(QRYqueue[i].query);
+               GDKfree(QRYqueue[i].query);
                QRYqueue[i].cntxt = 0;
                QRYqueue[i].tag = 0;
                QRYqueue[i].query = 0;
+               QRYqueue[i].progress =0;
                QRYqueue[i].status =0;
                QRYqueue[i].stk =0;
                QRYqueue[i].mb =0;
diff --git a/monetdb5/mal/mal_runtime.h b/monetdb5/mal/mal_runtime.h
--- a/monetdb5/mal/mal_runtime.h
+++ b/monetdb5/mal/mal_runtime.h
@@ -34,7 +34,7 @@ typedef struct QRYQUEUE{
        time_t start;
        int             progress;               /* percentage of MAL 
instructions handled */
        int             workers;                /* Actual number of concurrent 
workers */
-       lng             memory; /* Actual memory claim highwater mark */
+       int             memory; /* Actual memory claim highwater mark */
        lng runtime;
 } *QueryQueue;
 mal_export lng qtop;
diff --git a/sql/backends/monet5/sql_execute.c 
b/sql/backends/monet5/sql_execute.c
--- a/sql/backends/monet5/sql_execute.c
+++ b/sql/backends/monet5/sql_execute.c
@@ -376,18 +376,26 @@ SQLrun(Client c, backend *be, mvc *m)
                if (c->curprg->def)
                        printFunction(c->fdout, mb, 0, LIST_MAL_NAME | 
LIST_MAL_VALUE  | LIST_MAL_TYPE |  LIST_MAL_MAPI);
        } else if( m->emod & mod_debug) {
+               c->idle = 0;
+               c->lastcmd = time(0);
                msg = runMALDebugger(c, mb);
        } else {
                if( m->emod & mod_trace){
                        if((msg = SQLsetTrace(c,mb)) == MAL_SUCCEED) {
+                               c->idle = 0;
+                               c->lastcmd = time(0);
                                msg = runMAL(c, mb, 0, 0);
                                stopTrace(c);
                        }
                } else {
+                               c->idle = 0;
+                               c->lastcmd = time(0);
                        msg = runMAL(c, mb, 0, 0);
                }
        }
-
+       /* after the query has been finished we enter the idle state */
+       c->idle = time(0);
+       c->lastcmd = 0;
        // release the resources
        freeMalBlk(mb);
        MT_thread_setworking(NULL);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to