2

I am facing some issues with my Application, and am curious to know the network buffer usage at any given moment.

I am using a CentOS 6 linux Machine.

I know the Default values are present in /proc/sys/net/core/

But i have not been successful in finding the current usage of the Buffers. If any one has any clue on how to find the current usage, please let me know.

Thanks in advance.

Vijit Jain
  • 86
  • 3
  • 15

2 Answers2

3

If you run ss or netstat the values Recv-Q and Send-Q produce this output.

I.E

$ ss -nt
State      Recv-Q Send-Q        Local Address:Port          Peer Address:Port 
ESTAB      203    0               192.168.1.2:36122       198.xxx.xxx.xxx:80    
CLOSE-WAIT 1      0               192.168.1.2:43870       140.xxx.xxx.xxx:80    

I have added a simple python program to demonstrate this.

#/usr/bin/python
from time import sleep
from socket import *
import subprocess

if __name__ == "__main__":
  sock = socket(AF_INET, SOCK_STREAM)
  sock.setsockopt(IPPROTO_TCP, TCP_CORK, 1)
  sock.connect(('www.google.com', 80))
  length = sock.send("GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n")
  sport = sock.getsockname()[1]
  print "Length of sent data: {0}".format(length)
  subprocess.call(["ss" ,"-nt", "sport", "=", ":{0}".format(sport)])
  sock.close()

Which produces

Length of sent data: 40
State      Recv-Q Send-Q        Local Address:Port          Peer Address:Port 
ESTAB      0      40              192.168.1.2:34259       173.194.41.180:80    
Matthew Ife
  • 23,357
  • 3
  • 55
  • 72
  • Thank you. The Script is very useful. Just curious, the value in your example is 203, for Recv-Q, that is, 203 bytes?. Also, its for a given moment, is it possible to use something to update the value as it changes?, like we do with `tail -f`? – Vijit Jain Feb 20 '14 at 20:28
  • well, the first example is just me running `ss`. Not part of the script. In theory you can get the value as it changes in your process thats doing the sockets by using and edge triggered `epoll` on the socket and then using the `FIONREAD` request as an `ioctl` on the socket. There is no mechanisms I am aware to do the same in an unrelated process, without the child having been passed or inherited the file descriptor from the process doing the work. – Matthew Ife Feb 20 '14 at 20:38
  • Thank you Matthew, this should help me reach close to my target. Cheers :) – Vijit Jain Feb 20 '14 at 20:44
1

Off the top of my head, try ss -m - should print socket queue sizes, passing the output through grep/cut/awk should sum these up.

Deer Hunter
  • 1,070
  • 7
  • 17
  • 25
  • Thank you, your answer was correct as well. But, i chose Matthew's answer as it was more detailed. Cheers :) – Vijit Jain Feb 20 '14 at 20:30
  • @VijitJain : another bit of information is here: http://unix.stackexchange.com/questions/30509/what-is-the-formula-to-determine-how-much-memory-a-socket-consumes-under-linux – Deer Hunter Feb 20 '14 at 20:35