cakturk / go-netstat

A netstat implementation written in Go
MIT License
237 stars 67 forks source link

Added socket type check #8

Closed chicknsoup closed 4 years ago

chicknsoup commented 5 years ago

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.Contains(lname, "socket") to the loop the cost reduced significantly to around 25 seconds.

cakturk commented 4 years ago

Cannot build. You accidentally put an extra opening brace in the if block. Also, how about using strings.HasPrefix instead of doing a substring match with strings.Contains? Can you update your changes this way?

if !strings.HasPrefix(lname, sockPrefix) {
        continue
}
chicknsoup commented 4 years ago

Sure, i'll update it.