GithubHelp home page GithubHelp logo

socket's People

Contributors

allanbian1017 avatar areong avatar itcthienkhiem avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

socket's Issues

Solve 100% CPU usage at server listening.

(Related pull request: #6)

Purpose

#3 and #4 report 100% CPU usage when SocketServer is listening to connections. This phenomenon should not happen. The phenomenon is probably caused by that the SocketServer keeps listening after a client is connected.

Method

Let the user decide how many connections a SocketServer is going to listen. Once the specified number of clients connected, the SocketServer stops listening.

To-do

  • Rewrite the test code to verify the phenomenon.
    • Large CPU usage indeed happens. It happens on the server when the connected client is closed while the server is not yet closed.
    • I'm not sure if it is the same phenomenon stated in the two issues above.
    • One possible solution is to close the server after all connected clients were closed.
    • To define "all" clients, the upper limit of connection to a server should be specified, as stated in the purpose.
    • Update: A better solution is to close the corresponding connection thread once the connected client is closed. In this case, it does not matter whether there is an upper limit of the number of connections to a server.
  • [ ] Let SocketServer only listen to a specified number of connections.

Method

Close the corresponding connection thread once the connected client is closed. Also remove the closed connection thread from the list.

  • Socket.isClosed() will not be true until Socket.close() is called. That is, even the connected endpoint closes its socket, Socket.isClosed() on this side still returns false before Socket.close() is called.
  • Socket.isConnected() is true after it is connected to another endpoint. It will still be true when the other endpoint closes.
  • Use the first byte in the message sent from the client to tell the server if the connection should be closed.
  • Remove not running ConnectionThreads.
  • Merge the pull request and close this issue.

使用这个socket会报cpu使用100%

借用这个插件的时候,客户端和服务端分离,当服务端一直运行时,当每次新建一个客户端socket时,就会产生一个监听,然后监听一个连接,这样使用就会出现cpu使用100%的情况,使用jstack查了一下堆栈信息,发现监听线程和BufferedReader一直阻塞。然后我在BufferedReader接收消息然后回复后就马上关掉它,暂时保证CPU使用没有达到100%

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.