# too many sockets in use



## Lem0nHead (May 27, 2010)

hello
I started to get some ENOBUFS errors.


```
# vmstat -z | grep socket
socket:                   356,    12331,    12292,       39, 274334042,   112064

# netstat -n | wc -l
     621
```

any ideas on how to find out which process is using so many sockets?

thanks


----------



## SirDice (May 27, 2010)

You're probably looking for sockstat(1).


----------



## Lem0nHead (May 27, 2010)

now much different


```
# sockstat | wc -l
     511
```


----------



## SirDice (May 27, 2010)

You wanted to find out which process is using a lot of sockets? Then read the output, not pipe it through wc. 
The difference in numbers is because sockstat also shows file sockets.


----------



## Lem0nHead (May 27, 2010)

but, I mean, "socket" count is up to 12000+

from the look I gave on sockstat output, it's pretty ordinary (a few services using around 50~200 sockets), but nothing close to 1000+


----------



## SirDice (May 27, 2010)

Oh wait. Vmstat doesn't show the _number_ of sockets in use. It shows the amount of socket memory (buffers) in use.


----------



## SirDice (May 27, 2010)

And your solution is probably this:

http://www.mavetju.org/mail/view_message.php?list=freebsd-questions&id=807288


----------



## Lem0nHead (May 27, 2010)

SirDice said:
			
		

> Oh wait. Vmstat doesn't show the _number_ of sockets in use. It shows the amount of socket memory (buffers) in use.



oh, that makes some sense
the problem stopped after I raised maxsockets

but what I don't get is, on another server:


```
# sockstat | wc -l
     486

# vmstat -z | grep socket
socket:                   416,    25605,      613,     3032, 201205440,        0
```

so, almost the same number of sockets on sockstat (486), but WAY less buffers in use (613 vs 12000)

any ideas on what may cause that?
maybe multiple quick connections/disconnections in a time less than enough to clean the buffers?


----------



## SirDice (May 27, 2010)

I'm definitely not versed enough in socket programming but I think those buffers are used for all sorts of socket data.


----------

