mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-02 17:50:39 +00:00
WithNode is a CPU hog.
This commit is contained in:
@@ -84,14 +84,14 @@ func demoReport(nodeCount int) report.Report {
|
||||
)
|
||||
|
||||
// Endpoint topology
|
||||
r.Endpoint = r.Endpoint.WithNode(srcPortID, report.MakeNode().WithMetadata(map[string]string{
|
||||
r.Endpoint = r.Endpoint.AddNode(srcPortID, report.MakeNode().WithMetadata(map[string]string{
|
||||
process.PID: "4000",
|
||||
"name": c.srcProc,
|
||||
"domain": "node-" + src,
|
||||
}).WithEdge(dstPortID, report.EdgeMetadata{
|
||||
MaxConnCountTCP: newu64(uint64(rand.Intn(100) + 10)),
|
||||
}))
|
||||
r.Endpoint = r.Endpoint.WithNode(dstPortID, report.MakeNode().WithMetadata(map[string]string{
|
||||
r.Endpoint = r.Endpoint.AddNode(dstPortID, report.MakeNode().WithMetadata(map[string]string{
|
||||
process.PID: "4000",
|
||||
"name": c.dstProc,
|
||||
"domain": "node-" + dst,
|
||||
@@ -100,15 +100,15 @@ func demoReport(nodeCount int) report.Report {
|
||||
}))
|
||||
|
||||
// Address topology
|
||||
r.Address = r.Address.WithNode(srcAddressID, report.MakeNode().WithMetadata(map[string]string{
|
||||
r.Address = r.Address.AddNode(srcAddressID, report.MakeNode().WithMetadata(map[string]string{
|
||||
docker.Name: src,
|
||||
}).WithAdjacent(dstAddressID))
|
||||
r.Address = r.Address.WithNode(srcAddressID, report.MakeNode().WithMetadata(map[string]string{
|
||||
r.Address = r.Address.AddNode(srcAddressID, report.MakeNode().WithMetadata(map[string]string{
|
||||
docker.Name: dst,
|
||||
}).WithAdjacent(srcAddressID))
|
||||
|
||||
// Host data
|
||||
r.Host = r.Host.WithNode("hostX", report.MakeNodeWith(map[string]string{
|
||||
r.Host = r.Host.AddNode("hostX", report.MakeNodeWith(map[string]string{
|
||||
"ts": time.Now().UTC().Format(time.RFC3339Nano),
|
||||
"host_name": "host-x",
|
||||
"local_networks": localNet.String(),
|
||||
|
||||
@@ -64,14 +64,14 @@ func DemoReport(nodeCount int) report.Report {
|
||||
)
|
||||
|
||||
// Endpoint topology
|
||||
r.Endpoint = r.Endpoint.WithNode(srcPortID, report.MakeNode().WithMetadata(map[string]string{
|
||||
r.Endpoint = r.Endpoint.AddNode(srcPortID, report.MakeNode().WithMetadata(map[string]string{
|
||||
"pid": "4000",
|
||||
"name": c.srcProc,
|
||||
"domain": "node-" + src,
|
||||
}).WithEdge(dstPortID, report.EdgeMetadata{
|
||||
MaxConnCountTCP: newu64(uint64(rand.Intn(100) + 10)),
|
||||
}))
|
||||
r.Endpoint = r.Endpoint.WithNode(dstPortID, report.MakeNode().WithMetadata(map[string]string{
|
||||
r.Endpoint = r.Endpoint.AddNode(dstPortID, report.MakeNode().WithMetadata(map[string]string{
|
||||
"pid": "4000",
|
||||
"name": c.dstProc,
|
||||
"domain": "node-" + dst,
|
||||
@@ -80,15 +80,15 @@ func DemoReport(nodeCount int) report.Report {
|
||||
}))
|
||||
|
||||
// Address topology
|
||||
r.Address = r.Address.WithNode(srcAddressID, report.MakeNode().WithMetadata(map[string]string{
|
||||
r.Address = r.Address.AddNode(srcAddressID, report.MakeNode().WithMetadata(map[string]string{
|
||||
"name": src,
|
||||
}).WithAdjacent(dstAddressID))
|
||||
r.Address = r.Address.WithNode(dstAddressID, report.MakeNode().WithMetadata(map[string]string{
|
||||
r.Address = r.Address.AddNode(dstAddressID, report.MakeNode().WithMetadata(map[string]string{
|
||||
"name": dst,
|
||||
}).WithAdjacent(srcAddressID))
|
||||
|
||||
// Host data
|
||||
r.Host = r.Host.WithNode("hostX", report.MakeNodeWith(map[string]string{
|
||||
r.Host = r.Host.AddNode("hostX", report.MakeNodeWith(map[string]string{
|
||||
"ts": time.Now().UTC().Format(time.RFC3339Nano),
|
||||
"host_name": "host-x",
|
||||
"local_networks": localNet.String(),
|
||||
|
||||
@@ -178,8 +178,8 @@ func (r *Reporter) addConnection(rpt *report.Report, localAddr, remoteAddr strin
|
||||
})
|
||||
}
|
||||
|
||||
rpt.Address = rpt.Address.WithNode(localAddressNodeID, localNode)
|
||||
rpt.Address = rpt.Address.WithNode(remoteAddressNodeID, remoteNode)
|
||||
rpt.Address = rpt.Address.AddNode(localAddressNodeID, localNode)
|
||||
rpt.Address = rpt.Address.AddNode(remoteAddressNodeID, remoteNode)
|
||||
}
|
||||
|
||||
// Update endpoint topology
|
||||
@@ -225,8 +225,8 @@ func (r *Reporter) addConnection(rpt *report.Report, localAddr, remoteAddr strin
|
||||
if extraRemoteNode != nil {
|
||||
remoteNode = remoteNode.Merge(*extraRemoteNode)
|
||||
}
|
||||
rpt.Endpoint = rpt.Endpoint.WithNode(localEndpointNodeID, localNode)
|
||||
rpt.Endpoint = rpt.Endpoint.WithNode(remoteEndpointNodeID, remoteNode)
|
||||
rpt.Endpoint = rpt.Endpoint.AddNode(localEndpointNodeID, localNode)
|
||||
rpt.Endpoint = rpt.Endpoint.AddNode(remoteEndpointNodeID, remoteNode)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -253,8 +253,8 @@ func (s *Sniffer) Merge(p Packet, rpt *report.Report) {
|
||||
}
|
||||
|
||||
addAdjacency := func(t report.Topology, srcNodeID, dstNodeID string) report.Topology {
|
||||
result := t.WithNode(srcNodeID, report.MakeNode().WithAdjacent(dstNodeID))
|
||||
result = result.WithNode(dstNodeID, report.MakeNode())
|
||||
result := t.AddNode(srcNodeID, report.MakeNode().WithAdjacent(dstNodeID))
|
||||
result = result.AddNode(dstNodeID, report.MakeNode())
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -20,16 +20,17 @@ func MakeTopology() Topology {
|
||||
}
|
||||
}
|
||||
|
||||
// WithNode produces a topology from t, with nmd added under key nodeID; if a
|
||||
// node already exists for this key, nmd is merged with that node. Note that a
|
||||
// fresh topology is returned.
|
||||
func (t Topology) WithNode(nodeID string, nmd Node) Topology {
|
||||
// AddNode adds node to the topology under key nodeID; if a
|
||||
// node already exists for this key, nmd is merged with that node.
|
||||
// The same topology is returned to enable chaining.
|
||||
// This method is different from all the other similar methods
|
||||
// in that it mutates the Topology, to solve issues of GC pressure.
|
||||
func (t Topology) AddNode(nodeID string, nmd Node) Topology {
|
||||
if existing, ok := t.Nodes[nodeID]; ok {
|
||||
nmd = nmd.Merge(existing)
|
||||
}
|
||||
result := t.Copy()
|
||||
result.Nodes[nodeID] = nmd
|
||||
return result
|
||||
t.Nodes[nodeID] = nmd
|
||||
return t
|
||||
}
|
||||
|
||||
// Copy returns a value copy of the Topology.
|
||||
|
||||
Reference in New Issue
Block a user