Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High CPU usage when rest server running and idle (25% CPU) #41

Closed
sanchezpablo opened this issue Jan 31, 2021 · 5 comments
Closed

High CPU usage when rest server running and idle (25% CPU) #41

sanchezpablo opened this issue Jan 31, 2021 · 5 comments
Labels
fixed Issue was fixed or otherwise resolved.

Comments

@sanchezpablo
Copy link
Contributor

Is it normal that when server is running the CPU usage is 25% no matter what? there is no activity and the CPU usage is 25% continously.

image

Can we do anything to make it idle?

@scottoffen
Copy link
Owner

When the server is idle (no requests) it should be taking up 0% CPU. Can you post some sample code for me to take a look at?

@scottoffen scottoffen added the more-information-needed Needs more information before issue can be resolved label Feb 1, 2021
@sanchezpablo
Copy link
Contributor Author

Hi @scottoffen I tried with the sample provided in the repository, but the same result, so I decided to left a comment, maybe it's something else... I've tried also with other embedded webserver (https://github.com/unosquare/embedio) and the CPU is 0% when the server is idle.

If you need more information, let me know.

@scottoffen
Copy link
Owner

How are you blocking the thread while the server is running? If you are just benchmarking, use this method:

server.Start();
Console.ReadLine();

image

@sanchezpablo
Copy link
Contributor Author

sanchezpablo commented Feb 1, 2021

I used the server.Run() as in the sample, when I use server.Start() the CPU gets down to 0% when idle. So the server.Run() does something else in the background?

        public static void Run(this IRestServer server)
        {
            server.Start();
            while (server.IsListening) { }
        }

Probably the while loop inside...

Thanks!

@scottoffen
Copy link
Owner

scottoffen commented Feb 2, 2021

That while loop takes up a lot. I already changed it to poll the server at a predefined number of seconds, but that isn't in a release yet. I'll be changing it again soon to something more performant, so expect that to change.

Either way, when idle, the server takes up 0% cpu.

@scottoffen scottoffen added fixed Issue was fixed or otherwise resolved. and removed more-information-needed Needs more information before issue can be resolved labels Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed Issue was fixed or otherwise resolved.
Projects
None yet
Development

No branches or pull requests

2 participants