在使用 YCSB 测试 Apache Ignite 时尝试使用 JFR 跟踪缓存行为

问题描述 投票:0回答:1

我正在使用 YCSB 测试 Apache Ignite 版本 2.16.0 来发送 100K 整数输入。我想使用 JFR 来跟踪缓存操作何时发生。我在

ignite/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxyImpl.java

添加了以下 JFR 事件
@Name("org.apache.ignite.CacheGet")
@Label("Cache Get Operation")
class CacheGetEvent extends Event {
    @Label("Key")
    String key;

    @Label("Operation Success")
    boolean success;
}

@Name("org.apache.ignite.CachePut")
@Label("Cache Put Operation")
class CachePutEvent extends Event {
    @Label("Key")
    String key;

    @Label("Operation Success")
    boolean success;
}

@Name("org.apache.ignite.CacheRemove")
@Label("Cache Remove Operation")
class CacheRemoveEvent extends Event {
    @Label("Key")
    String key;

    @Label("Operation Success")
    boolean success;
}

我还在同一文件中的

get()
put()
remove()
函数中使用它们:

    @Override public V get(K key) {
        CacheGetEvent event = new CacheGetEvent();
        event.key = key.toString(); // Assuming key.toString() provides a meaningful representation
        event.begin();

        IgniteInternalCache<K, V> delegate = getDelegateSafe();
    
        try {
            V result;
            if (isAsync()) {
                setFuture(delegate.getAsync(key));
                result = null;
            }
            else {
                result = delegate.get(key);
            }
            event.success = true; // Operation succeeded
            return result;
        }
        catch (IgniteCheckedException | IgniteException e) {
            event.success = false; // Operation failed
            throw cacheException(e);
        }
        finally {
            event.commit(); // Commit the JFR event regardless of the outcome
        }
    }

    @Override public void put(K key, V val) {
        CachePutEvent event = new CachePutEvent();
        event.key = key.toString(); // Capture the key involved in the operation
        event.begin();

        IgniteInternalCache<K, V> delegate = getDelegateSafe();
    
        try {
            if (isAsync())
                setFuture(putAsync0(key, val));
            else
                delegate.put(key, val);
            
            event.success = true; // Mark the operation as successful
        }
        catch (IgniteCheckedException | IgniteException e) {
            event.success = false; // Mark the operation as failed
            throw cacheException(e);
        }
        finally {
            event.commit(); // Commit the JFR event regardless of the outcome
        }
    }

    @Override public boolean remove(K key) {
        CacheRemoveEvent event = new CacheRemoveEvent();
        event.key = key.toString(); // Capture the key involved in the operation
        event.begin();

        IgniteInternalCache<K, V> delegate = getDelegateSafe();
        boolean result;
    
        try {
            if (isAsync()) {
                setFuture(delegate.removeAsync(key));
                result = false; // Async operation, actual result unknown here
            }
            else {
                result = delegate.remove(key); // Synchronous operation, result known
            }
            event.success = true; // Assuming success if no exception
        }
        catch (IgniteCheckedException | IgniteException e) {
            event.success = false; // Mark the operation as failed
            throw cacheException(e);
        }
        finally {
            event.commit(); // Commit the JFR event regardless of the outcome
        }
    
        return result;
    }

我使用

mvn
构建 Ignite,然后使用以下脚本运行它:

source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk use java 17.0.10-librca

IGNITE=/home/sameer/thesis/ignite
#/home/sameer/thesis/ignite

# Define the directory for storing JFR recordings
JFR_DIR=data/jfr
mkdir -p "$JFR_DIR" # Ensure the JFR directory exists

# Define the filename for the JFR recording
JFR_FILE="$JFR_DIR/ignite_recording.jfr"

# Ensure directories for Ignite data exist
mkdir -p /data/dbignite
mkdir -p /data/walignite
mkdir -p /data/walarchignite

# Include JFR options in the JVM options
export JVM_OPTS="$JVM_OPTS -XX:+FlightRecorder -XX:StartFlightRecording=filename=$JFR_FILE,dumponexit=true"

# Start Ignite with the specified XML configuration
"$IGNITE"/bin/ignite.sh ignite01.xml

但是,每当我使用

jfr print --json --events "*" data/jfr/ignite_recording.jfr > data/jfr/ignite_recording.json
将生成的 .jfr 记录转换为 json 时,都不存在任何自定义缓存事件。我是否需要将自定义 JFR 事件添加到 Ignite 源代码中的不同文件中?

java ignite jfr ycsb
1个回答
0
投票

这只是一个理论,我没有尝试过,但我怀疑相关事件甚至没有被解雇。在这种情况下,应该在

IgniteConfiguration
bean 中显式启用缓存事件。 doc 说明了如何实现这一目标。

© www.soinside.com 2019 - 2024. All rights reserved.