我正在使用Netty 4.1 Beta3构建一个消息传递应用程序来设计我的服务器,并且服务器理解MQTT协议.
这是我的MqttServer.java类,它设置Netty服务器并将其绑定到特定端口.
EventLoopGroup bossPool=new NioEventLoopGroup();
EventLoopGroup workerPool=new NioEventLoopGroup();
try {
ServerBootstrap boot=new ServerBootstrap();
boot.group(bossPool,workerPool);
boot.channel(NioServerSocketChannel.class);
boot.childHandler(new MqttProxyChannel());
boot.bind(port).sync().channel().closeFuture().sync();
} catch (Exception e) {
e.printStackTrace();
}finally {
workerPool.shutdownGracefully();
bossPool.shutdownGracefully();
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我在Mac上对我的应用程序进行了负载测试,具有以下配置

网络性能非常出色.我在执行代码时查看了jstack,发现netty NIO产生了大约19个线程,但似乎没有一个线程等待通道或其他东西.
然后我在linux机器上执行了我的代码

这是一款2核15GB机器.问题是我的MQTT客户端发送的数据包似乎需要花费很长时间才能通过netty管道,并且在获取jstack时我发现有5个netty线程,所有这些都被困在这个
."nioEventLoopGroup-3-4" #112 prio=10 os_prio=0 tid=0x00007fb774008800 nid=0x2a0e runnable [0x00007fb768fec000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:79)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
- locked <0x00000006d0fdc898> (a
io.netty.channel.nio.SelectedSelectionKeySet)
- locked <0x00000006d100ae90> (a java.util.Collections$UnmodifiableSet)
- locked <0x00000006d0fdc7f0> (a sun.nio.ch.EPollSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:621)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:309)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:834)
at …Run Code Online (Sandbox Code Playgroud) 我知道最新的docker compose,我们可以指定基于每个服务的日志记录.例如: -
version: '2'
services:
Sachin:
image: hike/ubuntu:14.04
volumes:
- .:/testDocker
working_dir: /testDocker
logging:
driver: "json-file"
options:
max-size: "25m"
max-file: "2"
command: python -u test.py
Run Code Online (Sandbox Code Playgroud)
我的compose文件中有大量容器.我可以为docker守护程序本身指定日志配置.我只是想知道是否可以在docker compose文件的全局级别指定日志记录配置.像这样的东西
version: '2'
services:
Sachin:
image: hike/ubuntu:14.04
volumes:
- .:/testDocker
working_dir: /testDocker
logging:
driver: "json-file"
options:
max-size: "25m"
max-file: "2"
command: python -u test.py
Run Code Online (Sandbox Code Playgroud) System.out.println((long)(new Object()!=null ? 0 : new Object()));
Run Code Online (Sandbox Code Playgroud)
在执行时,这给出了类强制转换异常,如下所示
Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
Run Code Online (Sandbox Code Playgroud)
这可能是一个蹩脚的问题,但即使在我们明确地将0返回到long之后,我也无法理解为什么会发生这种情况.