Skip to content

Commit e5b49ef

Browse files
chicknsoupcakturk
authored andcommitted
Added socket type check
In some cases, where server is running with thousands of connections, looping through all the file descriptors takes times. I have tested on a server with 20k connections and it took around 1m30s to get all socket information. After adding !strings.HasPrefix(lname, "socket") to the loop the cost reduced significantly to around 25 seconds.
1 parent 297af0c commit e5b49ef

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

netstat/netstat_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func (p *procFd) iterFdDir() {
196196
for _, file := range fi {
197197
fd := path.Join(fddir, file.Name())
198198
lname, err := os.Readlink(fd)
199-
if err != nil {
199+
if err != nil || !strings.HasPrefix(lname, sockPrefix) {
200200
continue
201201
}
202202

0 commit comments

Comments
 (0)