Netty UDP Server Bootstrap

场景:使用Netty UDP协议将PHP程序的运行日志推送到Elasticsearch  中 。

 

采用:NioDatagramChannel 通道来实现UDP数据传输 

 突然想到 Netty 的Reactor 线程模型 ,准备使用主从多线程Reacrtor 线程模型 。之前的代码如下

Netty UDP Server Bootstrap_第1张图片

 

红色部分:表示在UDP协议时 使用BootStrap    而不是:ServerBootStrap 

StackOverFlow 上针对 UDP 有如下的Answer

 there is no need for NioServerDatagramChannel, because UDP servers open one channel for all clients.

  • ServerBootstrap allows many client to connect via its channel. Therefore TCP has a dedicated ServerSocketChannel.
  • Bootstrap is used to create channels for single connections. Because UDP has one channel for all clients it makes sense that only the Bootstrap is requried. All clients bind to the same channel

UDP 协议下的所有 客户端都绑定同一个通道仅仅使用Bootstrap ,而TCP都有专用的通道 。

本来打算使用Reacrtor主从模型来提高并发量 ,在调整时发现使用报错,特此记录下 udp 协议使用demo 

Netty UDP Server Bootstrap_第2张图片

udp 推送消息到elasticsearch 中时 的特点: 效率高,速度快,某些场合能极大的改善系统的性能,使用单通道 来传输 数据,那么问题来了如果有大量的日志需要上传会不会影响传输的吞吐量???? 下期遇到问题时在做总结

你可能感兴趣的:(Netty UDP Server Bootstrap)