Sign in to follow this  
Bow_vernon

slow accept??

Recommended Posts

I made a server program with non blocking socket, and it seems that the accepting process is slow...although it's not blocking, but it doesnt give error...can anyone explain this??oh and I select() then if there's pending connection, I accept()

Share this post


Link to post
Share on other sites
well, I log every events in the app, and I run server and client at the same pc..and it seems that they're sharing CPU time, so maybe it's caused by CPU scheduling...but Id like a good explanation from others..google doesnt help.and I cant post the code now...

Share this post


Link to post
Share on other sites
Bow_vernon: Rip-off actually made a good suggestion. I second it.

* Can you reduce your problem to the smallest possible case?
* Create two programs that each are 20 lines long, and show the problem?
* Alternatively, if you log the time stamps, can you copy and paste the bits of the log that show that there's actually a problem, so we can see what you mean?
* Is slow one millisecond? ten milliseconds? one second? ten seconds?
* Also, seeing the lines surrounding your calls to send, recv, select and accept would be useful, but not hundreds of lines of code.

I recommend you go through this simple method of analysis before you post, so that it's at least minimally possible for people outside your room to understand what the problem really can be.

In general, a network program should not be CPU bound (it should be sleeping when there are no events), and a graphics program should not be CPU bound (it should be fill rate bound, at the limit). You can open the CPU meter of your OS, and check if any CPU is running pegged. If so, you're probably busy-polling in some loop. If you have more busy loops than CPU cores in your system, you will end up with pre-emptive scheduling, which will rotate through the different threads/processes at a time slice that varies by OS, but is generally on the order of hundreds of milliseconds.

Btw: I often end up thinking I don't know the solution to a problem. Then I'll post to some internet forum. Then, as part of writing the post, where I try to thoroughly explain the entire problem to the others in the forum, I find that I walk through the problem step by step, describing "well, it's not X, because I checked Y, ..." and, before I'm done posting to the forum, I've actually solved the problem myself. Just the process of formulating all the symptoms you are seeing, and then walking through "it could be X, because I don't think so because of Y" for each is a very helpful methodology.

Share this post


Link to post
Share on other sites
sorry, hplus, you made me feel guilty :p. but I think you're right, I call sleep(0) at the end of the server main loop, and the problem's gone. anyway, I guess it was slow because the client ate the CPU. I tested the server with telnet and it's accepting damn fast.I learnt a lot from ths stupidity..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this