LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 05-23-2004, 07:15 PM   #1
pingswept
Member
 
Registered: May 2003
Location: Cambridge, MA
Distribution: SuSE, RedHat, and OpenBSD
Posts: 116

Rep: Reputation: 15
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.
 
Old 05-24-2004, 02:33 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
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.
 
Old 05-25-2004, 03:03 AM   #3
pingswept
Member
 
Registered: May 2003
Location: Cambridge, MA
Distribution: SuSE, RedHat, and OpenBSD
Posts: 116

Original Poster
Rep: Reputation: 15
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.
 
Old 05-25-2004, 03:18 AM   #4
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
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()?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does a multithreaded program gets hanged at recvfrom()? kranti Programming 1 10-17-2005 10:44 AM
Why does a multithreaded program gets hanged at recvfrom()? kranti Linux - Newbie 1 10-17-2005 04:40 AM
Why does a multithreaded program gets hanged at recvfrom()? kranti Linux - General 1 10-17-2005 04:09 AM
problem with recvfrom() in linux kernel .4.21-15.EL?? nkshirsagar Red Hat 0 06-27-2005 09:59 AM
Problem in recvfrom() live_dont_exist Programming 5 05-08-2005 04:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration