5

我有一个性能用例,我需要在其中识别某些process()调用,EntryProcessor这需要超过 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>

我给出了一个在内部休眠 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;
    }

}   

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

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

这是一个错误SlowOperationDetector还是我在这里遗漏了什么?

4

1 回答 1

2

这不是错误;但设计。我们所做的是定期扫描当前正在执行的操作。所以这取决于扫描的频率。慢操作检测器不打算用于(因此不是设计)来检测这种短操作。它实际上是为多秒操作执行而设计的。

于 2015-12-06T16:00:24.193 回答