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

task thrashing #3587

Closed
jesse99 opened this issue Sep 25, 2012 · 5 comments
Closed

task thrashing #3587

jesse99 opened this issue Sep 25, 2012 · 5 comments

Comments

@jesse99
Copy link
Contributor

jesse99 commented Sep 25, 2012

I don't have a good repro for this, but I have observed CPU usage going through the roof on my web server. It starts out fine: 27 threads (as reported by top) and 0% CPU. Then I click on a thingy which opens up two server-sent events causing 2 tasks to spawn. Threads goes to 29 and CPU to 200%. Then I start up two more SSEs and threads goes to 35 and CPU to 400%. This can go on even further but my Mac starts sounding like a turbine engine at that point.

It's a fairly complex exe with lots of tasks, and tasks that block, but there's nothing special about the SSEs: several are spawned when a client first connects to the server. Haven't been able to glean as much about the state of the world using Apple's Instruments as I'd like, but memory is fine and there don't seem to be any functions or threads sucking up CPU.

This leads me to think that the problem might be lock contention. Or possibly #3095, but I very much doubt that my tasks are doing much of anything at all (and Instruments backs that up).

This was on an 8-core Mac with rust from Sep 22, 2012.

@jesse99
Copy link
Contributor Author

jesse99 commented Sep 25, 2012

I'd like to poke at this some more. In particular I was wondering why there were so many threads, though I may wait for #3584 to be fixed.

@brson
Copy link
Contributor

brson commented Sep 25, 2012

I would be interested in seeing the code.

@jesse99
Copy link
Contributor Author

jesse99 commented Sep 25, 2012

It's a fair amount of code but it's here and here. You can in theory build it and run it (use make run-db), but there are quite a few dependencies. However they should all be in cargo (except you need my forks of rust-mustache and rust-socket). If you do that then you should be able to repro the CPU spiking by clicking on the big discs in the browser window it spawns (rub-db isn't perfectly reliable because it kicks off a browser page and then starts the server: sometimes chrome gives up too quickly).

gnos commit 89f2d70b553d170b9d1ac5c10a8cefe336118c9e and rwebserve commit 49cabbf56bc34f9b9acfcc6da0c0c70b4292eba8 are the bad ones. I'm going to try and remove some calls to spawn_sched that aren't doing what I thought.

@jesse99
Copy link
Contributor Author

jesse99 commented Sep 25, 2012

Cleaned up the scheduling and it still spikes CPU.

@jesse99
Copy link
Contributor Author

jesse99 commented Oct 3, 2012

This turned out to be a bug on my end.

Not sure why Instruments.app didn't clue me in but I looked at the top results more closely and noticed BSD syscalls were crazy high (24 million). dtruss -p <pid> -s -c showed me exactly what was happening: my tcp read code was checking buffer length instead of bytes read length so when the peer closed down my task went into a tight loop constantly reading zero bytes.

@jesse99 jesse99 closed this as completed Oct 3, 2012
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

2 participants