jvm_memory_bytes_used和jvm_gc_collection_seconds_sum

kafka_server_BrokerState_value针对 Kafka 的 JVM 配置了 32G 内存,出现高频 GC (jvm_gc_collection_seconds_sum 高) 和内存使用率接近上限(jvm_memory_bytes_used 达到 32G)的情况,可以从以下几个方面来排查问题:


1. 确认 JVM 参数配置是否合理

  • 堆内存分配:
    • 确保 -Xmx-Xms 的值一致,避免频繁调整堆大小。
    • 32G 内存虽然可用,但超过 32G 堆时可能导致垃圾回收效率下降(因为超过 32G 会触发 Compressed Oops 的禁用)。如果可以,建议调整为稍低于 32G,例如 31G。
  • 垃圾回收器选择:
    • 查看是否使用了合适的垃圾回收器:
      • G1GC:适合较大的堆,并能减少长时间的 GC 暂停。
      • CMS:在低延迟场景中也常见,但在高堆内存中可能表现不佳。
    • 确认 JVM 启动时是否指定了 -XX:+UseG1GC 或其他垃圾回收器参数。

2. 监控和分析 GC 日志

  • 启用 GC 日志
    -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -Xloggc:/path/to/gc.log
    
  • 分析 GC 日志
    • 查看是否存在频繁的 Minor GC 或 Full GC。
    • 如果 Full GC 很频繁,可能是:
      • 老年代内存不足。
      • 内存泄漏。
      • 大量对象未及时被回收。
  • 工具推荐
    使用如 GCEasy 或其他 GC 分析工具自动分析日志。

3. 分析 Kafka 的内存使用情况

  • 检查 Kafka Topic 配置:
    • 每个 Partition 会占用一定内存,确保 num.partitions 配置合理。
    • Topic 的 retention.bytesretention.ms 是否设置过高,导致较多数据在内存中占用。
  • Producer/Consumer 的速率:
    • 生产者是否发送过多的消息导致缓存积压。
    • 消费者消费速度是否过慢,导致数据堆积在内存中。
  • 缓冲区设置:
    • 检查 Kafka 的内存缓冲区配置,例如 message.max.byteslog.segment.bytes,确保其大小与使用场景匹配。
  • Page Cache:
    Kafka 可能会使用堆外内存进行 Page Cache 管理,确认是否分配了足够的系统内存。

4. 内存泄漏排查

  • 工具检测:
    • 使用工具如 VisualVM、JProfiler 或 MAT (Memory Analyzer Tool) 查看堆内存中的对象分布。
    • 检查是否存在异常的大对象(如 Map、List 等)占用大量内存。
  • Kafka 自定义代码:
    • 如果你有自定义的 Kafka Producer/Consumer 逻辑,检查是否有内存泄漏。
    • 避免消息缓冲区或回调队列无限增长。

5. 硬件和操作系统资源检查

  • 操作系统内存分配:
    • 确保操作系统分配给 Kafka 的内存充足。
    • 检查是否存在其他应用与 Kafka 争夺内存资源。
  • 磁盘 IO 和 Page Cache:
    • 磁盘性能瓶颈可能导致 Kafka 缓存数据过久。
    • 查看系统的 Page Cache 使用情况 (free -hvmstat)。

6. 调整 Kafka 配置

  • 重要参数:
    • num.network.threadsnum.io.threads:设置合适的线程数,避免线程阻塞导致内存积压。
    • queued.max.requests:调整请求队列大小,避免过多的内存占用。
    • log.cleaner.threads:清理日志的线程数是否足够。
  • 数据分区优化:
    • 如果消息积压严重,考虑增加分区,分散内存压力。

7. 总结和优化方案

  • 短期方案:
    • 减少 Kafka 堆内存到 31G。
    • 调整垃圾回收器,推荐 G1GC。
  • 长期方案:
    • 监控并优化消息的生产和消费速率。
    • 检查并优化 Kafka Topic 配置。
    • 定期分析 GC 日志,持续优化配置。

根据排查结果,逐步优化系统配置。若有更多细节(如 GC 日志或 Kafka 参数配置),可以进一步诊断问题根源。

--- lowercaseOutputLabelNames: true lowercaseOutputName: true whitelistObjectNames: ["java.lang:type=OperatingSystem"] blacklistObjectNames: [] rules: - pattern: 'java.lang<type=OperatingSystem><>(committed_virtual_memory|free_physical_memory|free_swap_space|total_physical_memory|total_swap_space)_size:' name: os_$1_bytes type: GAUGE attrNameSnakeCase: true - pattern: 'java.lang<type=OperatingSystem><>((?!process_cpu_time)\w+):' name: os_$1 type: GAUGE attrNameSnakeCase: true 解释代码后,解释# HELP jvm_info VM version info # TYPE jvm_info gauge jvm_info{runtime="Java(TM) SE Runtime Environment",vendor="Oracle Corporation",version="1.7.0_79-b15",} 1.0 # HELP os_process_cpu_load java.lang:name=null,type=OperatingSystem,attribute=ProcessCpuLoad # TYPE os_process_cpu_load gauge os_process_cpu_load 0.07142857142857142 # HELP os_open_file_descriptor_count java.lang:name=null,type=OperatingSystem,attribute=OpenFileDescriptorCount # TYPE os_open_file_descriptor_count gauge os_open_file_descriptor_count 84.0 # HELP os_max_file_descriptor_count java.lang:name=null,type=OperatingSystem,attribute=MaxFileDescriptorCount # TYPE os_max_file_descriptor_count gauge os_max_file_descriptor_count 4096.0 # HELP os_total_swap_space_bytes java.lang:name=null,type=OperatingSystem,attribute=TotalSwapSpaceSize # TYPE os_total_swap_space_bytes gauge os_total_swap_space_bytes 4.160745472E9 # HELP os_total_physical_memory_bytes java.lang:name=null,type=OperatingSystem,attribute=TotalPhysicalMemorySize # TYPE os_total_physical_memory_bytes gauge os_total_physical_memory_bytes 8.201289728E9 # HELP os_system_cpu_load java.lang:name=null,type=OperatingSystem,attribute=SystemCpuLoad # TYPE os_system_cpu_load gauge os_system_cpu_load 0.10714285714285714 # HELP os_committed_virtual_memory_bytes java.lang:name=null,type=OperatingSystem,attribute=CommittedVirtualMemorySize # TYPE os_committed_virtual_memory_bytes gauge os_committed_virtual_memory_bytes 3.57505024E9 # HELP os_system_load_average java.lang:name=null,type=OperatingSystem,attribute=SystemLoadAverage # TYPE os_system_load_average gauge os_system_load_average 0.17 # HELP os_free_physical_memory_bytes java.lang:name=null,type=OperatingSystem,attribute=FreePhysicalMemorySize # TYPE os_free_physical_memory_bytes gauge os_free_physical_memory_bytes 6.509023232E9 # HELP os_available_processors java.lang:name=null,type=OperatingSystem,attribute=AvailableProcessors # TYPE os_available_processors gauge os_available_processors 2.0 # HELP os_free_swap_space_bytes java.lang:name=null,type=OperatingSystem,attribute=FreeSwapSpaceSize # TYPE os_free_swap_space_bytes gauge os_free_swap_space_bytes 4.160745472E9 # HELP jmx_scrape_duration_seconds Time this JMX scrape took, in seconds. # TYPE jmx_scrape_duration_seconds gauge jmx_scrape_duration_seconds 0.001119413 # HELP jmx_scrape_error Non-zero if this scrape failed. # TYPE jmx_scrape_error gauge jmx_scrape_error 0.0 # HELP jmx_scrape_cached_beans Number of beans with their matching rule cached # TYPE jmx_scrape_cached_beans gauge jmx_scrape_cached_beans 0.0 # HELP jvm_buffer_pool_used_bytes Used bytes of a given JVM buffer pool. # TYPE jvm_buffer_pool_used_bytes gauge jvm_buffer_pool_used_bytes{pool="direct",} 8192.0 jvm_buffer_pool_used_bytes{pool="mapped",} 0.0 # HELP jvm_buffer_pool_capacity_bytes Bytes capacity of a given JVM buffer pool. # TYPE jvm_buffer_pool_capacity_bytes gauge jvm_buffer_pool_capacity_bytes{pool="direct",} 8192.0 jvm_buffer_pool_capacity_bytes{pool="mapped",} 0.0 # HELP jvm_buffer_pool_used_buffers Used buffers of a given JVM buffer pool. # TYPE jvm_buffer_pool_used_buffers gauge jvm_buffer_pool_used_buffers{pool="direct",} 1.0 jvm_buffer_pool_used_buffers{pool="mapped",} 0.0 # HELP jvm_memory_objects_pending_finalization The number of objects waiting in the finalizer queue. # TYPE jvm_memory_objects_pending_finalization gauge jvm_memory_objects_pending_finalization 0.0 # HELP jvm_memory_bytes_used Used bytes of a given JVM memory area. # TYPE jvm_memory_bytes_used gauge jvm_memory_bytes_used{area="heap",} 2.38314152E8 jvm_memory_bytes_used{area="nonheap",} 5.160628E7 # HELP jvm_memory_bytes_committed Committed (bytes) of a given JVM memory area. # TYPE jvm_memory_bytes_committed gauge jvm_memory_bytes_committed{area="heap",} 5.19569408E8 jvm_memory_bytes_committed{area="nonheap",} 5.2822016E7 # HELP jvm_memory_bytes_max Max (bytes) of a given JVM memory area. # TYPE jvm_memory_bytes_max gauge jvm_memory_bytes_max{area="heap",} 1.823473664E9 jvm_memory_bytes_max{area="nonheap",} 1.3631488E8 # HELP jvm_memory_bytes_init Initial bytes of a given JVM memory area. # TYPE jvm_memory_bytes_init gauge jvm_memory_bytes_init{area="heap",} 1.28145152E8 jvm_memory_bytes_init{area="nonheap",} 2.4576E7 # HELP jvm_memory_pool_bytes_used Used bytes of a given JVM memory pool. # TYPE jvm_memory_pool_bytes_used gauge jvm_memory_pool_bytes_used{pool="Code Cache",} 3370048.0 jvm_memory_pool_bytes_used{pool="PS Eden Space",} 1.78591736E8 jvm_memory_pool_bytes_used{pool="PS Survivor Space",} 2.4223408E7 jvm_memory_pool_bytes_used{pool="PS Old Gen",} 3.5499008E7 jvm_memory_pool_bytes_used{pool="PS Perm Gen",} 4.8236232E7 # HELP jvm_memory_pool_bytes_committed Committed bytes of a given JVM memory pool. # TYPE jvm_memory_pool_bytes_committed gauge jvm_memory_pool_bytes_committed{pool="Code Cache",} 4063232.0 jvm_memory_pool_bytes_committed{pool="PS Eden Space",} 4.09468928E8 jvm_memory_pool_bytes_committed{pool="PS Survivor Space",} 2.4641536E7 jvm_memory_pool_bytes_committed{pool="PS Old Gen",} 8.5458944E7 jvm_memory_pool_bytes_committed{pool="PS Perm Gen",} 4.8758784E7 # HELP jvm_memory_pool_bytes_max Max bytes of a given JVM memory pool. # TYPE jvm_memory_pool_bytes_max gauge jvm_memory_pool_bytes_max{pool="Code Cache",} 5.0331648E7 jvm_memory_pool_bytes_max{pool="PS Eden Space",} 6.31242752E8 jvm_memory_pool_bytes_max{pool="PS Survivor Space",} 2.4641536E7 jvm_memory_pool_bytes_max{pool="PS Old Gen",} 1.367343104E9 jvm_memory_pool_bytes_max{pool="PS Perm Gen",} 8.5983232E7 # HELP jvm_memory_pool_bytes_init Initial bytes of a given JVM memory pool. # TYPE jvm_memory_pool_bytes_init gauge jvm_memory_pool_bytes_init{pool="Code Cache",} 2555904.0 jvm_memory_pool_bytes_init{pool="PS Eden Space",} 3.2505856E7 jvm_memory_pool_bytes_init{pool="PS Survivor Space",} 5242880.0 jvm_memory_pool_bytes_init{pool="PS Old Gen",} 8.5458944E7 jvm_memory_pool_bytes_init{pool="PS Perm Gen",} 2.2020096E7 # HELP jvm_memory_pool_collection_used_bytes Used bytes after last collection of a given JVM memory pool. # TYPE jvm_memory_pool_collection_used_bytes gauge jvm_memory_pool_collection_used_bytes{pool="PS Eden Space",} 0.0 jvm_memory_pool_collection_used_bytes{pool="PS Survivor Space",} 2.4223408E7 jvm_memory_pool_collection_used_bytes{pool="PS Old Gen",} 0.0 jvm_memory_pool_collection_used_bytes{pool="PS Perm Gen",} 0.0 # HELP jvm_memory_pool_collection_committed_bytes Committed after last collection bytes of a given JVM memory pool. # TYPE jvm_memory_pool_collection_committed_bytes gauge jvm_memory_pool_collection_committed_bytes{pool="PS Eden Space",} 4.09468928E8 jvm_memory_pool_collection_committed_bytes{pool="PS Survivor Space",} 2.4641536E7 jvm_memory_pool_collection_committed_bytes{pool="PS Old Gen",} 0.0 jvm_memory_pool_collection_committed_bytes{pool="PS Perm Gen",} 0.0 # HELP jvm_memory_pool_collection_max_bytes Max bytes after last collection of a given JVM memory pool. # TYPE jvm_memory_pool_collection_max_bytes gauge jvm_memory_pool_collection_max_bytes{pool="PS Eden Space",} 6.31242752E8 jvm_memory_pool_collection_max_bytes{pool="PS Survivor Space",} 2.4641536E7 jvm_memory_pool_collection_max_bytes{pool="PS Old Gen",} 1.367343104E9 jvm_memory_pool_collection_max_bytes{pool="PS Perm Gen",} 8.5983232E7 # HELP jvm_memory_pool_collection_init_bytes Initial after last collection bytes of a given JVM memory pool. # TYPE jvm_memory_pool_collection_init_bytes gauge jvm_memory_pool_collection_init_bytes{pool="PS Eden Space",} 3.2505856E7 jvm_memory_pool_collection_init_bytes{pool="PS Survivor Space",} 5242880.0 jvm_memory_pool_collection_init_bytes{pool="PS Old Gen",} 8.5458944E7 jvm_memory_pool_collection_init_bytes{pool="PS Perm Gen",} 2.2020096E7 # HELP jvm_classes_currently_loaded The number of classes that are currently loaded in the JVM # TYPE jvm_classes_currently_loaded gauge jvm_classes_currently_loaded 8198.0 # HELP jvm_classes_loaded_total The total number of classes that have been loaded since the JVM has started execution # TYPE jvm_classes_loaded_total counter jvm_classes_loaded_total 8198.0 # HELP jvm_classes_unloaded_total The total number of classes that have been unloaded since the JVM has started execution # TYPE jvm_classes_unloaded_total counter jvm_classes_unloaded_total 0.0 # HELP jmx_exporter_build_info A metric with a constant '1' value labeled with the version of the JMX exporter. # TYPE jmx_exporter_build_info gauge jmx_exporter_build_info{version="0.18.0",name="jmx_prometheus_javaagent",} 1.0 # HELP jvm_threads_current Current thread count of a JVM # TYPE jvm_threads_current gauge jvm_threads_current 29.0 # HELP jvm_threads_daemon Daemon thread count of a JVM # TYPE jvm_threads_daemon gauge jvm_threads_daemon 28.0 # HELP jvm_threads_peak Peak thread count of a JVM # TYPE jvm_threads_peak gauge jvm_threads_peak 31.0 # HELP jvm_threads_started_total Started thread count of a JVM # TYPE jvm_threads_started_total counter jvm_threads_started_total 33.0 # HELP jvm_threads_deadlocked Cycles of JVM-threads that are in deadlock waiting to acquire object monitors or ownable synchronizers # TYPE jvm_threads_deadlocked gauge jvm_threads_deadlocked 0.0 # HELP jvm_threads_deadlocked_monitor Cycles of JVM-threads that are in deadlock waiting to acquire object monitors # TYPE jvm_threads_deadlocked_monitor gauge jvm_threads_deadlocked_monitor 0.0 # HELP jvm_threads_state Current count of threads by state # TYPE jvm_threads_state gauge jvm_threads_state{state="NEW",} 0.0 jvm_threads_state{state="WAITING",} 14.0 jvm_threads_state{state="TIMED_WAITING",} 7.0 jvm_threads_state{state="UNKNOWN",} 0.0 jvm_threads_state{state="TERMINATED",} 0.0 jvm_threads_state{state="RUNNABLE",} 8.0 jvm_threads_state{state="BLOCKED",} 0.0 # HELP process_cpu_seconds_total Total user and system CPU time spent in seconds. # TYPE process_cpu_seconds_total counter process_cpu_seconds_total 17.38 # HELP process_start_time_seconds Start time of the process since unix epoch in seconds. # TYPE process_start_time_seconds gauge process_start_time_seconds 1.749808021796E9 # HELP process_open_fds Number of open file descriptors. # TYPE process_open_fds gauge process_open_fds 84.0 # HELP process_max_fds Maximum number of open file descriptors. # TYPE process_max_fds gauge process_max_fds 4096.0 # HELP process_virtual_memory_bytes Virtual memory size in bytes. # TYPE process_virtual_memory_bytes gauge process_virtual_memory_bytes 3.575046144E9 # HELP process_resident_memory_bytes Resident memory size in bytes. # TYPE process_resident_memory_bytes gauge process_resident_memory_bytes 6.88590848E8 # HELP jmx_config_reload_failure_total Number of times configuration have failed to be reloaded. # TYPE jmx_config_reload_failure_total counter jmx_config_reload_failure_total 0.0 # HELP jmx_config_reload_success_total Number of times configuration have successfully been reloaded. # TYPE jmx_config_reload_success_total counter jmx_config_reload_success_total 0.0 # HELP jvm_memory_pool_allocated_bytes_total Total bytes allocated in a given JVM memory pool. Only updated after GC, not continuously. # TYPE jvm_memory_pool_allocated_bytes_total counter jvm_memory_pool_allocated_bytes_total{pool="PS Survivor Space",} 3.523552E7 jvm_memory_pool_allocated_bytes_total{pool="Code Cache",} 3718208.0 jvm_memory_pool_allocated_bytes_total{pool="PS Perm Gen",} 4.5692072E7 jvm_memory_pool_allocated_bytes_total{pool="PS Eden Space",} 1.43917056E9 jvm_memory_pool_allocated_bytes_total{pool="PS Old Gen",} 3.5499008E7 # HELP jvm_gc_collection_seconds Time spent in a given JVM garbage collector in seconds. # TYPE jvm_gc_collection_seconds summary jvm_gc_collection_seconds_count{gc="PS Scavenge",} 11.0 jvm_gc_collection_seconds_sum{gc="PS Scavenge",} 0.15 jvm_gc_collection_seconds_count{gc="PS MarkSweep",} 0.0 jvm_gc_collection_seconds_sum{gc="PS MarkSweep",} 0.0 # HELP jmx_config_reload_failure_created Number of times configuration have failed to be reloaded. # TYPE jmx_config_reload_failure_created gauge jmx_config_reload_failure_created 1.749808021823E9 # HELP jmx_config_reload_success_created Number of times configuration have successfully been reloaded. # TYPE jmx_config_reload_success_created gauge jmx_config_reload_success_created 1.749808021822E9 # HELP jvm_memory_pool_allocated_bytes_created Total bytes allocated in a given JVM memory pool. Only updated after GC, not continuously. # TYPE jvm_memory_pool_allocated_bytes_created gauge jvm_memory_pool_allocated_bytes_created{pool="PS Survivor Space",} 1.749808022447E9 jvm_memory_pool_allocated_bytes_created{pool="Code Cache",} 1.749808022448E9 jvm_memory_pool_allocated_bytes_created{pool="PS Perm Gen",} 1.749808022448E9 jvm_memory_pool_allocated_bytes_created{pool="PS Eden Space",} 1.749808022448E9 jvm_memory_pool_allocated_bytes_created{pool="PS Old Gen",} 1.749808022448E9
最新发布
06-14
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值