JVM Maximum Memory Allocation Pool Size

本文介绍如何通过-Xms和-Xmx参数调整Java虚拟机(JVM)的内存分配池初始大小及最大限制。这对于处理大数据量或大型图像矩阵非常关键。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The defaulf size of JVM memory allocation pool size is 64 MB. In some cases, big matrices storing images need to be created, which are usually larger than the limit. Therefore, a big size has to be set.

The following part explains how to increase the limit.

 

java [ options ] class [ argument ... ]
java [ options ] -jar file.jar [ argument ... ]
javaw [ options ] class [ argument ... ]
javaw [ options ] -jar file.jar [ argument ... ]

 

-Xmsn


Specify the initial size, in bytes, of the memory allocation pool. This value must be a multiple of 1024 greater than 1MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 2MB. Examples:

-Xms6291456
-Xms6144k
-Xms6m

 

-Xmxn

 
Specify the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 64MB. Examples:

-Xmx83886080
-Xmx81920k
-Xmx80m

 

from : http://blog.lib.umn.edu/sunx0170/ThinkU/023236.html

more: http://download.oracle.com/javase/1.4.2/docs/tooldocs/windows/java.html

--- 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
<think>我们正在讨论JVM监控指标及其含义。用户希望理解内存池(heap/nonheap)、线程状态(RUNNABLE/WAITING等)、CPU使用率、GC收集时间以及操作系统相关指标。根据引用[1]和引用[2],我们可以整合信息,并结合JVM监控的一般知识进行解释。我们将按照以下结构回答:1.内存池指标:包括堆内存(heap)和非堆内存(non-heap)的各个部分。2.线程状态:解释常见的线程状态(如RUNNABLE,WAITING,BLOCKED等)。3.CPU使用率:解释JVM进程和线程的CPU使用情况。4.GC收集时间:垃圾收集的相关指标。5.操作系统相关指标:与JVM运行相关的系统级指标。注意:引用[1]中提到了一些工具(jps,jstat,jinfo,jstack,jmap,jcmd)的使用场景,我们可以结合这些工具来说明如何获取这些指标。引用[2]提到了jprofiler(商业工具),但我们主要关注指标含义,工具使用仅作为获取指标的途径。回答要求:使用中文,行内数学表达式用$...$,独立公式用$$...$$(但本问题可能公式较少,若有则注意格式)。在回答中,我们会在适当的地方添加引用标识[^1]或[^2](注意引用[1]和[2]的内容已经在问题中给出,我们只需要在引用到这些内容时标注即可)。最后,生成相关问题。开始回答:</think>### JVM监控指标详解 #### 一、内存池指标 1. **堆内存(Heap Memory)** - **年轻代(Young Generation)**:存储新创建对象,由 Eden 区和两个 Survivor 区组成。 - 监控要点:$YoungGC$ 频率过高说明 Eden 区过小(推荐占总堆的 1/3) - **老年代(Old Generation)**:存储长期存活对象。 - 监控要点:$FullGC$ 频繁说明老年代不足或存在内存泄漏 - **元空间(Metaspace)**:存储类元数据(JDK8+替代 PermGen)。 - 监控要点:加载类过多时可能溢出(需调整 `-XX:MaxMetaspaceSize`) 2. **非堆内存(Non-Heap Memory)** - **代码缓存(Code Cache)**:存储 JIT 编译的本地代码 - **线程栈(Thread Stack)**:每个线程独立占用(默认 1MB/线程) - **直接内存(Direct Memory)**:NIO 使用的堆外内存 > **诊断工具**: > - `jstat -gc <pid>`:查看各分区使用量(如 `S0C/S1C/EdenC/OldC`)[^1] > - `jmap -heap <pid>`:输出堆内存分布详情 #### 二、线程状态指标 | 状态 | 含义 | 典型场景 | |-------------|----------------------------------------------------------------------|-----------------------------| | **RUNNABLE** | 线程正在执行或等待CPU资源 | 业务逻辑处理中 | | **BLOCKED** | 线程阻塞等待监视器锁(如 `synchronized` 竞争) | 锁竞争激烈时高频出现 | | **WAITING** | 无限期等待其他线程唤醒(如 `Object.wait()`) | 线程池任务队列空时 | | **TIMED_WAITING** | 有限时间等待(如 `Thread.sleep()`) | 定时任务或网络I/O超时等待 | > **诊断工具**: > - `jstack <pid>`:查看线程堆栈,统计状态分布[^1] > - 高 `BLOCKED` 线程需排查锁竞争;长期 `WAITING` 可能线程泄漏 #### 三、CPU使用率指标 1. **进程级CPU** - 用户态(User%):JVM 执行代码的 CPU 占比 - 内核态(Sys%):内核系统调用消耗(如 I/O 操作) - 过高场景: - 用户态高:计算密集型任务或低效算法 - 内核态高:频繁 I/O 或大量线程上下文切换 2. **线程级CPU** - 通过 `top -Hp <pid>` 定位高消耗线程 - 结合 `jstack` 将线程 ID 转十六进制,匹配堆栈定位热点代码 #### 四、GC收集指标 | 指标 | 含义 | 健康阈值 | |---------------------|-------------------------------|-----------------------| | **Young GC 时间** | 年轻代回收耗时 | 单次 < 50ms | | **Young GC 频率** | 每分钟回收次数 | < 1次/分钟(默认堆) | | **Full GC 时间** | 全堆回收耗时 | 单次 < 1s | | **Full GC 频率** | 触发频率 | 接近0(否则需调优) | > **诊断工具**: > - `jstat -gcutil <pid> 1000`:每秒输出 GC 统计(如 `YGC/YGCT/FGC/FGCT`) > - 推荐工具:VisualVM GC 插件或付费工具 JProfiler[^2] #### 五、操作系统级指标 1. **物理内存使用**:JVM 总占用(堆 + 非堆 + 直接内存)不应超过物理内存 80% 2. **SWAP 使用率**:若 > 0% 说明物理内存不足,引发严重性能下降 3. **文件描述符数**:网络服务需监控,避免 `Too many open files` 错误 4. **上下文切换(Context Switch)**:每秒 > 10万次表明线程调度开销过大 --- ### 监控实践建议 1. **基准建立**:在业务低峰/高峰时段分别采集指标作为基准线 2. **关联分析**:例如: - CPU 高 + 低 GC → 排查计算逻辑 - 内存持续增长 + FullGC 无效 → 内存泄漏(用 `jmap -dump` 分析)[^1] 3. **工具链组合**: ```mermaid graph LR A[jps 定位PID] --> B[jstat 监控GC] A --> C[jstack 查线程] A --> D[jmap 堆分析] D --> E[MAT/VisualVM 可视化] ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值