Exemple #1
0
 def loadItems(self):
     ## Select 10% of the rows to be marked "original"
     originalRows = rand.selectUniqueIds(self.scaleParameters.items / 10, 1, self.scaleParameters.items)
     
     ## Load all of the items
     tuples = [ ]
     total_tuples = 0
     for i in range(1, self.scaleParameters.items+1):
         original = (i in originalRows)
         tuples.append(self.generateItem(i, original))
         total_tuples += 1
         if len(tuples) == self.batch_size:
             logging.debug("LOAD - %s: %5d / %d" % (constants.TABLENAME_ITEM, total_tuples, self.scaleParameters.items))
             self.handle.loadTuples(constants.TABLENAME_ITEM, tuples)
             tuples = [ ]
     ## FOR
     if len(tuples) > 0:
         logging.debug("LOAD - %s: %5d / %d" % (constants.TABLENAME_ITEM, total_tuples, self.scaleParameters.items))
         self.handle.loadTuples(constants.TABLENAME_ITEM, tuples)
Exemple #2
0
    def loadItems(self):
        ## Select 10% of the rows to be marked "original"
        originalRows = rand.selectUniqueIds(self.scaleParameters.items / 10, 1,
                                            self.scaleParameters.items)

        ## Load all of the items
        tuples = []
        total_tuples = 0
        for i in range(1, self.scaleParameters.items + 1):
            original = (i in originalRows)
            tuples.append(self.generateItem(i, original))
            total_tuples += 1
            if len(tuples) == self.batch_size:
                logging.debug("LOAD - %s: %5d / %d" %
                              (constants.TABLENAME_ITEM, total_tuples,
                               self.scaleParameters.items))
                self.handle.loadTuples(constants.TABLENAME_ITEM, tuples)
                tuples = []
        ## FOR
        if len(tuples) > 0:
            logging.debug("LOAD - %s: %5d / %d" %
                          (constants.TABLENAME_ITEM, total_tuples,
                           self.scaleParameters.items))
            self.handle.loadTuples(constants.TABLENAME_ITEM, tuples)
Exemple #3
0
    def loadWarehouse(self, w_id):
        logging.debug("LOAD - %s: %d / %d" %
                      (constants.TABLENAME_WAREHOUSE, w_id, len(self.w_ids)))

        ## WAREHOUSE
        w_tuples = [self.generateWarehouse(w_id)]
        self.handle.loadTuples(constants.TABLENAME_WAREHOUSE, w_tuples)

        ## DISTRICT
        d_tuples = []
        for d_id in range(1, self.scaleParameters.districtsPerWarehouse + 1):
            d_next_o_id = self.scaleParameters.customersPerDistrict + 1
            d_tuples = [self.generateDistrict(w_id, d_id, d_next_o_id)]

            c_tuples = []
            h_tuples = []

            ## Select 10% of the customers to have bad credit
            selectedRows = rand.selectUniqueIds(
                self.scaleParameters.customersPerDistrict / 10, 1,
                self.scaleParameters.customersPerDistrict)

            ## TPC-C 4.3.3.1. says that o_c_id should be a permutation of [1, 3000]. But since it
            ## is a c_id field, it seems to make sense to have it be a permutation of the
            ## customers. For the "real" thing this will be equivalent
            cIdPermutation = []

            for c_id in range(1,
                              self.scaleParameters.customersPerDistrict + 1):
                badCredit = (c_id in selectedRows)
                c_tuples.append(
                    self.generateCustomer(w_id, d_id, c_id, badCredit, True))
                h_tuples.append(self.generateHistory(w_id, d_id, c_id))
                cIdPermutation.append(c_id)
            ## FOR
            assert cIdPermutation[0] == 1
            assert cIdPermutation[
                self.scaleParameters.customersPerDistrict -
                1] == self.scaleParameters.customersPerDistrict
            shuffle(cIdPermutation)

            o_tuples = []
            ol_tuples = []
            no_tuples = []

            for o_id in range(1, self.scaleParameters.customersPerDistrict):
                o_ol_cnt = rand.number(constants.MIN_OL_CNT,
                                       constants.MAX_OL_CNT)

                ## The last newOrdersPerDistrict are new orders
                newOrder = ((self.scaleParameters.customersPerDistrict -
                             self.scaleParameters.newOrdersPerDistrict) < o_id)
                o_tuples.append(
                    self.generateOrder(w_id, d_id, o_id,
                                       cIdPermutation[o_id - 1], o_ol_cnt,
                                       newOrder))

                ## Generate each OrderLine for the order
                for ol_number in range(0, o_ol_cnt):
                    ol_tuples.append(
                        self.generateOrderLine(w_id, d_id, o_id, ol_number,
                                               self.scaleParameters.items,
                                               newOrder))
                ## FOR

                ## This is a new order: make one for it
                if newOrder: no_tuples.append([o_id, d_id, w_id])
            ## FOR

            self.handle.loadTuples(constants.TABLENAME_DISTRICT, d_tuples)
            self.handle.loadTuples(constants.TABLENAME_CUSTOMER, c_tuples)
            self.handle.loadTuples(constants.TABLENAME_ORDERS, o_tuples)
            self.handle.loadTuples(constants.TABLENAME_ORDER_LINE, ol_tuples)
            self.handle.loadTuples(constants.TABLENAME_NEW_ORDER, no_tuples)
            self.handle.loadTuples(constants.TABLENAME_HISTORY, h_tuples)
            self.handle.loadFinishDistrict(w_id, d_id)
        ## FOR

        ## Select 10% of the stock to be marked "original"
        s_tuples = []
        selectedRows = rand.selectUniqueIds(self.scaleParameters.items / 10, 1,
                                            self.scaleParameters.items)
        total_tuples = 0
        for i_id in range(1, self.scaleParameters.items + 1):
            original = (i_id in selectedRows)
            s_tuples.append(self.generateStock(w_id, i_id, original))
            total_tuples += 1
            if len(s_tuples) >= self.batch_size:
                logging.debug("LOAD - %s [W_ID=%d]: %5d / %d" %
                              (constants.TABLENAME_STOCK, w_id, total_tuples,
                               self.scaleParameters.items))
                self.handle.loadTuples(constants.TABLENAME_STOCK, s_tuples)
                s_tuples = []
        ## FOR
        if len(s_tuples) > 0:
            logging.debug("LOAD - %s [W_ID=%d]: %5d / %d" %
                          (constants.TABLENAME_STOCK, w_id, total_tuples,
                           self.scaleParameters.items))
            self.handle.loadTuples(constants.TABLENAME_STOCK, s_tuples)
Exemple #4
0
    def loadWarehouse(self, w_id):
        logging.debug("LOAD - %s: %d / %d" % (constants.TABLENAME_WAREHOUSE, w_id, len(self.w_ids)))
        
        ## WAREHOUSE
        w_tuples = [ self.generateWarehouse(w_id) ]
        self.handle.loadTuples(constants.TABLENAME_WAREHOUSE, w_tuples)

        ## DISTRICT
        d_tuples = [ ]
        for d_id in range(1, self.scaleParameters.districtsPerWarehouse+1):
            d_next_o_id = self.scaleParameters.customersPerDistrict + 1
            d_tuples = [ self.generateDistrict(w_id, d_id, d_next_o_id) ]
            
            c_tuples = [ ]
            h_tuples = [ ]
            
            ## Select 10% of the customers to have bad credit
            selectedRows = rand.selectUniqueIds(self.scaleParameters.customersPerDistrict / 10, 1, self.scaleParameters.customersPerDistrict)
            
            ## TPC-C 4.3.3.1. says that o_c_id should be a permutation of [1, 3000]. But since it
            ## is a c_id field, it seems to make sense to have it be a permutation of the
            ## customers. For the "real" thing this will be equivalent
            cIdPermutation = [ ]

            for c_id in range(1, self.scaleParameters.customersPerDistrict+1):
                badCredit = (c_id in selectedRows)
                c_tuples.append(self.generateCustomer(w_id, d_id, c_id, badCredit, True))
                h_tuples.append(self.generateHistory(w_id, d_id, c_id))
                cIdPermutation.append(c_id)
            ## FOR
            assert cIdPermutation[0] == 1
            assert cIdPermutation[self.scaleParameters.customersPerDistrict - 1] == self.scaleParameters.customersPerDistrict
            shuffle(cIdPermutation)
            
            o_tuples = [ ]
            ol_tuples = [ ]
            no_tuples = [ ]
            
            for o_id in range(1, self.scaleParameters.customersPerDistrict):
                o_ol_cnt = rand.number(constants.MIN_OL_CNT, constants.MAX_OL_CNT)
                
                ## The last newOrdersPerDistrict are new orders
                newOrder = ((self.scaleParameters.customersPerDistrict - self.scaleParameters.newOrdersPerDistrict) < o_id)
                o_tuples.append(self.generateOrder(w_id, d_id, o_id, cIdPermutation[o_id - 1], o_ol_cnt, newOrder))

                ## Generate each OrderLine for the order
                for ol_number in range(0, o_ol_cnt):
                    ol_tuples.append(self.generateOrderLine(w_id, d_id, o_id, ol_number, self.scaleParameters.items, newOrder))
                ## FOR

                ## This is a new order: make one for it
                if newOrder: no_tuples.append([o_id, d_id, w_id])
            ## FOR
            
            self.handle.loadTuples(constants.TABLENAME_DISTRICT, d_tuples)
            self.handle.loadTuples(constants.TABLENAME_CUSTOMER, c_tuples)
            self.handle.loadTuples(constants.TABLENAME_ORDERS, o_tuples)
            self.handle.loadTuples(constants.TABLENAME_ORDER_LINE, ol_tuples)
            self.handle.loadTuples(constants.TABLENAME_NEW_ORDER, no_tuples)
            self.handle.loadTuples(constants.TABLENAME_HISTORY, h_tuples)
            self.handle.loadFinishDistrict(w_id, d_id)
        ## FOR
        
        ## Select 10% of the stock to be marked "original"
        s_tuples = [ ]
        selectedRows = rand.selectUniqueIds(self.scaleParameters.items / 10, 1, self.scaleParameters.items)
        total_tuples = 0
        for i_id in range(1, self.scaleParameters.items+1):
            original = (i_id in selectedRows)
            s_tuples.append(self.generateStock(w_id, i_id, original))
            total_tuples += 1
            if len(s_tuples) >= self.batch_size:
                logging.debug("LOAD - %s [W_ID=%d]: %5d / %d" % (constants.TABLENAME_STOCK, w_id, total_tuples, self.scaleParameters.items))
                self.handle.loadTuples(constants.TABLENAME_STOCK, s_tuples)
                s_tuples = [ ]
        ## FOR
        if len(s_tuples) > 0:
            logging.debug("LOAD - %s [W_ID=%d]: %5d / %d" % (constants.TABLENAME_STOCK, w_id, total_tuples, self.scaleParameters.items))
            self.handle.loadTuples(constants.TABLENAME_STOCK, s_tuples)