我有一个性能用例,根据该用例,我需要识别EntryProcessor
中的某些process()
调用,这需要300毫秒以上的时间。我尝试使用以下配置的SlowOperationDetector
。
<!-- SlowOperation Detector Configuration -->
<property name="hazelcast.slow.operation.detector.enabled">true</property>
<property name="hazelcast.slow.operation.detector.stacktrace.logging.enabled">true</property>
<property name="hazelcast.slow.operation.detector.log.purge.interval.seconds">60000</property>
<property name="hazelcast.slow.operation.detector.log.retention.seconds">60000</property>
<property name="hazelcast.slow.operation.detector.threshold.millis">300</property>
我给出了一个示例测试代码,它在process()
中休眠1秒。
public static void main(String args[])
{
Config cfg = null;
try {
cfg = new FileSystemXmlConfig("C:\workarea\hazelcast\hazelcast-perf.xml");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(cfg);
IMap<String, Employee> employeesMap = hazelcastInstance.getMap("anyMap");
employeesMap.put("100", new Employee(100));
SlowEntryProcessor slowEntryProcessor = new SlowEntryProcessor();
employeesMap.executeOnKey("100", slowEntryProcessor);
}
static public class SlowEntryProcessor implements EntryProcessor<String, Employee>
{
private static final long serialVersionUID = 1L;
@Override
public EntryBackupProcessor<String, Employee> getBackupProcessor()
{
return null;
}
@Override
public Object process(Entry<String, Employee> arg0)
{
System.out.println("About to sleep");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("done processing");
return null;
}
}
当配置的阈值小于1000ms时,我看不到任何日志。因此,在本例中,我没有看到任何慢速操作堆栈跟踪或日志。
如果我将睡眠时间更改为2秒,将慢速操作阈值更改为1秒,则慢速操作检测器将启动并显示日志。
这是SlowOperationDetector
中的一个错误,还是我在这里遗漏了什么?
这不是一个bug;而是设计。我们所做的是定期扫描当前正在执行的操作。所以这取决于扫描的频率。慢速操作检测器不打算用于(因此没有设计)检测这种短操作。它实际上是为多秒的操作执行而设计的。