c# - Why Thread.Sleep() is so CPU intensive? -
i have asp.net page pseduo code:
while (read) { response.outputstream.write(buffer, 0, buffer.length); response.flush(); }
any client requests page start download binary file. ok @ point clients had no limit in download speed changed above code this:
while (read) { response.outputstream.write(buffer, 0, buffer.length); response.flush(); thread.sleep(500); }
speed problem solved now, under test 100 concurrent clients connect 1 after (3 seconds lag between each new connection) cpu usage increases when number of clients increases , when there 70 ~ 80 concurrent clients cpu reaches 100% , new connection refused. numbers may different on other machines question why thread.sleep() cpu intensive , there way speed done client without cpu rising ?
i can @ iis level need more control inside of application.
just guess:
i don't think it's thread.sleep()
that's tying cpu - it's fact you're causing threads tied responding request long, , system needs spin new threads (and other resources) respond new requests since sleeping threads no longer available in thread pool.
Comments
Post a Comment