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

[libuv] libuv cost lot's of cpu. #404

Closed
sonygod opened this issue Aug 1, 2020 · 3 comments
Closed

[libuv] libuv cost lot's of cpu. #404

sonygod opened this issue Aug 1, 2020 · 3 comments

Comments

@sonygod
Copy link

sonygod commented Aug 1, 2020

libuv cost lot's of cpu.

why libuv cost lot's of cpu.

just an instance of tcp.

class Main {
	static function main() {
	

		var loop = hl.uv.Loop.getDefault();
	
		var tcp = new hl.uv.Tcp(loop);//cost more than 50%~90% of single cpu
	}
}

image

hl 1.12.0

@sonygod
Copy link
Author

sonygod commented Aug 15, 2020

@ncannasse will you take a look?

@ncannasse
Copy link
Member

I think this is by design, and definitely not HashLink related.

@RealyUniqueName
Copy link
Member

I think this happens because of the integration of libuv's default loop into Haxe's MainLoop:

loopEvent = haxe.MainLoop.add(function() {
	// if no more things to process, stop
	if (def.run(NoWait) == 0) {
		loopEvent.stop();
		loopEvent = null;
	}
});

https://github.com/HaxeFoundation/haxe/blob/fe23a92264be3853dddb03cf664595f2a07aa196/std/hl/uv/Loop.hx#L49-L55
Since tcp handler is alive, def.run(NoWait) immediately returns non-zero value. And then MainLoop immediately runs the next tick because loopEvent is not stopped.
These PRs should address the issue: #464, HaxeFoundation/haxe#10342

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants