智能硬件设备,需要实时长链接向服务器发送数据,这个设备只要插上电就会向服务器上传数据。
目前的设计方案是服务器接收一个请求,开一个线程。但是刚才用jMeter测试,发现有100个并发线程CPU就跑140%+了。
就想到了用线程池,但是如果用线程池,如果池子里只有100个线程,我有200个设备接入。是不是就意味着有100个设备连不上。
谢谢大家。
黄舟2017-04-18 09:20:03
I see that you only wrote that the device will send data to the server, but did not write that the server will push data to the device. If this is the case, then it is not impossible to use the HTTP protocol. If there is a two-way demand, but data is uploaded at certain intervals and is not transmitted in real time, you can consider using non-blocking IO to achieve it. In this way, the IO response is sent to the bottom layer of the system, and the Java layer only needs to transmit data again. Just create a thread for processing, which can reduce thread overhead. If there are really 200 device connections, 200 devices will be uploading at the same time and transmitting data continuously. The only way is to upgrade the configuration, and other methods will be thankless.