Din*_*esh 5 java distributed-cache distributed-caching hazelcast hazelcast-imap
我有一个性能用例,通过该用例,我需要确定花费300毫秒以上的某些process()
调用EntryProcessor
。我尝试使用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>
Run Code Online (Sandbox Code Playgroud)
我给出了一个示例测试代码,该代码在内部睡眠1秒钟process()
。
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;
}
}
Run Code Online (Sandbox Code Playgroud)
当配置的阈值小于1000ms时,我看不到任何日志。因此,在此示例中,我看不到任何缓慢的操作堆栈跟踪或日志。
如果将睡眠时间更改为2秒,并且将慢速操作阈值更改为1秒,则慢速操作检测器将启动并显示日志。
这是错误SlowOperationDetector
吗,还是我在这里错过了什么?
这不是一个错误;而是一个错误。但设计。我们所做的就是定期扫描当前正在执行的操作。所以这取决于扫描的频率。慢速操作检测器无意用于(因此未设计)来检测此类短操作。它实际上是为了执行多秒操作而设计的。