Skip to content

Commit

Permalink
Optimizing prism clone (fixes TestPlentyOfAssignments)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 8, 2019
1 parent da44cff commit d34c81b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
Expand Up @@ -724,7 +724,9 @@ protected void copyValues(CloneStrategy strategy, PrismContainerImpl<C> clone) {
clone.compileTimeClass = this.compileTimeClass;
for (PrismContainerValue<C> pval : getValues()) {
try {
clone.add(pval.cloneComplex(strategy));
// No need to check for uniqueness here. If the value is unique in this object, it will also be unique in clone.
// Not comparing values makes clones faster.
clone.add(pval.cloneComplex(strategy), false, null);
} catch (SchemaException e) {
// This should not happen
throw new SystemException("Internal Error: "+e.getMessage(),e);
Expand Down
Expand Up @@ -57,9 +57,9 @@ public enum InternalCounters {

REPOSITORY_READ_COUNT("repositoryReadCount", "repository read count", null),

PRISM_OBJECT_COMPARE_COUNT("prismObjectCompareCount", "prism object compare count", null),
PRISM_OBJECT_COMPARE_COUNT("prismObjectCompareCount", "prism object compare count", InternalOperationClasses.PRISM_OPERATIONS),

PRISM_OBJECT_CLONE_COUNT("prismObjectCloneCount", "prism object clone count", null),
PRISM_OBJECT_CLONE_COUNT("prismObjectCloneCount", "prism object clone count", InternalOperationClasses.PRISM_OPERATIONS),

ROLE_EVALUATION_COUNT("roleEvaluationCount", "role evaluation count", InternalOperationClasses.ROLE_EVALUATIONS),

Expand Down
Expand Up @@ -45,7 +45,8 @@ public class InternalMonitor implements PrismMonitor, DebugDumpable {
private static final String CLONE_START_TIMESTAMP_KEY = InternalMonitor.class.getName()+".cloneStartTimestamp";

private static Map<InternalCounters,Long> counterMap = new HashMap<>();
private static Map<InternalOperationClasses,Boolean> traceMap = new HashMap<>();
private static Map<InternalOperationClasses,Boolean> traceClassMap = new HashMap<>();
private static Map<InternalCounters,Boolean> traceCounterMap = new HashMap<>();

private static CachingStatistics resourceCacheStats = new CachingStatistics();
private static CachingStatistics connectorCacheStats = new CachingStatistics();
Expand All @@ -65,9 +66,8 @@ public static long getCount(InternalCounters counter) {

public static void recordCount(InternalCounters counter) {
long count = recordCountInternal(counter);
InternalOperationClasses operationClass = counter.getOperationClass();
if (operationClass != null && isTrace(operationClass)) {
traceOperation(counter, operationClass, count);
if (isTrace(counter)) {
traceOperation(counter, counter.getOperationClass(), count);
}
}

Expand All @@ -82,7 +82,7 @@ private static synchronized long recordCountInternal(InternalCounters counter) {
}

public static boolean isTrace(InternalOperationClasses operationClass) {
Boolean b = traceMap.get(operationClass);
Boolean b = traceClassMap.get(operationClass);
if (b == null) {
return false;
} else {
Expand All @@ -91,6 +91,10 @@ public static boolean isTrace(InternalOperationClasses operationClass) {
}

private static boolean isTrace(InternalCounters counter) {
Boolean counterTrace = traceCounterMap.get(counter);
if (counterTrace != null) {
return counterTrace;
}
InternalOperationClasses operationClass = counter.getOperationClass();
if (operationClass == null) {
return false;
Expand All @@ -99,7 +103,11 @@ private static boolean isTrace(InternalCounters counter) {
}

public static void setTrace(InternalOperationClasses operationClass, boolean val) {
traceMap.put(operationClass, val);
traceClassMap.put(operationClass, val);
}

public static void setTrace(InternalCounters counter, boolean val) {
traceCounterMap.put(counter, val);
}

private static void traceOperation(InternalCounters counter, InternalOperationClasses operationClass, long count) {
Expand Down Expand Up @@ -171,7 +179,7 @@ public static <O extends ObjectType> void recordRepositoryRead(Class<O> type, St
}

public synchronized <O extends Objectable> void recordPrismObjectCompareCount(PrismObject<O> thisObject, Object thatObject) {
recordCountInternal(InternalCounters.PRISM_OBJECT_COMPARE_COUNT);
recordCount(InternalCounters.PRISM_OBJECT_COMPARE_COUNT);
}

public static boolean isCloneTimingEnabled() {
Expand Down Expand Up @@ -247,7 +255,7 @@ public static void setInspector(InternalInspector inspector) {
public static void reset() {
LOGGER.info("MONITOR reset");
counterMap.clear();
traceMap.clear();
traceClassMap.clear();
resourceCacheStats = new CachingStatistics();
connectorCacheStats = new CachingStatistics();
inspector = null;
Expand Down
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2017 Evolveum
* Copyright (c) 2017-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,7 +30,9 @@ public enum InternalOperationClasses {

PRISM_OBJECT_CLONES("prismObjectClone", "prism object clones"),

ROLE_EVALUATIONS("roleEvaluations", "role evaluations");
ROLE_EVALUATIONS("roleEvaluations", "role evaluations"),

PRISM_OPERATIONS("prismOperations", "prism operations");

// Used as localization key
private String key;
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017 Evolveum
* Copyright (c) 2017-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,6 +43,7 @@
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.internals.InternalCounters;
import com.evolveum.midpoint.schema.internals.InternalMonitor;
import com.evolveum.midpoint.schema.internals.InternalOperationClasses;
import com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition;
import com.evolveum.midpoint.schema.processor.ResourceAttribute;
import com.evolveum.midpoint.schema.processor.ResourceAttributeContainer;
Expand Down Expand Up @@ -149,15 +150,11 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
.beginOutbound()
.beginExpression()
.expressionEvaluator(evaluator);
// try {
// IntegrationTestTools.displayXml("RRRRRRRRR", role.asPrismObject());
// } catch (SchemaException e) {
// throw new SystemException(e);
// }
}, initResult);

inspector = new CountingInspector();
InternalMonitor.setInspector(inspector);
// InternalMonitor.setTrace(InternalCounters.PRISM_OBJECT_COMPARE_COUNT, true);
}

private String generateRoleOid(String format, int num) {
Expand Down Expand Up @@ -584,6 +581,7 @@ public void test220AddAlice() throws Exception {
display("User before", assignmentSummary(userBefore));

inspector.reset();
rememberCounter(InternalCounters.PRISM_OBJECT_CLONE_COUNT);
rememberCounter(InternalCounters.PRISM_OBJECT_COMPARE_COUNT);
rememberCounter(InternalCounters.REPOSITORY_READ_COUNT);
long startMillis = System.currentTimeMillis();
Expand All @@ -599,13 +597,14 @@ public void test220AddAlice() throws Exception {
assertSuccess(result);

display("Added alice in "+(endMillis - startMillis)+"ms ("+((endMillis - startMillis)/NUMBER_OF_GENERATED_DUMMY_GROUPS)+"ms per assignment)");

PrismObject<UserType> userAfter = getUser(USER_ALICE_OID);
display("User after", assignmentSummary(userAfter));
assertAliceRoleMembershipRef(userAfter);

display("Repo reads", InternalMonitor.getCount(InternalCounters.REPOSITORY_READ_COUNT));
display("Object compares", InternalMonitor.getCount(InternalCounters.PRISM_OBJECT_COMPARE_COUNT));
display("Prism clones", InternalMonitor.getCount(InternalCounters.PRISM_OBJECT_CLONE_COUNT));

display("Inspector", inspector);

Expand Down

0 comments on commit d34c81b

Please sign in to comment.