• elasticsearch jvm优化


    测试环境elasticsearch jvm 4G jdk1.8

    [serveradm@test-log-server elasticsearch]$ java -version
    java version "1.8.0_212"
    Java(TM) SE Runtime Environment (build 1.8.0_212-b10)
    Java HotSpot(TM) 64-Bit Server VM (build 25.212-b10, mixed mode)
    [serveradm@test-log-server elasticsearch]$ 

    -Xms4g
    -Xmx4g

     jmap -heap pid查看heap内存大小

    [serveradm@test-log-server elasticsearch]$ jmap -heap 11516
    Attaching to process ID 11516, please wait...
    Debugger attached successfully.
    Server compiler detected.
    JVM version is 25.212-b10
    
    using parallel threads in the new generation.
    using thread-local object allocation.
    Concurrent Mark-Sweep GC
    
    Heap Configuration:
       MinHeapFreeRatio         = 40
       MaxHeapFreeRatio         = 70
       MaxHeapSize              = 4294967296 (4096.0MB)
       NewSize                  = 348913664 (332.75MB)
       MaxNewSize               = 348913664 (332.75MB)
       OldSize                  = 3946053632 (3763.25MB)
       NewRatio                 = 2
       SurvivorRatio            = 8
       MetaspaceSize            = 21807104 (20.796875MB)
       CompressedClassSpaceSize = 1073741824 (1024.0MB)
       MaxMetaspaceSize         = 17592186044415 MB
       G1HeapRegionSize         = 0 (0.0MB)
    
    Heap Usage:
    New Generation (Eden + 1 Survivor Space):
       capacity = 314048512 (299.5MB)
       used     = 275463512 (262.70247650146484MB)
       free     = 38585000 (36.797523498535156MB)
       87.7136816365492% used
    Eden Space:
       capacity = 279183360 (266.25MB)
       used     = 245544536 (234.16951751708984MB)
       free     = 33638824 (32.080482482910156MB)
       87.95099249468163% used
    From Space:
       capacity = 34865152 (33.25MB)
       used     = 29918976 (28.532958984375MB)
       free     = 4946176 (4.717041015625MB)
       85.81341047932331% used
    To Space:
       capacity = 34865152 (33.25MB)
       used     = 0 (0.0MB)
       free     = 34865152 (33.25MB)
       0.0% used
    concurrent mark-sweep generation:
       capacity = 3946053632 (3763.25MB)
       used     = 27565128 (26.28815460205078MB)
       free     = 3918488504 (3736.961845397949MB)
       0.6985492487092482% used
    View Code

    主要信息如下:

    MaxHeapSize = 4294967296 (4096.0MB)
    NewSize = 348913664 (332.75MB)
    MaxNewSize = 348913664 (332.75MB)
    OldSize = 3946053632 (3763.25MB)
    NewRatio = 2

    通过https://www.jianshu.com/p/832fc4d4cb53计算可得:

    默认情况下和cpu核数有关:

    64M * 4 * 13 / 10 = 332.8M

    max_heap / (NewRatio+1) 的值为4096M / 3 = 1365M

    符合文章所说的大小

    所以,YoungGen 的大小在没有设置的情况下是通过计算得出的,其大小可能与 NewRatio 的默认配置没什么关系而与ParallelGCThreads 的配置有一定的关系。
    那么既然 YoungGen 大小有不确定性,我们最好还是通过这些 -XX:NewSize、-XX:MaxNewSize 或者 -xmn 参数设置下

    设置参数:
    -Xms4g
    -Xmx4g
    -XX:NewRatio=4
    [serveradm@test-log-server elasticsearch]$ jmap -heap 11885
    Attaching to process ID 11885, please wait...
    Debugger attached successfully.
    Server compiler detected.
    JVM version is 25.212-b10
    
    using parallel threads in the new generation.
    using thread-local object allocation.
    Concurrent Mark-Sweep GC
    
    Heap Configuration:
       MinHeapFreeRatio         = 40
       MaxHeapFreeRatio         = 70
       MaxHeapSize              = 4294967296 (4096.0MB)
       NewSize                  = 858980352 (819.1875MB)
       MaxNewSize               = 858980352 (819.1875MB)
       OldSize                  = 3435986944 (3276.8125MB)
       NewRatio                 = 4
       SurvivorRatio            = 8
       MetaspaceSize            = 21807104 (20.796875MB)
       CompressedClassSpaceSize = 1073741824 (1024.0MB)
       MaxMetaspaceSize         = 17592186044415 MB
       G1HeapRegionSize         = 0 (0.0MB)
    
    Heap Usage:
    New Generation (Eden + 1 Survivor Space):
       capacity = 773128192 (737.3125MB)
       used     = 486640352 (464.0964050292969MB)
       free     = 286487840 (273.2160949707031MB)
       62.94432890115072% used
    Eden Space:
       capacity = 687276032 (655.4375MB)
       used     = 413461664 (394.3077697753906MB)
       free     = 273814368 (261.1297302246094MB)
       60.15947665115142% used
    From Space:
       capacity = 85852160 (81.875MB)
       used     = 73178688 (69.78863525390625MB)
       free     = 12673472 (12.08636474609375MB)
       85.23802779103053% used
    To Space:
       capacity = 85852160 (81.875MB)
       used     = 0 (0.0MB)
       free     = 85852160 (81.875MB)
       0.0% used
    concurrent mark-sweep generation:
       capacity = 3435986944 (3276.8125MB)
       used     = 25476440 (24.296226501464844MB)
       free     = 3410510504 (3252.516273498535MB)
       0.7414591619589112% used
    View Code

    此时heap信息如下:

    MaxHeapSize = 4294967296 (4096.0MB)
    NewSize = 858980352 (819.1875MB)
    MaxNewSize = 858980352 (819.1875MB)
    OldSize = 3435986944 (3276.8125MB)
    NewRatio = 4

    堆内存查看:

    jstat -gc pid 默认单位k
    [serveradm@test-log-server elasticsearch]$ jstat -gc 11885
    S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT 
    83840.0 83840.0 0.0 13404.3 671168.0 644823.4 3355456.0 250260.3 83012.0 76771.6 12156.0 10227.8 21 0.771 4 0.246 1.017
    [serveradm@test-log-server elasticsearch]$
    • S0C:survivor0区总内存大小(Capacity)
    • S1C: survivor1区总内存大小
    • S0U: survivor0区当前内存大小(Used)
    • S1U: survivor1区当前内存大小
    • EC:Eden区总内存大小
    • EU:Eden区当前内存大小
    • OC:老年代总内存大小
    • OU:老年代当前内存大小
    • MC:meta data区总内存大小
    • MU:meta data区当前内存大小
    所以:
    NewSize=S0C+S1C+EC
     OldSize=OC
    jvm常用参数:
    -Xms :表示java虚拟机堆区内存初始内存分配的大小
    -Xmx:表示java虚拟机堆区内存可被分配的最大上限
    通常会将-Xms 与-Xmx两个参数的配置相同的值,其目的是为了能够在java垃圾回收机制清理完堆区后不需要重新分隔计算堆区的大小而浪费资源
    -XX:newSize:表示新生代初始内存的大小,应该小于-Xms的值
    -XX:MaxnewSize:表示新生代可被分配的内存的最大上限;当然这个值应该小于-Xmx的值;
    -Xmn:至于这个参数则是对 -XX:newSize、-XX:MaxnewSize两个参数的同时配置,也就是说如果通过-Xmn来配置新生代的内存大小,那么-XX:newSize = -XX:MaxnewSize = -Xmn
    java虚拟机对非堆区内存配置的两个参数:
    -XX:PermSize:表示非堆区初始内存分配大小(方法区)
    -XX:MaxPermSize:表示对非堆区分配的内存的最大上限(方法区)
  • 相关阅读:
    CEF调试符号下载地址
    Koa搭建静态文件服务器
    查看requireJS已经加载的模块
    Android Unterminated string at character
    【微信支付】公众号 JSAPI支付 HTML5(使用MUI前端框架)+WebApi 实现流程
    winform 替换word文档中的字段(包含图片添加),生成导出PDF文件(也可是word文件)
    小程序 获取用户信息及手机号码
    winform PictureBox图片上动态添加Label或其他控件
    Html5+Mui前端框架,开发记录(四):下拉菜单绑定数据、搜索、时间控件
    Html5+Mui前端框架,开发记录(三):七牛云 上传图片
  • 原文地址:https://www.cnblogs.com/xuliang666/p/11942443.html
Copyright © 2020-2023  润新知