4

Hopefully this question isn't too dumb. I'm wondering how expensive (system resource, and bandwidth wise) a ping is. If I have a small embedded linux device that has very limited ram, cpu, and bandwidth would it be bad to start a ping command and have it continue running for days?

I'm trying to figure out how to minimize the impact. Looking at the options for ping it looks like I can specify the size. Should I do that to make it smaller? Is there anything else I can do to make it smaller? I need it to run but I don't want it to have any negative impact on ram, cpu, or bandwidth (performance in any way).

In my testing I haven't observed any difference in ram or cpu with it running. I haven't tested network speed very thoroughly but I haven't noticed anything there either. Thoughts?

Falcon Momot
  • 25,244
  • 15
  • 63
  • 92
user548971
  • 259
  • 1
  • 3
  • 10
  • 1
    `ping command and have it continue running for days?` - Adjust the interval. Do you really need a response every second? Will every 15, or 60 seconds be adequate? What are you trying to test with constant ping? Would something like smokeping set to every 5 minutes give you better information? It sends a burst of 20 packets and graphs the delay of each reply. – Zoredache Aug 28 '13 at 22:16
  • That's a good idea. I might be able to have it only ping every 5 seconds or so. In this case smokeping would not help. Most of the time I'm expecting to not receive a response from the ping. In the event that I do I will be running a script. – user548971 Aug 28 '13 at 22:54
  • Are you trying to monitor network stability or performance? Instead of just a ping, try `mtr` and adjust the interval of its pings (also has the option to choose UDP datagrams or ICMP packets): http://www.bitwizard.nl/mtr/ – ChunkyBaconPlz Aug 28 '13 at 23:51
  • Actually, I'm not using it to monitor either. I'm using it to trigger an action on the embedded device. Essentially, I have a bunch of embedded devices that will be pinging a server. I will use iptable rules on the server to respond to the ping requests or not. If a the device receives a response it will run a script. If the ping timesout it will not run the script. So, the point is to provide a way of triggering a script on the device in close to real time in a way that is managed from the server. – user548971 Aug 29 '13 at 03:46

1 Answers1

9

The cost difference between processing a ping hardly varies at all across byte sizes. The bulk of the cost of responding to one is in the routing table lookup when the reply is sent, and in the various socket logic (which varies based on OS) used to listen for and recieve a packet. This is also negligible in virtually all cases.

The reason for the adjustable size of ICMP echo (ping) packets is so that you can determine network characteristics based on packet size (eg. to find the MTU).

Because most of the cost is in the protocol stack in the kernel, and the NIC operation and network drivers, there is probably plenty a developer or hardware designer could do to make it (and network operation in general) more efficient, but in the general case as a system administrator these present a fixed and negligible load.

Tangentially, many people like to throttle ICMP requests at firewalls to prevent a ping-based DoS attack (which is one of the least effective DoS attacks available).

Falcon Momot
  • 25,244
  • 15
  • 63
  • 92