Search in sources :

Example 6 with UsageScenario

use of org.palladiosimulator.pcm.usagemodel.UsageScenario in project iobserve-analysis by research-iobserve.

the class UsageModelFactory method createUsageScenario.

/**
 * Create new usage scenario and add it to the passed usage model.
 *
 * @param name
 *            of the usage scenario
 * @param usageModel
 *            the usage scenario is added to
 * @return created usage scenario
 */
public static UsageScenario createUsageScenario(final String name, final UsageModel usageModel) {
    // create the usage scenario
    final UsageScenario usageScenario = UsagemodelFactory.eINSTANCE.createUsageScenario();
    usageScenario.setEntityName(name);
    usageScenario.setUsageModel_UsageScenario(usageModel);
    usageModel.getUsageScenario_UsageModel().add(usageScenario);
    // create a scenario behavior
    final ScenarioBehaviour scenarioBehaviour = UsageModelFactory.createScenarioBehaviour();
    usageScenario.setScenarioBehaviour_UsageScenario(scenarioBehaviour);
    return usageScenario;
}
Also used : UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)

Example 7 with UsageScenario

use of org.palladiosimulator.pcm.usagemodel.UsageScenario in project iobserve-analysis by research-iobserve.

the class SimpleSequenceReference method getModel.

/**
 * Creates a reference model that contains a simple sequence of calls. Accordingly, user
 * sessions whose call sequences contain a simple call sequence are created. (RQ-1.1) It is also
 * used to evaluate the accuracy of workload specifications. Therefore, varying workload is
 * generated by random entry and exit times of the user sessions, a random number of user
 * sessions for a closed workload specification and a random mean inter arrival time for an open
 * workload specification (RQ-1.9)
 *
 * @param referenceUsageModelFileName
 *            file name of the reference model to store its result
 * @param repositoryLookupModel
 *            repository lookup model
 * @param correspondenceModel
 *            correspondence model
 * @param thinkTime
 *            of a closed workload.
 * @param isClosedWorkload
 *            decides whether a closed or an open workload is created
 * @return the reference usage model, a corresponding EntryCallSequenceModel and a reference
 *         workload
 * @throws IOException
 *             on error
 */
public static ReferenceElements getModel(final String referenceUsageModelFileName, final RepositoryLookupModelProvider repositoryLookupModel, final ICorrespondence correspondenceModel, final int thinkTime, final boolean isClosedWorkload) throws IOException {
    // Creates a random number of user sessions and random model element parameters. The user
    // sessions' behavior will be created according to the reference usage model and
    // subsequently the user sessions are used to create a usage model. The created usage model
    // is matched against the reference usage model.
    final int numberOfUsersSessions = TestHelper.getRandomInteger(200, 1);
    final int numberOfCalls = TestHelper.getRandomInteger(5, 1);
    final EntryCallSequenceModel entryCallSequenceModel = new EntryCallSequenceModel(TestHelper.getUserSessions(numberOfUsersSessions));
    final ReferenceElements referenceElements = new ReferenceElements();
    // In the following the reference usage model is created
    final UsageModel usageModel = UsageModelFactory.createUsageModel();
    final UsageScenario usageScenario = UsageModelFactory.createUsageScenario("", usageModel);
    final ScenarioBehaviour scenarioBehaviour = usageScenario.getScenarioBehaviour_UsageScenario();
    final Start start = UsageModelFactory.createAddStartAction("", scenarioBehaviour);
    final Stop stop = UsageModelFactory.createAddStopAction("", scenarioBehaviour);
    AbstractUserAction lastAction = start;
    Optional<Correspondent> correspondent;
    // created
    for (int i = 0; i < numberOfCalls; i++) {
        if (i >= 0 && i < 5) {
            correspondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[i], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[i]);
        } else {
            throw new IllegalArgumentException("Illegal value of model element parameter");
        }
        if (correspondent.isPresent()) {
            final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, correspondent.get());
            UsageModelFactory.addUserAction(scenarioBehaviour, entryLevelSystemCall);
            UsageModelFactory.connect(lastAction, entryLevelSystemCall);
            lastAction = entryLevelSystemCall;
        }
    }
    UsageModelFactory.connect(lastAction, stop);
    // According to the reference usage model user sessions are created that exactly represent
    // the user behavior of the reference usage model. The entry and exit times are set randomly
    // to evaluate a closed workload. For the evaluation of an open workload the mean inter
    // arrival time is set randomly
    int entryTime = 0;
    int exitTime = 1;
    final int meanInterArrivalTime = TestHelper.getRandomInteger(30, 1);
    for (int i = 0; i < entryCallSequenceModel.getUserSessions().size(); i++) {
        if (isClosedWorkload) {
            entryTime = TestHelper.getRandomInteger(30, 1);
            exitTime = entryTime + 1;
        } else {
            entryTime += meanInterArrivalTime;
            exitTime += meanInterArrivalTime;
        }
        for (int k = 0; k < numberOfCalls; k++) {
            EntryCallEvent entryCallEvent = null;
            if (k >= 0 && k < 5) {
                entryCallEvent = new EntryCallEvent(entryTime, exitTime, ReferenceUsageModelBuilder.OPERATION_SIGNATURE[k], ReferenceUsageModelBuilder.CLASS_SIGNATURE[k], String.valueOf(i), "hostname");
            } else {
                throw new IllegalArgumentException("Illegal value of model element parameter");
            }
            entryCallSequenceModel.getUserSessions().get(i).add(entryCallEvent, true);
            entryTime = entryTime + 2;
            exitTime = exitTime + 2;
        }
    }
    // Saves the reference usage model and sets the usage model, the EntryCallSequenceModel
    // and the workload as the reference elements. Our approach is now executed with the
    // EntryCallSequenceModel and the resulting usage model can be matched against the reference
    // usage model. Alike, the by our approach calculated workload can be matched against the
    // reference workload. This is done by {@link
    // org.iobserve.analysis.userbehavior.test.WorkloadEvaluation}
    TestHelper.saveModel(usageModel, referenceUsageModelFileName);
    referenceElements.setEntryCallSequenceModel(entryCallSequenceModel);
    referenceElements.setUsageModel(usageModel);
    referenceElements.setMeanInterArrivalTime(meanInterArrivalTime + numberOfCalls * 2);
    referenceElements.setMeanConcurrentUserSessions(SimpleSequenceReference.calculateTheNumberOfConcurrentUsers(entryCallSequenceModel.getUserSessions()));
    return referenceElements;
}
Also used : EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) Start(org.palladiosimulator.pcm.usagemodel.Start) Stop(org.palladiosimulator.pcm.usagemodel.Stop) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) EntryCallSequenceModel(org.iobserve.analysis.data.EntryCallSequenceModel) AbstractUserAction(org.palladiosimulator.pcm.usagemodel.AbstractUserAction) UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) Correspondent(org.iobserve.model.correspondence.Correspondent) ReferenceElements(org.iobserve.analysis.userbehavior.ReferenceElements)

Example 8 with UsageScenario

use of org.palladiosimulator.pcm.usagemodel.UsageScenario in project iobserve-analysis by research-iobserve.

the class WorkloadEvaluation method calculateRME.

/**
 * Calculates the relative measurement error between a reference workload and the approach's
 * calculated workload. For an open workload the relative error of the mean inter arrival time
 * is calculated. For a closed workload the relative error of the mean number of concurrent
 * users is calculated. RME = (mw - rw) / rw, mw = measured workload, rw = reference workload
 *
 * @param usageModel
 *            contains the calculated workload
 * @param referenceElements
 *            contains the reference workload
 * @return return the relative measurement error
 */
public static double calculateRME(final UsageModel usageModel, final ReferenceElements referenceElements) {
    double rme = 0;
    final UsageScenario usageScenarioOfUsageModel = usageModel.getUsageScenario_UsageModel().get(0);
    final Workload workload = usageScenarioOfUsageModel.getWorkload_UsageScenario();
    // We distinguish between a closed and an open workload
    if (workload.getClass().equals(ClosedWorkloadImpl.class)) {
        final ClosedWorkload closedWorkloadOfUsageModel = (ClosedWorkload) workload;
        // The RME is calculated by the mean number of concurrent users that states the
        // population count of a closed workload
        final int usageModelWorkload = closedWorkloadOfUsageModel.getPopulation();
        final int referenceWorkload = referenceElements.getMeanConcurrentUserSessions();
        rme = (1.0 * usageModelWorkload - 1.0 * referenceWorkload) / (1.0 * referenceWorkload);
    } else if (workload.getClass().equals(OpenWorkloadImpl.class)) {
        final OpenWorkload openWorkloadOfUsageModel = (OpenWorkload) workload;
        final String interArrivalTime = openWorkloadOfUsageModel.getInterArrivalTime_OpenWorkload().getSpecification();
        // The RME is calculated by the mean inter arrival time that states an open workload
        final long usageModelWorkload = Long.parseLong(interArrivalTime);
        final long referenceWorkload = referenceElements.getMeanInterArrivalTime();
        rme = (1.0 * usageModelWorkload - 1.0 * referenceWorkload) / (1.0 * referenceWorkload);
    }
    rme = Math.abs(rme) * 100;
    return rme;
}
Also used : ClosedWorkload(org.palladiosimulator.pcm.usagemodel.ClosedWorkload) OpenWorkloadImpl(org.palladiosimulator.pcm.usagemodel.impl.OpenWorkloadImpl) UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) OpenWorkload(org.palladiosimulator.pcm.usagemodel.OpenWorkload) Workload(org.palladiosimulator.pcm.usagemodel.Workload) OpenWorkload(org.palladiosimulator.pcm.usagemodel.OpenWorkload) ClosedWorkload(org.palladiosimulator.pcm.usagemodel.ClosedWorkload)

Example 9 with UsageScenario

use of org.palladiosimulator.pcm.usagemodel.UsageScenario in project iobserve-analysis by research-iobserve.

the class LoopWithinBranchReference method getModel.

/**
 * It creates a reference usage model that contains loops within branches. Accordingly, user
 * sessions whose call sequences differ from each other at the positions of the branches and
 * that contain iterated call sequences are created.(RQ-1.6)
 *
 * @param referenceUsageModelFileName
 *            file name of the reference model to store its result
 * @param repositoryLookupModel
 *            repository lookup model
 * @param correspondenceModel
 *            correspondence model
 *
 * @return a reference model and corresponding user sessions
 * @throws IOException
 *             on error
 */
public static ReferenceElements getModel(final String referenceUsageModelFileName, final RepositoryLookupModelProvider repositoryLookupModel, final ICorrespondence correspondenceModel) throws IOException {
    // Create a random number of user sessions and random model element parameters. The user
    // sessions' behavior will be created according to the reference usage model and
    // subsequently the user sessions are used to create a usage model. The created usage model
    // is matched against the reference usage model. The minimum number of user sessions is set
    // dependently from the random number of branch transitions, because it must be ensured that
    // each branch transition is represented within the user sessions.
    final int numberOfBranchTransitions = TestHelper.getRandomInteger(3, 2);
    final int numberOfConcurrentUsers = TestHelper.getRandomInteger(30, 10 * numberOfBranchTransitions);
    final int lengthOfBranchSequence = TestHelper.getRandomInteger(2, 1);
    final int countOfLoop = TestHelper.getRandomInteger(3, 2);
    final EntryCallSequenceModel entryCallSequenceModel = new EntryCallSequenceModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
    final ReferenceElements referenceElements = new ReferenceElements();
    // In the following the reference usage model is created
    final UsageModel usageModel = UsageModelFactory.createUsageModel();
    final UsageScenario usageScenario = UsageModelFactory.createUsageScenario("", usageModel);
    final ScenarioBehaviour scenarioBehaviour = usageScenario.getScenarioBehaviour_UsageScenario();
    // lastAction = start;
    final Branch branch = LoopWithinBranchReference.createBranch(repositoryLookupModel, scenarioBehaviour, correspondenceModel, numberOfBranchTransitions, lengthOfBranchSequence, countOfLoop);
    // According to the reference usage model user sessions are created that exactly represent
    // the user behavior of the reference usage model. The entry and exit times enable that the
    // calls within the user sessions are ordered according to the reference usage model. The
    // branch transition counter ensures that each branch transition is represnted within the
    // user sessions
    final List<Integer> branchTransitionCounter = new ArrayList<>();
    boolean areAllBranchesVisited = true;
    do {
        for (int i = 0; i < branch.getBranchTransitions_Branch().size(); i++) {
            branchTransitionCounter.add(i, 0);
        }
        int entryTime = 1;
        for (int i = 0; i < entryCallSequenceModel.getUserSessions().size(); i++) {
            entryTime = 1;
            // Each user session represents one of the branch transitions
            final int branchDecisioner = TestHelper.getRandomInteger(numberOfBranchTransitions - 1, 0);
            if (branchDecisioner == 0) {
                entryTime = LoopWithinBranchReference.createLoop(branchTransitionCounter, entryTime, 0, 1, entryCallSequenceModel, lengthOfBranchSequence, countOfLoop, i);
            } else if (branchDecisioner == 1) {
                entryTime = LoopWithinBranchReference.createLoop(branchTransitionCounter, entryTime, 1, 2, entryCallSequenceModel, lengthOfBranchSequence, countOfLoop, i);
            } else if (branchDecisioner == 2) {
                entryTime = LoopWithinBranchReference.createLoop(branchTransitionCounter, entryTime, 2, 0, entryCallSequenceModel, lengthOfBranchSequence, countOfLoop, i);
            }
        }
        // It is checked whether all branch transitions are represented within the user sessions
        for (int i = 0; i < branchTransitionCounter.size(); i++) {
            if (branchTransitionCounter.get(i) == 0) {
                areAllBranchesVisited = false;
                break;
            }
        }
    } while (!areAllBranchesVisited);
    // Sets the likelihoods of the branch transitions according to the created user sessions
    for (int i = 0; i < branch.getBranchTransitions_Branch().size(); i++) {
        branch.getBranchTransitions_Branch().get(i).setBranchProbability((double) branchTransitionCounter.get(i) / (double) numberOfConcurrentUsers);
    }
    // Saves the reference usage model and sets the usage model and the EntryCallSequenceModel
    // as the reference elements. Our approach is now executed with the EntryCallSequenceModel
    // and the resulting usage model can be matched against the reference usage model
    TestHelper.saveModel(usageModel, referenceUsageModelFileName);
    referenceElements.setEntryCallSequenceModel(entryCallSequenceModel);
    referenceElements.setUsageModel(usageModel);
    return referenceElements;
}
Also used : UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) Branch(org.palladiosimulator.pcm.usagemodel.Branch) ArrayList(java.util.ArrayList) EntryCallSequenceModel(org.iobserve.analysis.data.EntryCallSequenceModel) ReferenceElements(org.iobserve.analysis.userbehavior.ReferenceElements)

Example 10 with UsageScenario

use of org.palladiosimulator.pcm.usagemodel.UsageScenario in project iobserve-analysis by research-iobserve.

the class PcmUsageModelBuilder method createUsageModel.

/**
 * Creates a PCM usage model from the passed LoopBranchModels.
 *
 * @return the created PCM usage model
 */
public UsageModel createUsageModel() {
    final UsageModel usageModel = UsageModelFactory.createUsageModel();
    // Creates for each detected user group its own usage scenario
    for (int i = 0; i < this.loopBranchModels.size(); i++) {
        final BranchModel callBranchModel = this.loopBranchModels.get(i);
        final UsageScenario usageScenario = UsageModelFactory.createUsageScenario("Usage Scneario of user group " + i, usageModel);
        final Map<Integer, ScenarioBehaviour> branchScenarioBehaviours = new HashMap<>();
        this.branchScenarioBehavioursOfUserGroups.add(branchScenarioBehaviours);
        if (this.isClosedWorkloadRequested) {
            UsageModelFactory.createClosedWorkload(callBranchModel.getWorkloadIntensity().getAvgNumberOfConcurrentUsers(), this.thinkTime, usageScenario);
        } else {
            UsageModelFactory.createOpenWorkload(callBranchModel.getWorkloadIntensity().getInterarrivalTimeOfUserSessions(), usageScenario);
        }
        // creates for each Branch its own scenario behavior
        this.createForEachBranchAScenarioBehavior(callBranchModel.getRootBranch(), i);
        // The rootBranch contains every succeeding branches and is set as the scenario behavior
        // of the user groupĀ“s usage scenario
        usageScenario.setScenarioBehaviour_UsageScenario(this.branchScenarioBehavioursOfUserGroups.get(i).get(callBranchModel.getRootBranch().getBranchId()));
        usageModel.getUsageScenario_UsageModel().add(usageScenario);
    }
    return usageModel;
}
Also used : UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) HashMap(java.util.HashMap) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) BranchModel(org.iobserve.analysis.userbehavior.data.BranchModel)

Aggregations

UsageScenario (org.palladiosimulator.pcm.usagemodel.UsageScenario)20 UsageModel (org.palladiosimulator.pcm.usagemodel.UsageModel)17 ScenarioBehaviour (org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)12 Test (org.junit.Test)8 EntryCallSequenceModel (org.iobserve.analysis.data.EntryCallSequenceModel)7 AbstractUserAction (org.palladiosimulator.pcm.usagemodel.AbstractUserAction)7 EntryLevelSystemCall (org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall)7 Start (org.palladiosimulator.pcm.usagemodel.Start)7 Stop (org.palladiosimulator.pcm.usagemodel.Stop)7 ReferenceElements (org.iobserve.analysis.userbehavior.ReferenceElements)6 Correspondent (org.iobserve.model.correspondence.Correspondent)6 PCMRandomVariable (org.palladiosimulator.pcm.core.PCMRandomVariable)5 Loop (org.palladiosimulator.pcm.usagemodel.Loop)5 EntryCallEvent (org.iobserve.stages.general.data.EntryCallEvent)4 ArrayList (java.util.ArrayList)3 BranchTransition (org.palladiosimulator.pcm.usagemodel.BranchTransition)3 HashMap (java.util.HashMap)2 Branch (org.palladiosimulator.pcm.usagemodel.Branch)2 List (java.util.List)1 EObject (org.eclipse.emf.ecore.EObject)1