Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
05-23-2004, 07:15 PM
|
#1
|
Member
Registered: May 2003
Location: Cambridge, MA
Distribution: SuSE, RedHat, and OpenBSD
Posts: 116
Rep:
|
recvfrom() takes 20 ms to return?
I'm writing a server which uses recvfrom() to read UDP packets. Each call to recvfrom() takes 20 ms to execute, even though I can ping the same interface and get a response in less than 1 ms.
The packets I am receiving frequently have bad checksums-- I suspect this may be what is causing the delay.
On to the question: how can I speed up recvfrom(), or at least disable checksumming to see if that makes a difference?
I'm writing in C on OpenBSD 3.4. I could also try it on Linux if it would make a difference.
|
|
|
05-24-2004, 02:33 PM
|
#2
|
Moderator
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696
|
From 'man recvfrom':
Quote:
If no messages are available at the socket, the receive calls wait for
a message to arrive, unless the socket is nonblocking (see fcntl(2)) in
which case the value -1 is returned and the external variable errno set
to EAGAIN.
|
I'd make it nonblocking and see what's the result. But if there are many packets comming you may come to scalability problems as shown in this test: http://bulk.fefe.de/scalability/. If you don't have all patches installed, do it.
|
|
|
05-25-2004, 03:03 AM
|
#3
|
Member
Registered: May 2003
Location: Cambridge, MA
Distribution: SuSE, RedHat, and OpenBSD
Posts: 116
Original Poster
Rep:
|
Unfortunately, I already have the socket set to non-blocking.
From the graphs you linked to, it looks like OpenBSD doesn't do so well with socket() or bind(), but I'm not sure how that relates to recvfrom().
I still have the suspicion that some error is occurring, followed by a 20 ms timeout.
In any case, I tried rewriting the server using libpcap, and it is faster. The latency is all over the map, but on average its 5 times faster than recvfrom(). Weird.
|
|
|
05-25-2004, 03:18 AM
|
#4
|
Senior Member
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246
Rep:
|
Do you have a loop with select() in it then? Maybe with a 20ms timeout? Maybe you don't have all the descriptors that you need added to FDSET. Or maybe your first arg to select() isn't correct (should be the highest descriptor +1).
Are you sure it's spending that entire 20ms inside recvfrom()?
|
|
|
All times are GMT -5. The time now is 01:10 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|