zxq-kyle / dc1server Goto Github PK
View Code? Open in Web Editor NEWDc1Server
Dc1Server
直接跑项目源码连接dc1插座未发现此问题,但是打成jar包后这个问题就出现了。通过jmx连接查看jvm运行情况发现创建了大量的线程池。 最终导致应用程序崩溃。目前dc1的release jar包和docker 镜像都存在这种情况。
下面是我写的一些测试代码,不知道是不是这么写是否正确,但确实会引起上述问题 并产生oom
`public class OOMTest {
@Test
public void test() throws Exception {
sendMessage("{\"action\":\"activate=\",\"uuid\":\"activate=0ca\",\"auth\":\"\",\"params\":{\"device_type\":\"PLUG_DC1_7\",\"mac\":\"A4:7B:9D:00:1D:C9\"}}");
while(true) {
String id = "T"+System.currentTimeMillis();
sendMessage("{\"action\":\"datapoint\",\"uuid\":"+id+",\"auth\":\"\",\"params\":\"\"}");
sendMessage("{\"uuid\":"+id+",\"status\":200,\"result\":{\"status\":1111,\"I\":0,\"V\":0,\"P\":0},\"msg\":\"get datapoint success\"}");
Thread.sleep(100);
}
}
private void sendMessage(String msg) throws Exception {
System.out.println(msg);
Socket socket = new Socket("localhost", 8000);
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
out.writeBytes(msg);
out.flush();
out.close();
socket.close();
}
}
`
关键异常信息
java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) [na:1.8.0_121] at java.lang.Thread.start(Thread.java:714) [na:1.8.0_121] at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:950) ~[na:1.8.0_121] at java.util.concurrent.ThreadPoolExecutor.ensurePrestart(ThreadPoolExecutor.java:1587) ~[na:1.8.0_121] at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:334) ~[na:1.8.0_121] at java.util.concurrent.ScheduledThreadPoolExecutor.scheduleWithFixedDelay(ScheduledThreadPoolExecutor.java:597) ~[na:1.8.0_121] at space.ponyo.dc1.server.server.DeviceConnection.<init>(DeviceConnection.java:74) ~[main/:na] at space.ponyo.dc1.server.server.ConnectionManager.addChannel(ConnectionManager.java:70) ~[main/:na] at space.ponyo.dc1.server.server.NettySocketServer$ServerHandler.channelActive(NettySocketServer.java:92) ~[main/:na]
目前已经确定的是,这个问题是由每次收到客户端请求(客户端请求的端口号是随机的,所以每次都会出现一个新的DeviceConnection),然后产生了这个问题。
我尝试将端mDeviceConnectionMap中key的端口号删除,并且在remove连接时关闭DeviceConnection和 PhoneConnection的线程池。 同时也去除了DeviceConnection 和 PhoneConnection中sendMessageScheduleThread的static声明. 现在问题得到了暂时的解决,不过目测这是一个bug
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.