Fast duplication check in inodes processing.
Instead of encoding a JSON string of each connection (non-trivial at high connection volumes) we can use the connTmp struct for map look-ups if we eliminate the unused `uids` field. Also switches to using the empty struct instead of bool for zero memory overhead.
This commit is contained in:
parent
42156fdf0d
commit
276c873f0d
|
@ -281,7 +281,6 @@ type connTmp struct {
|
||||||
laddr Addr
|
laddr Addr
|
||||||
raddr Addr
|
raddr Addr
|
||||||
status string
|
status string
|
||||||
uids []int32
|
|
||||||
pid int32
|
pid int32
|
||||||
boundPid int32
|
boundPid int32
|
||||||
path string
|
path string
|
||||||
|
@ -347,7 +346,7 @@ func ConnectionsPidMax(kind string, pid int32, max int) ([]ConnectionStat, error
|
||||||
}
|
}
|
||||||
|
|
||||||
func statsFromInodes(root string, pid int32, tmap []netConnectionKindType, inodes map[string][]inodeMap) ([]ConnectionStat, error) {
|
func statsFromInodes(root string, pid int32, tmap []netConnectionKindType, inodes map[string][]inodeMap) ([]ConnectionStat, error) {
|
||||||
dupCheckMap := make(map[string]bool)
|
dupCheckMap := make(map[connTmp]struct{})
|
||||||
var ret []ConnectionStat
|
var ret []ConnectionStat
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
@ -367,13 +366,16 @@ func statsFromInodes(root string, pid int32, tmap []netConnectionKindType, inode
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, c := range ls {
|
for _, c := range ls {
|
||||||
|
if _, ok := dupCheckMap[c]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
conn := ConnectionStat{
|
conn := ConnectionStat{
|
||||||
Fd: c.fd,
|
Fd: c.fd,
|
||||||
Family: c.family,
|
Family: c.family,
|
||||||
Type: c.sockType,
|
Type: c.sockType,
|
||||||
Laddr: c.laddr,
|
Laddr: c.laddr,
|
||||||
Raddr: c.raddr,
|
Raddr: c.raddr,
|
||||||
Uids: c.uids,
|
|
||||||
Status: c.status,
|
Status: c.status,
|
||||||
Pid: c.pid,
|
Pid: c.pid,
|
||||||
}
|
}
|
||||||
|
@ -387,13 +389,8 @@ func statsFromInodes(root string, pid int32, tmap []netConnectionKindType, inode
|
||||||
proc := process{Pid: conn.Pid}
|
proc := process{Pid: conn.Pid}
|
||||||
conn.Uids, _ = proc.getUids()
|
conn.Uids, _ = proc.getUids()
|
||||||
|
|
||||||
// check duplicate using JSON format
|
ret = append(ret, conn)
|
||||||
json := conn.String()
|
dupCheckMap[c] = struct{}{}
|
||||||
_, exists := dupCheckMap[json]
|
|
||||||
if !exists {
|
|
||||||
ret = append(ret, conn)
|
|
||||||
dupCheckMap[json] = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue