Changeset: ff65dbbb6d7f for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ff65dbbb6d7f
Modified Files:
        clients/Tests/exports.stable.out
        monetdb5/mal/mal.h
        monetdb5/optimizer/opt_mitosis.c
        monetdb5/optimizer/opt_mitosis.h
        sql/backends/monet5/sql_scenario.c
Branch: default
Log Message:

Recompile plan when concurrency level changed
Keep track of the number of active users in the MAL block
when you apply the mitosis optimizer. It can optionally
be re-compiled by the client when the load  changes.


diffs (171 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -1683,6 +1683,7 @@ int OPTmacroImplementation(Client cntxt,
 int OPTmatpackImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
 int OPTmergetableImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr p);
 int OPTmitosisImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr p);
+int OPTmitosisPlanOverdue(Client cntxt, str fname);
 int OPTmultiplexImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
 str OPTmultiplexSimple(Client cntxt);
 str OPTorcam(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p);
diff --git a/monetdb5/mal/mal.h b/monetdb5/mal/mal.h
--- a/monetdb5/mal/mal.h
+++ b/monetdb5/mal/mal.h
@@ -212,6 +212,7 @@ typedef struct MALBLK {
        lng runtime;                            /* average execution time of 
block in ticks */
        int calls;                                      /* number of calls */
        lng optimize;                           /* total optimizer time */
+       int activeClients;                      /* load during mitosis 
optimization */
 } *MalBlkPtr, MalBlkRecord;
 
 #define STACKINCR   128
diff --git a/monetdb5/optimizer/opt_mitosis.c b/monetdb5/optimizer/opt_mitosis.c
--- a/monetdb5/optimizer/opt_mitosis.c
+++ b/monetdb5/optimizer/opt_mitosis.c
@@ -1,9 +1,20 @@
 /*
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0.  If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
  *
- * Copyright 2008-2015 MonetDB B.V.
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2015 MonetDB B.V.
+ * All Rights Reserved.
  */
 
 #include "monetdb_config.h"
@@ -41,6 +52,21 @@ getVarMergeTableId(MalBlkPtr mb, int v)
        return -1;
 }
 
+
+/* The plans are marked with the concurrent user load.
+ *  * If this has changed, we may want to recompile the query
+ *   */
+int
+OPTmitosisPlanOverdue(Client cntxt, str fname)
+{
+    Symbol s;
+
+    s = findSymbol(cntxt->nspace, userRef, fname);
+    if(s )
+        return s->def->activeClients != MCactiveClients();
+    return 0;
+}
+
 int
 OPTmitosisImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
 {
@@ -51,12 +77,14 @@ OPTmitosisImplementation(Client cntxt, M
        size_t argsize = 6 * sizeof(lng);
        /*     per op:   6 = (2+1)*2   <=  2 args + 1 res, each with head & 
tail */
        int threads = GDKnr_threads ? GDKnr_threads : 1;
+       int activeClients;
 
        (void) cntxt;
        (void) stk;
        if (!eligible(mb))
                return 0;
 
+       activeClients = mb->activeClients = MCactiveClients();
        old = mb->stmt;
        for (i = 1; i < mb->stop; i++) {
                InstrPtr p = old[i];
@@ -116,19 +144,22 @@ OPTmitosisImplementation(Client cntxt, M
         * threads than strictly needed.
         * Experience shows that the pieces should not be too small.
         * If we should limit to |threads| is still an open issue.
+        *
+        * Take into account the number of client connections, 
+        * because all user together are responsible for resource contentions
         */
-       r = (wrd) (monet_memory / argsize/ MCactiveClients());
+       r = (wrd) (monet_memory / argsize);
        /* if data exceeds memory size,
         * i.e., (rowcnt*argsize > monet_memory),
         * i.e., (rowcnt > monet_memory/argsize = r) */
-       if (rowcnt > r && r / threads > 0) {
+       if (rowcnt > r && r / threads / activeClients > 0) {
                /* create |pieces| > |threads| partitions such that
                 * |threads| partitions at a time fit in memory,
                 * i.e., (threads*(rowcnt/pieces) <= r),
                 * i.e., (rowcnt/pieces <= r/threads),
                 * i.e., (pieces => rowcnt/(r/threads))
                 * (assuming that (r > threads*MINPARTCNT)) */
-               pieces = (int) (rowcnt / (r / threads/ MCactiveClients())) + 1;
+               pieces = (int) (rowcnt / (r / threads / activeClients)) + 1;
        } else if (rowcnt > MINPARTCNT) {
        /* exploit parallelism, but ensure minimal partition size to
         * limit overhead */
diff --git a/monetdb5/optimizer/opt_mitosis.h b/monetdb5/optimizer/opt_mitosis.h
--- a/monetdb5/optimizer/opt_mitosis.h
+++ b/monetdb5/optimizer/opt_mitosis.h
@@ -15,6 +15,7 @@
 #define MINPARTCNT 100000      /* minimal record count per partition */
 
 opt_export int OPTmitosisImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr 
stk, InstrPtr p);
+opt_export int OPTmitosisPlanOverdue(Client cntxt, str fname);
 
 #define OPTDEBUGmitosis  if ( optDebug & ((lng)1 <<DEBUG_OPT_MITOSIS) )
 
diff --git a/sql/backends/monet5/sql_scenario.c 
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -50,6 +50,7 @@
 #include "opt_statistics.h"
 #include "opt_prelude.h"
 #include "opt_pipes.h"
+#include "opt_mitosis.h"
 #include <unistd.h>
 #include "sql_upgrades.h"
 
@@ -1102,9 +1103,21 @@ SQLparser(Client c)
                        sqlcleanup(m, err);
                        goto finalize;
                }
+               // look for outdated plans
+               if ( OPTmitosisPlanOverdue(c,be->q->name) ){
+                       msg = SQLCacheRemove(c, be->q->name);
+                       qc_delete(be->mvc->qc, be->q);
+                       goto recompilequery;
+               }
                m->emode = m_inplace;
                scanner_query_processed(&(m->scanner));
        } else if (caching(m) && cachable(m, NULL) && m->emode != m_prepare && 
(be->q = qc_match(m->qc, m->sym, m->args, m->argc, m->scanner.key ^ 
m->session->schema->base.id)) != NULL) {
+               // look for outdated plans
+               if ( OPTmitosisPlanOverdue(c,be->q->name) ){
+                       msg = SQLCacheRemove(c, be->q->name);
+                       qc_delete(be->mvc->qc, be->q);
+                       goto recompilequery;
+               }
 
                if (m->emod & mod_debug)
                        SQLsetDebugger(c, m, TRUE);
@@ -1114,8 +1127,11 @@ SQLparser(Client c)
                        m->emode = m_inplace;
                scanner_query_processed(&(m->scanner));
        } else {
-               sql_rel *r = sql_symbol2relation(m, m->sym);
-               stmt *s = sql_relation2stmt(m, r);
+               sql_rel *r;
+               stmt *s;
+recompilequery:
+               r = sql_symbol2relation(m, m->sym);
+               s = sql_relation2stmt(m, r);
 
                if (s == 0 || (err = mvc_status(m) && m->type != Q_TRANS)) {
                        msg = createException(PARSE, "SQLparser", "%s", 
m->errstr);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to