为消息处理器配置垃圾回收器

在 Edge for Private Cloud 4.54.00(在 Java 21 上运行)中,消息 处理器默认使用 Garbage-First 垃圾回收器 (G1GC)。本文档介绍了如何在消息处理器上配置和验证垃圾回收设置。

自定义消息处理器上的垃圾回收器

本部分简要介绍了在 Edge 消息处理器上配置替代垃圾回收 (GC) 设置的过程。您可以通过更新消息处理器上的 GC 属性来管理 GC 参数。如需调整 任何配置属性,请使用 如何配置 Edge中定义的令牌语法。

如需修改消息处理器上的 GC 设置,请执行以下步骤:

  1. 检查 GC 属性
  2. 修改消息处理器上的 GC

检查 GC 属性

以下步骤介绍了如何检查配置的 GC 属性:

  1. 使用以下命令在消息处理器源目录 /opt/apigee/edge-message-processor/source 中搜索 GC 属性: 命令:
    grep -riE "useG1GC|useZGC|useStringDeduplication" /opt/apigee/edge-message-processor/source
    
  2. 确认此命令的输出显示了消息处理器的 GC 属性配置:
    /opt/apigee/edge-message-processor/source/conf/system.properties:useG1GC={T}conf_system_useG1GC{/T}
    /opt/apigee/edge-message-processor/source/conf/system.properties:useZGC={T}conf_system_useZGC{/T}
    /opt/apigee/edge-message-processor/source/conf/system.properties:useStringDeduplication={T}conf_system_useStringDeduplication{/T}

    {T}{/T} 标记之间的字符串是您可以在消息处理器的 .properties 文件中设置的属性的名称。

修改消息处理器上的 GC

以下步骤介绍了如何修改 Apigee 消息处理器上的 GC 设置:

  1. 在编辑器中打开消息处理器机器上的 /opt/apigee/customer/application/message-processor.properties 文件。如果该文件尚不存在,请创建该文件。例如:
    vi /opt/apigee/customer/application/message-processor.properties
    
  2. 根据目标配置文件添加所需的 GC 配置行:
    • 选项 A:将 G1GC 用作默认垃圾回收器,并进行一些 修改:
      conf_system_useG1GC=true
      conf_system_useStringDeduplication=true
      conf_system_g1gc.g1ReservePercent=15
    • 选项 B:启用 Generational ZGC(对于超低延迟 部署,此选项是可选的):
      conf_system_useG1GC=false
      conf_system_useZGC=true
      bin_setenv_max_meta_space_size=1024m
    • 选项 C:启用通用 GC 设置:

      在组件的 .properties 替换文件 (/opt/apigee/customer/application/message-processor.properties) 中设置 bin_setenv_ext_jvm_opts,以配置任何通用 GC 属性,然后重启该 组件。例如:

      conf_system_useG1GC=false
      conf_system_useZGC=false
      bin_setenv_ext_jvm_opts="-XX:+UseParallelGC"
  3. 保存更改。
  4. 确保此属性文件的所有者是 apigee 用户。 例如:
    chown apigee:apigee /opt/apigee/customer/application/message-processor.properties
    
  5. 使用以下命令重启消息处理器:
    /opt/apigee/apigee-service/bin/apigee-service edge-message-processor restart
    
  6. 如果您有多个消息处理器,请在所有 消息处理器上重复执行这些步骤。

更新字符串去重

默认情况下,G1GC 配置会将 UseStringDeduplication 设置为 true,这允许相同的 String 值共享单个字符数组,从而优化 Java 堆内存分配。如需停用字符串去重,请在 /opt/apigee/customer/application/message-processor.properties 中设置 conf_system_useStringDeduplication=false,然后重启消息处理器,如 修改消息处理器上的 GC 中所述。

验证消息处理器上的 GC 配置

如需验证 GC 配置更改是否已应用于消息 处理器 ,请执行以下操作:

  1. 在 /opt/apigee/edge-message-processor/conf 目录中搜索 GC 属性,并检查 该属性是否已设置为新值。例如:
    grep -riE "useG1GC|useZGC|g1gc\.|useStringDeduplication" /opt/apigee/edge-message-processor/conf
    
  2. 验证 /opt/apigee/edge-message-processor/conf/system.properties 是否反映了您新配置的值。例如, Apigee 默认 GC 设置如下所示:
    /opt/apigee/edge-message-processor/conf/system.properties:useG1GC=true
    /opt/apigee/edge-message-processor/conf/system.properties:useZGC=false
    /opt/apigee/edge-message-processor/conf/system.properties:g1gc.maxGCPauseMillis=200
    /opt/apigee/edge-message-processor/conf/system.properties:g1gc.initiatingHeapOccupancyPercent=45
    /opt/apigee/edge-message-processor/conf/system.properties:g1gc.g1ReservePercent=15
    /opt/apigee/edge-message-processor/conf/system.properties:useStringDeduplication=true
  3. 验证运行的消息处理器 JVM 进程是否已使用预期的 -XX: 标志启动:
    ps -ef | grep edge-message-processor | grep -E "UseG1GC|UseZGC"
    
    • 对于 Apigee 默认 G1GC,请确认命令行 包含: -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:InitiatingHeapOccupancyPercent=45 -XX:G1ReservePercent=15 -XX:+UseStringDeduplication -XX:MaxMetaspaceSize=1024m
    • 对于 Generational ZGC,请确认命令行包含: -XX:+UseZGC -XX:+ZGenerational -XX:MaxMetaspaceSize=1024m
  4. 如果您仍然无法配置 GC 设置,请与 Apigee Edge 支持团队联系。

接下来怎么做?