portlist: document, clean up, fix an open fd spike, optimize a bit
I noticed portlist when looking at some profiles and hadn't looked at the code much before. This is a first pass over it. It allocates a fair bit. More love remains, but this does a bit: name old time/op new time/op delta GetList-8 9.92ms ± 8% 9.64ms ±12% ~ (p=0.247 n=10+10) name old alloc/op new alloc/op delta GetList-8 931kB ± 0% 869kB ± 0% -6.70% (p=0.000 n=10+10) name old allocs/op new allocs/op delta GetList-8 4.59k ± 0% 3.69k ± 1% -19.71% (p=0.000 n=10+10) Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
6c3820e8c4
commit
120273d7f6
@@ -6,8 +6,10 @@
|
||||
|
||||
package portlist
|
||||
|
||||
import "time"
|
||||
|
||||
// We have to run netstat, which is a bit expensive, so don't do it too often.
|
||||
const POLL_SECONDS = 5
|
||||
const pollInterval = 5 * time.Second
|
||||
|
||||
func listPorts() (List, error) {
|
||||
return listPortsNetstat("-na")
|
||||
|
||||
Reference in New Issue
Block a user