Usually Hybris server has a slow performance in terms of RPS due to wrong usage of coverters and populators in controllers/facades. Main wrong usecases are:
- convert same Model into Data object few times
- populate Data object with all possible data instead of population only valuable for current page attributes
To identify which populators are slow and executed more than once you can use such aspect:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package com.blog.core.performance;
import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import java.util.concurrent.TimeUnit;
public class ExecutionTimeMeasurementAspect {
private static final Logger LOG = Logger.getLogger(ExecutionTimeMeasurementAspect.class);
public Object measure(final ProceedingJoinPoint pjp) throws Throwable // NOSONAR
{
final String methodName = pjp.getTarget().getClass().getSimpleName() + "." + pjp.getSignature().getName();
final long startTime = System.nanoTime();
final Object result = pjp.proceed();
durationLog(startTime, methodName);
return result;
}
private static void durationLog(long startTime, String message) {
long endTime = System.nanoTime();
long duration = TimeUnit.MILLISECONDS.convert(endTime - startTime, TimeUnit.NANOSECONDS);
if (duration > 20) {
LOG.warn(message + " in " + duration + " milliseconds.");
}
}
}
|
With pointcut definition:
1
2
3
4
5
6
7
8
9
10
11
|
<bean id="executionTimeMeasurementAspect"
class="com.blog.core.performance.ExecutionTimeMeasurementAspect"/>
<aop:config>
<aop:pointcut id="executionTaskPointcut"
expression="execution(public * de.hybris.platform.converters.Populator+.populate(..))"/>
<aop:aspect ref="executionTimeMeasurementAspect">
<aop:around pointcut-ref="executionTaskPointcut" method="measure"/>
</aop:aspect>
</aop:config>
|