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
|
||||
raddr Addr
|
||||
status string
|
||||
uids []int32
|
||||
pid int32
|
||||
boundPid int32
|
||||
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) {
|
||||
dupCheckMap := make(map[string]bool)
|
||||
dupCheckMap := make(map[connTmp]struct{})
|
||||
var ret []ConnectionStat
|
||||
|
||||
var err error
|
||||
|
@ -367,13 +366,16 @@ func statsFromInodes(root string, pid int32, tmap []netConnectionKindType, inode
|
|||
return nil, err
|
||||
}
|
||||
for _, c := range ls {
|
||||
if _, ok := dupCheckMap[c]; ok {
|
||||
continue
|
||||
}
|
||||
|
||||
conn := ConnectionStat{
|
||||
Fd: c.fd,
|
||||
Family: c.family,
|
||||
Type: c.sockType,
|
||||
Laddr: c.laddr,
|
||||
Raddr: c.raddr,
|
||||
Uids: c.uids,
|
||||
Status: c.status,
|
||||
Pid: c.pid,
|
||||
}
|
||||
|
@ -387,13 +389,8 @@ func statsFromInodes(root string, pid int32, tmap []netConnectionKindType, inode
|
|||
proc := process{Pid: conn.Pid}
|
||||
conn.Uids, _ = proc.getUids()
|
||||
|
||||
// check duplicate using JSON format
|
||||
json := conn.String()
|
||||
_, exists := dupCheckMap[json]
|
||||
if !exists {
|
||||
ret = append(ret, conn)
|
||||
dupCheckMap[json] = true
|
||||
}
|
||||
dupCheckMap[c] = struct{}{}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue