Giter Club home page Giter Club logo

Comments (5)

jvanlangen avatar jvanlangen commented on July 28, 2024

I've found something that might be causing hi-cpu load.

if (!(stream as NetworkStream).DataAvailable)
{
continue;
}

The problem is, that when there is no data, it will directly continue the while loop. There is no sleep/wait event here. So it acks like a shortcircuit.
I just added a sleep(1) which brings the cpu usage down dramatically.

Any thoughts?

from libua.

bevanweiss avatar bevanweiss commented on July 28, 2024

This is my breakage, I didn't notice that it's caused high CPU.
What I should have probably done is do the ReadAsync() and a TimerAsync (driven by the NeedsPulse), await either.. check if the Read is complete, if it is, go and do the read stuff.. otherwise if the NeedsPulse is ready, go and do the timer stuff (then reset timer task.. or just set it as autoresetting) then go back to waiting for them..

But short term... you could just check out the previous revision 990a7ac

I'll try to fix this up in the next week or so.

from libua.

nauful avatar nauful commented on July 28, 2024

Reverted back to the previous version. Try the latest master and let us know if you still see high CPU usage.

from libua.

jvanlangen avatar jvanlangen commented on July 28, 2024

I also found some small points in the code, which are not quite nice in terms of code structure.

For example (stream as NetworkStream).DataAvailable, now you can be sure that stream is a NetworkStream, but if this ever changes you will get a NullReferenceException here. NullReferenceExceptions are generally seen as sloppiness.

It's better to do a hard cast here. ((NetworkStream)stream).DataAvailable, if the stream is not NetworkStream, you will get a InvalidCastException which explains the error better.

Would you mind if I contributed something?

from libua.

nauful avatar nauful commented on July 28, 2024

Sure, feel free.

from libua.

Related Issues (20)

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.