Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite more Map-Reduces as Renderers to save garbage #2938

Merged
merged 4 commits into from
Nov 22, 2017
Merged

Conversation

bboreham
Copy link
Collaborator

MapX2Host and to a lesser extent MapProcess2Name have the property that they map many nodes onto fewer nodes, so looping and using the machinery in joinResults is more effective than creating many copies of the same node and merging.

Benchmarks before (c5bdebd):

BenchmarkTopologyList-2         	       2	 603197223 ns/op	112161732 B/op	 1253503 allocs/op
BenchmarkTopologyHosts-2        	       3	 385415232 ns/op	82957173 B/op	 1015204 allocs/op
BenchmarkTopologyContainers-2   	      10	 192766565 ns/op	33145659 B/op	  407698 allocs/op

after this PR:

BenchmarkTopologyList-2         	       3	 476705872 ns/op	101366640 B/op	 1109042 allocs/op
BenchmarkTopologyHosts-2        	       3	 373288182 ns/op	76540733 B/op	  933301 allocs/op
BenchmarkTopologyContainers-2   	      10	 183615683 ns/op	33132417 B/op	  407672 allocs/op

@bboreham bboreham changed the title Rewrite more Map-rReduces as Renderers to save garbage Rewrite more Map-Reduces as Renderers to save garbage Nov 14, 2017
render/render.go Outdated
// is only ever called when m is an endpoint and we never look at endpoint counts
func (ret *joinResults) addToResults(m report.Node, id string, create func(string) report.Node) {
// incrementing a counter if nonblank, and updating the mapping from old ID to new ID
func (ret *joinResults) addToResults(m report.Node, id string, addChildren bool, create func(string) report.Node, counters ...string) {

This comment was marked as abuse.

Copy link
Member

@rade rade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite lovely. Just a few cosmetic issues to sort out.

render/host.go Outdated
for _, n := range nodes.Nodes {
if n.Topology == Pseudo {
continue // Don't propagate pseudo nodes - we do this in MapEndpoint2Host
} else {

This comment was marked as abuse.

ProcessRenderer,
),
)
var ProcessNameRenderer = CustomRenderer{Renderer: ProcessRenderer, RenderFunc: processes2Names}

This comment was marked as abuse.

@rade
Copy link
Member

rade commented Nov 22, 2017

With more-renderers-b I am seeing a similar improvements in allocations as above, but no improvements in runtime:

master

BenchmarkTopologyList-4         	       2	 634468221 ns/op	107948256 B/op	 1056511 allocs/op
BenchmarkTopologyHosts-4        	       2	 553097064 ns/op	78231540 B/op	  812637 allocs/op
BenchmarkTopologyContainers-4   	       5	 235253550 ns/op	30075289 B/op	  302554 allocs/op

branch

BenchmarkTopologyList-4         	       2	 638986932 ns/op	97484960 B/op	  915473 allocs/op
BenchmarkTopologyHosts-4        	       2	 545031910 ns/op	71767348 B/op	  730887 allocs/op
BenchmarkTopologyContainers-4   	       5	 225194107 ns/op	30069329 B/op	  302520 allocs/op

(each line is the best result of three runs)

rade and others added 2 commits November 22, 2017 10:30
This is preparatory to future refactorings: all existing calls are to
Endpoints which have no children and where we don't want a Counter.

We make addChildAndChildren an obvious extension of addChild even
though it adds a dead code path (we never call addChildAndChildren
with an endpoint).
This is more efficient as there are typically many fewer names than
processes.
bboreham and others added 2 commits November 22, 2017 10:39
It's more efficient as many input Nodes map onto a few hosts.
@rade
Copy link
Member

rade commented Nov 22, 2017

I've re-run the benchmarks with cpu=1, and now I do see a >5% runtime improvement in BenchmarkTopologyList.

@bboreham bboreham merged commit 3bc8f22 into master Nov 22, 2017
@rade rade deleted the more-renderers branch December 25, 2017 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants