在 Edge for Private Cloud 4.54.00 (在 Java 21 上執行) 中,Message Processor 預設會使用 Garbage-First Garbage Collector (G1GC)。本文說明如何設定及驗證訊息處理器的垃圾收集設定。
自訂訊息處理器的垃圾收集器
本節概述在 Edge 訊息處理器上設定替代垃圾收集 (GC) 設定的程序。如要管理 GC 參數,請更新訊息處理器的 GC 屬性。如要調整任何設定屬性,請使用「如何設定 Edge」中定義的權杖語法。
如要在訊息處理器上修改 GC 設定,請按照下列步驟操作:
檢查 GC 屬性
下列步驟說明如何查看已設定的 GC 屬性:
-
在 Message Processor 來源目錄中搜尋 GC 屬性
/opt/apigee/edge-message-processor/source,方法是使用下列指令:grep -riE "useG1GC|useZGC|useStringDeduplication" /opt/apigee/edge-message-processor/source
-
確認這個指令的輸出內容顯示訊息處理器的 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}標記之間的字串是您可以在 Message Processor 的.properties檔案中設定的屬性名稱。
修改訊息處理器的 GC
下列步驟說明如何修改 Apigee Message Processor 的 GC 設定:
-
在編輯器中開啟 訊息處理器 電腦上的
/opt/apigee/customer/application/message-processor.properties檔案。如果檔案不存在,請建立檔案。例如:vi /opt/apigee/customer/application/message-processor.properties
-
根據目標設定檔新增所需的 GC 設定行:
-
選項 A:將 G1GC 設為預設垃圾收集器,並進行部分修改:
conf_system_useG1GC=true conf_system_useStringDeduplication=true conf_system_g1gc.g1ReservePercent=15
-
方法 B:啟用 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"
-
選項 A:將 G1GC 設為預設垃圾收集器,並進行部分修改:
- 儲存變更。
-
請確認這個屬性檔案的擁有者是
apigee使用者。 例如:chown apigee:apigee /opt/apigee/customer/application/message-processor.properties
-
使用下列指令重新啟動訊息處理器:
/opt/apigee/apigee-service/bin/apigee-service edge-message-processor restart
- 如果您有多個訊息處理器,請在所有訊息處理器上重複執行這些步驟。
更新字串簡化
根據預設,G1GC 設定會將 UseStringDeduplication 設為 true,允許相同 String 值共用單一字元陣列,藉此最佳化 Java 堆積記憶體配置。如要停用字串簡化功能,請在 /opt/apigee/customer/application/message-processor.properties 中設定 conf_system_useStringDeduplication=false,然後重新啟動訊息處理器,如「修改訊息處理器上的垃圾收集」所述。
在訊息處理器上驗證 GC 設定
如要確認 GC 設定變更已套用至訊息處理器,請按照下列步驟操作:
-
在
/opt/apigee/edge-message-processor/conf目錄中搜尋 GC 屬性,並確認已設為新值。例如:grep -riE "useG1GC|useZGC|g1gc\.|useStringDeduplication" /opt/apigee/edge-message-processor/conf
-
確認
/opt/apigee/edge-message-processor/conf/system.properties反映新設定的值。舉例來說,「Apigee Default 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
-
確認執行中的 訊息處理器 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 -
如果是分代 ZGC,請確認指令列包含:
-XX:+UseZGC -XX:+ZGenerational -XX:MaxMetaspaceSize=1024m
-
如果是 Apigee 預設 G1GC,請確認指令列包含:
- 如果還是無法設定 GC 設定,請聯絡 Apigee Edge 支援團隊。