Giter Club home page Giter Club logo

dc1server's People

Contributors

yuan910715 avatar zxq-kyle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dc1server's Issues

【bug】dc1server产生大量线程池,最终沾满服务器内存导致程序崩溃

直接跑项目源码连接dc1插座未发现此问题,但是打成jar包后这个问题就出现了。通过jmx连接查看jvm运行情况发现创建了大量的线程池。 最终导致应用程序崩溃。目前dc1的release jar包和docker 镜像都存在这种情况。
image
image
下面是我写的一些测试代码,不知道是不是这么写是否正确,但确实会引起上述问题 并产生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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.