def establishConnection(self, config, args, channel):
        ## ----------------------------------------------
        ## Connect to MongoDB
        ## ----------------------------------------------
        hostname = config.get(configutil.SECT_MONGODB, 'host')
        port = config.getint(configutil.SECT_MONGODB, 'port')
        assert hostname
        assert port
        try:
            conn = mongokit.Connection(host=hostname, port=port)
        except:
            LOG.error("Failed to connect to MongoDB at %s:%s" % (hostname, port))
            raise
        ## Register our objects with MongoKit
        conn.register([ catalog.Collection, workload.Session ])

        ## Make sure that the databases that we need are there
        db_names = conn.database_names()
        for key in [ 'dataset_db', ]: # FIXME 'workload_db' ]:
            if not config.has_option(configutil.SECT_MONGODB, key):
                raise Exception("Missing the configuration option '%s.%s'" % (configutil.SECT_MONGODB, key))
            elif not config.get(configutil.SECT_MONGODB, key):
                raise Exception("Empty configuration option '%s.%s'" % (configutil.SECT_MONGODB, key))
        ## FOR
        
        metadata_db = conn[config.get(configutil.SECT_MONGODB, 'metadata_db')]
        dataset_db = conn[config.get(configutil.SECT_MONGODB, 'dataset_db')]
        
        designer = Designer(config, metadata_db, dataset_db, channel)
        designer.setOptionsFromArguments(args)
        
        return designer
    ## DEF
    
## CLASS
Beispiel #2
0
    def setUp(self):
        TPCCTestCase.setUp(self)

        config = RawConfigParser()
        configutil.setDefaultValues(config)

        self.designer = Designer(config, self.metadata_db, self.dataset_db)
        self.dc = self.designer.generateDesignCandidates(self.collections, self.workload)
        self.assertIsNotNone(self.dc)
        
        # Make sure that we don't have any invalid candidate keys
        for col_name in self.collections.iterkeys():
            for index_keys in self.dc.indexKeys[col_name]:
                for key in index_keys:
                    assert not key.startswith(constants.REPLACE_KEY_DOLLAR_PREFIX), \
                        "Unexpected candidate key '%s.%s'" % (col_name, key)
Beispiel #3
0
class FindExpectedDesign(TPCCTestCase):
    """
        Try to see if the existing cost model could generate the best desgin we
        expected
    """
    def setUp(self):
        TPCCTestCase.setUp(self)

        config = RawConfigParser()
        configutil.setDefaultValues(config)

        self.designer = Designer(config, self.metadata_db, self.dataset_db)
        self.dc = self.designer.generateDesignCandidates(self.collections, self.workload)
        self.assertIsNotNone(self.dc)
        
        # Make sure that we don't have any invalid candidate keys
        for col_name in self.collections.iterkeys():
            for index_keys in self.dc.indexKeys[col_name]:
                for key in index_keys:
                    assert not key.startswith(constants.REPLACE_KEY_DOLLAR_PREFIX), \
                        "Unexpected candidate key '%s.%s'" % (col_name, key)
        ## FOR
        
    ## DEF

    def outtestfindExpectedDesign(self):
        """Perform the actual search for a design"""
        # Generate all the design candidates
        # Instantiate cost model
        cmConfig = {
            'weight_network': 4,
            'weight_disk':    1,
            'weight_skew':    1,
            'nodes':          10,
            'max_memory':     1024,
            'skew_intervals': 10,
            'address_size':   64,
            'window_size':    500
        }
        cm = CostModel(self.collections, self.workload, cmConfig)

        initialDesign = InitialDesigner(self.collections, self.workload, None).generate()
        upper_bound = cm.overallCost(initialDesign)
        print "init solution: ", initialDesign
        print "init solution cost: ", upper_bound
        collectionNames = [c for c in self.collections]
        
        dc = self.dc.getCandidates(collectionNames)
        print "candidates: ", dc
        ln = LNSDesigner(self.collections, \
                        self.dc, \
                        self.workload, \
                        None, \
                        cm, \
                        initialDesign, \
                        upper_bound, \
                        LNS_RUN_TIME)
        solution = ln.solve()
        print "Best cost: ", ln.bestCost
        print "solution: ", solution
Beispiel #4
0
        ]:
            if LOG.isEnabledFor(logging.DEBUG):
                LOG.warn("Dropping %s.%s", metadata_db.name, col_name)
            metadata_db.drop_collection(col_name)
        ## FOR

        for col_name in dataset_db.collection_names():
            if col_name.startswith("system"): continue
            if LOG.isEnabledFor(logging.DEBUG):
                LOG.warn("Dropping %s.%s" % (dataset_db.name, col_name))
            dataset_db.drop_collection(col_name)
        ## FOR
    ## IF

    # This designer is only used for input processing
    designer = Designer(config, metadata_db, dataset_db)
    designer.setOptionsFromArguments(args)

    if args['init_design']:
        designer.load(False, None, True)
        exit("Initial Design done")
    ## IF
    if args['input_design']:
        # evaluate the input design and then quit
        ds = Deserializer()
        ds.loadDesignFile(args['input_design'])
        replay_design = ds.Deserialize()
        LOG.info("Read in design\n%s", replay_design)
        designer.load(True, replay_design)
        exit("Design evaluation done")
    ## IF
Beispiel #5
0
        for col_name in [metadata_db.Session.collection.name, metadata_db.Collection.collection.name]:
            if LOG.isEnabledFor(logging.DEBUG):
                LOG.warn("Dropping %s.%s", metadata_db.name, col_name)
            metadata_db.drop_collection(col_name)
        ## FOR

        for col_name in dataset_db.collection_names():
            if col_name.startswith("system"): continue
            if LOG.isEnabledFor(logging.DEBUG):
                LOG.warn("Dropping %s.%s" % (dataset_db.name, col_name))
            dataset_db.drop_collection(col_name)
        ## FOR
    ## IF
    
    # This designer is only used for input processing
    designer = Designer(config, metadata_db, dataset_db)
    designer.setOptionsFromArguments(args)
    
    if args['init_design']:
        designer.load(False, None, True)
        exit("Initial Design done")
    ## IF
    if args['input_design']:
        # evaluate the input design and then quit
        ds = Deserializer()
        ds.loadDesignFile(args['input_design'])
        replay_design = ds.Deserialize()
        LOG.info("Read in design\n%s", replay_design)
        designer.load(True, replay_design)
        exit("Design evaluation done")
    ## IF