• 请不要在回答技术问题时复制粘贴 AI 生成的内容
tobychen1991
V2EX  ›  程序员

管理 Netty 的 channel 问题

  •  
  •   tobychen1991 · Sep 4, 2018 · 4954 views
    This topic created in 2814 days ago, the information mentioned may be changed or developed.

    netty 里的 channel 既然不能序列化,请问大家是怎样实现管理,共享 channel 的呢? 总感觉用 ConcurrentHashMap 会有瓶颈,数量上去就承受不了

    11 replies    2018-09-05 09:51:11 +08:00
    BBCCBB
        1
    BBCCBB  
       Sep 4, 2018
    ConcurrentHashMap 能有什么瓶颈, 内存够他就能承受
    tobychen1991
        2
    tobychen1991  
    OP
       Sep 4, 2018
    @BBCCBB 就是怕内存不够呀,如果扩展多台机器就需要共享了
    Finest
        3
    Finest  
       Sep 4, 2018
    Channel 是对一个链接的抽象吧
    xiongzhen
        4
    xiongzhen  
       Sep 4, 2018
    上层拓展一个管理节点管理下面的子节点就好了
    linbiaye
        5
    linbiaye  
       Sep 4, 2018
    为啥要用感觉,预估一下规模,直接测试不就是了?
    BBCCBB
        6
    BBCCBB  
       Sep 4, 2018
    @tobychen1991 不需要共享啊. 长连接和 http 这种不太一样的, 长连接连接上之后就连固定的 socket 了,这个和 http 每次都需要单独发起请求,单独 proxy 到机器不一样.
    anthow
        7
    anthow  
       Sep 4, 2018
    @tobychen1991 你这是有多少链接啊。。。还怕内存不够
    xuqd
        8
    xuqd  
       Sep 4, 2018
    我记得 Netty 本身有个 ChannelPool 类似与连接池的可以使用
    seancheer
        9
    seancheer  
       Sep 4, 2018
    担心单个 map 数量太多效率问题,那就一个 map 存 5w 个,弄 10 个 map,然后在外层结合自己业务场景 hash 到这 10 个 map。

    50w 个还不够就以此类推下。。实际上 map 一次 put 和 get 也就几十 us,数量多了效率也不会太差。
    252748371
        10
    252748371  
       Sep 4, 2018
    你可以算算一个 Channel 占得内存大小,1 台机器你维持 100W 个 Channel,瓶颈已经是 linux 最大文件句柄数了,而且 100W 个 Channel 已经算很厉害了
    goinghugh
        11
    goinghugh  
       Sep 5, 2018
    ChannelGroup 接口可以了解一下,感觉你想说的是怎么集群吧?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4582 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 224ms · UTC 05:36 · PVG 13:36 · LAX 22:36 · JFK 01:36
    ♥ Do have faith in what you're doing.