Netty4 bottom-up with object pooling and without object pooling practice optimization

Source: Internet
Author: User

with the development of JVM virtual machine and JIT compilation technology, object allocation and collection is a very lightweight task. But for buffer buffers, the situation is slightly different, especially for the allocation and recycling of out-of-heap direct memory, which is a time-consuming operation. In order to reuse buffers as much as possible, Netty provides a buffer reuse mechanism based on the memory pool. The performance test shows that the bytebuf of the memory pool is about 23 times times higher than that of the bytebuf, which is strongly correlated with the performance data. in the 4.x version, Unpooledbytebufallocator is the default allocator, although there are some limitations. Now that Pooledbytebufallocator has been used extensively for a while, and we have an enhanced buffer leak tracking mechanism, it's time to make Pooledbytebufallocator the default.
Before optimization: When the player reaches about 1100, the direct memory increases rapidly and the CPU occupies high
At the highest peak, the server heap memory is 3993 m, occupying the heap memory 3476 m, and the direct memory is 2048 m, occupying direct memory 715.8125 m.
found that the objects at the bottom of the Netty occupy a lot

Class Name Shallow Heap retained Heap
  • class Com.lingyu.game.service.stage.StageManager @ 0x738778950 ?
8 166,381,728
UL style= "List-style:none; overflow:visible; margin:0px; padding:0px ">
  • Com.lingyu.game.service.equip.EquipDataTemplateManager @ 0x738051240 ?
  • 64 61,389,640
    • io.netty.channel.abstractchannelhandlercontext$writeandflushtask @ 0x7a8a1b698 ?
    40 56,363,384
    UL style= "List-style:none; overflow:visible; margin:0px; padding:0px ">
  • com.lingyu.game.service.map.mapdatatemplatemanager @ 0x738709b70 ?
  • 64 48,234,856
    • com.lingyu.game.service.item.itemrepository @ 0x7387965e0 ?
    24 45,883,384
    UL style= "List-style:none; overflow:visible; margin:0px; padding:0px ">
  • io.netty.channel.abstractchannelhandlercontext$ Writeandflushtask @ 0x7d0b4ad08 ?
  • 40 45,730,344
    • io.netty.channel.abstractchannelhandlercontext$writeandflushtask @ 0x7dba870e8 ?
    40 43,118,248
    UL style= "List-style:none; overflow:visible; margin:0px; padding:0px ">
  • io.netty.channel.abstractchannelhandlercontext$ Writeandflushtask @ 0x76289b300 ?
  • 40 41,260,728
    • io.netty.channel.abstractchannelhandlercontext$writeandflushtask @ 0x796226f90 ?
    40 33,083,800
    UL style= "List-style:none; overflow:visible; margin:0px; padding:0px ">
  • io.netty.channel.abstractchannelhandlercontext$ Writeandflushtask @ 0x7ec9f19a0 ?
  • 40 32,922,432
    • io.netty.channel.channeloutboundbuffer @ 0x754207b68 ?
    72 25,823,800
    • Total:11 entries

    Optimization, guess is because the direct memory is not enough, in the application of space repeatedly, resulting in CPU consumption, and direct memory is not lost! After using the object pool, 1380 people, the CPU occupies approximately 100/1200, the performance is very stable, the number of FULLGC is 0 server heap memory total 3993 m, occupy heap memory 2150 m, direct memory total 2048 m, occupy direct memory 400.00098 m
    S0 S1 E O P ygc ygct FGC fgct GCT
    0.00 0.71 8.87 15.05 71.87 175 2.638 0 0.000 2.638

    The main is added the following two sentences: Bootstrap.option (Channeloption.allocator, Pooledbytebufallocator.default);
    Bootstrap.childoption (Channeloption.allocator, Pooledbytebufallocator.default);/The key is this sentence


    Class Name Shallow Heap retained Heap
    • class Com.lingyu.game.service.stage.StageManager @ 0x738977238 ?
    8 126,628,072
    UL style= "List-style:none; overflow:visible; margin:0px; padding:0px ">
  • Com.lingyu.game.service.equip.EquipDataTemplateManager @ 0x7380c53f8 ?
  • 64 61,391,800
    • com.lingyu.game.service.map.mapdatatemplatemanager @ 0x738ce20d8 ?
    64 48,234,856
    UL style= "List-style:none; overflow:visible; margin:0px; padding:0px ">
  • Com.xianling.stage.configure.entity.map.PathInfoTemplate @ 0x7389e7c60 ?
  • 40 8,975,440
    • sun.misc.launcher$appclassloader @ 0x738024e80 ?
    80 8,652,528
    UL style= "List-style:none; overflow:visible; margin:0px; padding:0px ">
  • com.lmax.disruptor.ringbuffer @ 0x7382e4408 ?
  • 32 7,340,056
    • com.lingyu.game.service.item.itemdatatemplatemanager @ 0x738bc4a30 ?
    56 5,910,288
    UL style= "List-style:none; overflow:visible; margin:0px; padding:0px ">
  • Com.xianling.stage.configure.entity.map.PathInfoTemplate @ 0x73ac19aa8 ?
  • 40 5,231,256
    • org.springframework.beans.factory.support.defaultlistablebeanfactory @ 0x7381979b8 ?
    200 5,172,192
    UL style= "List-style:none; overflow:visible; margin:0px; padding:0px ">
  • Com.xianling.stage.configure.entity.map.PathInfoTemplate @ 0x73addc8b8 ?
  • 40 4,572,560
    Total:10 entries
    Summary: This optimization, memory saved 1.7G, direct memory remaining 300M, and stable performance, the number of online increased by 300 people (may be limited by bandwidth, otherwise performance should be better), CPU from 100% to 10%.

    Netty4 bottom-up with object pooling and without object pooling practice optimization

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.