Hazelcast SlowOperationDetector 识别执行时间少于 1 秒的操作

Hazelcast SlowOperationDetector to identify operations with less than 1 sec execution time

我有一个性能用例,我需要通过该用例识别 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;
    }

}   

当配置的阈值小于 1000 毫秒时,我看不到任何日志。所以在这个例子中,我没有看到任何缓慢的操作堆栈跟踪或日志。

如果我将睡眠时间更改为 2 秒,并将慢速操作阈值更改为 1 秒,慢速操作检测器将启动并显示日志。

这是 SlowOperationDetector 中的错误还是我遗漏了什么?

这不是错误;但设计。我们所做的是定期扫描当前正在执行的操作。所以这取决于扫描的频率。慢速操作检测器并非旨在用于(因此未设计)检测此类短操作。它真正用于多秒操作执行。