编程语言
首页 > 编程语言> > java – Hazelcast SlowOperationDetector,用于识别执行时间少于1秒的操作

java – Hazelcast SlowOperationDetector,用于识别执行时间少于1秒的操作

作者:互联网

我有一个性能用例,我需要在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>

我给出了一个示例测试代码,它在进程()内部休眠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中的错误还是我在这里遗漏了什么?

解决方法:

这不是一个bug;但设计.我们所做的是定期扫描当前正在执行的操作.所以这取决于扫描的频率.不打算使用慢速操作检测器(并且因此未设计)来检测这种短操作.它实际上是用于多秒操作执行.

标签:java,hazelcast,distributed-caching,distributed-cache,hazelcast-imap
来源: https://codeday.me/bug/20190702/1356800.html