[Winpcap-users] Tips for a real-time (low latency) application?
pcap-ri at scientician.org
Fri Jun 16 02:00:25 GMT 2006
Gianluca Varenni <gianluca.varenni at cacetech.com> wrote:
> all the ideas that you propose can make sense. What's missing from your
> mail is the maximum latency that you want to achieve
Unfortunately, the best answer I can give is "it depends." :)
I'm currently trying to figure out what latency I am willing to accept. For now, I want to be able to *control* the latency between packet arrival and application processing (by trading off CPU, throughput, memory consumption, etc.).
> (which basically means "what is the purpose of your app?").
For my research I'm building a system of mostly-application-independent proxies that provide a layer of indirection between a sender and receiver. (Sorry for being so abstract -- I don't know if going into the gory details will be very useful.) Due to the system's architecture, the proxies will inevitably introduce a significant amount of latency. I'm trying to squish out as much of the latency as possible.
Based on my imperfect understanding of how WinPcap/libpcap works, I am concerned that the packet capture process will contribute a non-negligible amount of latency. I would love to know more about the internal workings of WinPcap to see if my concerns are well-founded. I am early enough in development that I have not yet tested how much latency each component introduces -- I just wanted to be aware of any potential problems before investing a lot of time in development.
> Have a nice day
> ----- Original Message -----
> From: "Richard Hansen" <pcap-ri at scientician.org>
> To: <winpcap-users at winpcap.org>
> Sent: Thursday, June 15, 2006 3:31 PM
> Subject: [Winpcap-users] Tips for a real-time (low latency) application?
>> Hi all,
>> I'm new to WinPcap/libpcap and have some questions on how to use WinPcap
>> for a low-latency app. I'm willing to sacrifice some throughput and CPU
>> usage to improve latency.
>> I can think of three ways to minimize latency, and I have a bunch of
>> questions related to them:
>> 1. Use pcap_setmintocopy() to improve real-time responsiveness. Is
>> there a practical limit to how low I can set this? Would it be bad to
>> set it to 0? Also, is there a libpcap equivalent to this?
>> 2. Make sure pcap_next() returns the instant a packet is available. I'm
>> somewhat confused about how to_ms affects how pcap_next() returns. Does
>> it return immediately if a packet is available? Or is it possible for
>> pcap_next() to wait up to to_ms even if a packet is immediately
>> available? Is this affected by pcap_setmintocopy()?
>> What I would like is a function that returns a packet immediately if
>> one is available, otherwise it will wait up to a specified amount of time
>> for a packet to arrive (and will return the instant a packet arrives).
>> And -- if at all possible -- I would like it to work on multiple
>> platforms (especially Linux and BSD). Is this possible? I am currently
>> setting pcap to non-blocking mode and doing a tight poll, but that pegs
>> the CPU.
>> 3. Mess with the kernel queue behavior. It would be nifty if the kernel
>> buffer was a head-drop FIFO queue that automatically dropped packets
>> older than a specified cutoff age. This way I wouldn't waste time
>> copying stale packets into userspace. Is this possible without messing
>> with the WinPcap source code? How does WinPcap's kernel buffer behave?
>> How does libpcap behave?
>> Any other suggestions for improving latency would be much appreciated.
>> Thank you!
More information about the Winpcap-users