Sepasoft MES Module Suite
Load Testing a Batch Procedure System
Python |
import pprint, time, random def createUnits(prefix, maxCount): for i in range(1,(maxCount+1)): unitName = prefix+str(i) try: eqpLink = system.mes.getMESObjectLinkByName('Unit',unitName) eqp = eqpLink.getMESObject() eqp.setActive(True) eqp.save() except: eqp = system.mes.createMESObject('Unit') eqp.setName(unitName) eqp.setEquipmentPath('Enterprise\Site\Area\Process Cell\'+unitName) eqp.setActive(True) parentLink = system.mes.getMESObjectLinkByName('ProcessCell','Process Cell') parent = parentLink.getMESObject() eqp.addParent(parent) eqp.save() for i in range(maxCount+1,300): unitName = prefix+str(i) try: eqpLink = system.mes.getMESObjectLinkByName('Unit',unitName) eqp = eqpLink.getMESObject() eqp.setActive(False) eqp.save() except: pass def addUnitsToClass(prefix, maxCount): for i in range(1,(maxCount+1)): unitName = prefix+str(i) unitClass = 'Mixer' unitLink = system.mes.batch.unit.getLink(unitName) unitClassLink = system.mes.batch.unitclass.getLink(unitClass) system.mes.batch.unit.assignUnitClass(unitLink, unitClassLink) def printAllocList(): allocList = system.mes.batch.unit.getAllocationList(0, 1000, 'aUnit', True, False) for al in allocList: print(al) al.getAllocatedEquipmentPath() def addBatches(prefix, minID, maxID, recipeName): #cls = system.mes.batch.recipe.loadRecipeClass('Master Routes', None) for i in range(minID,(maxID+1)): batchID = prefix+str(i) masterRecipeLink = system.mes.batch.recipe.getRecipeLink(recipeName, None) # system.mes.batch.queue.addEntry(masterRecipeLink, batchID, batchID, processCellPath = 'Enterprise\Site\Area\Process Cell') # print 'Adding Batch Entry: ' + batchID try: system.mes.batch.queue.addEntry(masterRecipeLink, batchID, batchID, processCellPath = 'Enterprise\Site\Area\Process Cell') print 'Adding Batch Entry: ' + batchID except: pass def clearOldBatches(prefix, minID, maxID): for i in range(minID,(maxID+1)): batchID = prefix+str(i) try: bqe = system.mes.batch.queue.getEntry(batchID) batchState = bqe.batchState print 'Clearing batch: ' + batchID if batchState == 'HELD': system.mes.batch.queue.executeEntryCommand(bqe, 'RESTART') system.mes.batch.queue.executeEntryCommand(bqe, 'ABORT') if batchState == 'RUNNING': system.mes.batch.queue.executeEntryCommand(bqe, 'ABORT') system.mes.batch.queue.executeEntryCommand(bqe, 'RESET') except: pass def restartHeldBatches(prefix, minID, maxID): for i in range(minID,(maxID+1)): allocList = system.mes.batch.unit.getAllocationList(0, 1000, 'aUnit', True, False) batchID = prefix+str(i) bqe = system.mes.batch.queue.getEntry(batchID) batchState = bqe.batchState if batchState == 'HELD': print 'Re-Starting batch: ' + batchID + ', len(allocList) = ' + str(len(allocList)) system.mes.batch.queue.executeEntryCommand(bqe, 'RESTART') def startSomeBatches(prefix, minID, maxID, unitCount, newBatchCount): allocList = system.mes.batch.unit.getAllocationList(0, 1000, 'aUnit', True, False) startCount = newBatchCount if unitCount > len(allocList) and unitCount < len(allocList) + startCount : startCount = unitCount - len(allocList) s = 0 i = minID #print 'Starting Batches: Units = ' + str(unitCount) +', Allocated = ' + str(len(allocList)) + ', To start = ' + str(startCount) while (s < startCount and i <= maxID): batchID = prefix+str(i) bqe = system.mes.batch.queue.getEntry(batchID) batchState = bqe.batchState if batchState == 'IDLE': system.mes.batch.queue.executeEntryCommand(bqe, 'START') allocList = system.mes.batch.unit.getAllocationList(0, 1000, 'aUnit', True, False) print ' Starting batch: ' + batchID s = s + 1 i = i + 1 def runBatches(prefix, minID, maxID, unitCount, newBatchCount, minRunning): stop = False onRise = True while (stop == False): if 1==1: # Restart held batches restartHeldBatches(prefix, minID, maxID) # If we have free units start up to 10 new batches startSomeBatches(prefix, minID, maxID, unitCount, newBatchCount) # set "stop" condition print '---' allocList = system.mes.batch.unit.getAllocationList(0, 1000, '', True, False) for au in allocList: print au.batchID + ' @ ' + au.allocatedEquipmentPath if len(allocList) >= minRunning: if onRise == True: print 'Set onRise > False' + ', len(allocList) = ' + str(len(allocList)) onRise = False if onRise == False and len(allocList) < 2: stop = True unit_prefix = 'aUnit' batch_prefix = 'aBatch' recipeName = 'Scripted1' minID = 41 maxID = minID+39 unitCount = 10 newBatchCount = 5 minRunning = 2 enabled = 5 if enabled == 1: createUnits(unit_prefix, unitCount) if enabled == 2: addUnitsToClass(unit_prefix, unitCount) if enabled == 3: addBatches(batch_prefix, minID, maxID, recipeName) if enabled == 4: runBatches(batch_prefix, minID, maxID, unitCount, newBatchCount, minRunning) if enabled == 5: clearOldBatches(batch_prefix,minID,maxID) #### server 1 = gateway A #### laptop 1 = that can simulate 3 or 4 users #### laptop 2 = that can simulate 3 or 4 users #### laptop 3 = that can simulate 3 or 4 users |
Sepasoft MES Module Suite