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

[Carry 1534] Improve scalabiltiy of bridge network isolation rules #2117

Merged
merged 3 commits into from
Apr 2, 2018

Conversation

AkihiroSuda
Copy link
Member

Carry #1534


  • This reduces complexity from O(N^2) to O(2N)

Related to moby/moby#26435

Reported as example the time measurement for creating 50 bridge networks and for pruning them.
Also because of the removal of the loop in isolateNetwork(), the timing is drastically improved:

   CURRENT		  NEW
Creation of the 50th network:
real	0m3.035s	0m0.146s
user	0m0.004s	0m0.008s
sys	0m0.004s	0m0.000s

Creation of all 50 networks:
real	0m43.785s	0m6.931s
user	0m0.336s	0m0.324s
sys	0m0.084s	0m0.148s

Pruning of the 50 networks:
real	1m2.136s	0m7.342s
user	0m0.004s	0m0.000s
sys	0m0.008s	0m0.016s

- This reduces complexity from O(N^2) to O(2N)

Signed-off-by: Alessandro Boch <aboch@docker.com>
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
@AkihiroSuda
Copy link
Member Author

cc @aboch @selansen
cc @hisaharu

@codecov-io
Copy link

codecov-io commented Mar 19, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@1b91bc9). Click here to learn what that means.
The diff coverage is 54.68%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2117   +/-   ##
=========================================
  Coverage          ?   40.41%           
=========================================
  Files             ?      139           
  Lines             ?    22388           
  Branches          ?        0           
=========================================
  Hits              ?     9047           
  Misses            ?    12014           
  Partials          ?     1327
Impacted Files Coverage Δ
drivers/bridge/setup_ip_tables.go 57.78% <45.09%> (ø)
drivers/bridge/bridge.go 55.11% <92.3%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1b91bc9...9be4c10. Read the comment docs.

@thaJeztah
Copy link
Member

❤️ thanks!

ping @fcrisciani @ctelfer PTAL

Copy link
Contributor

@ctelfer ctelfer left a comment

Choose a reason for hiding this comment

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

Overall this seems like a sensible approach and the patch does a few thing cleaner than the original code. So far I only one thing that probably needs to change. (see other comment)

if err != nil {
return nil, nil, nil, fmt.Errorf("failed to create FILTER isolation chain: %v", err)
return nil, nil, nil, nil, fmt.Errorf("failed to create FILTER isolation chain: %v", err)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

If creating isolationChain2 fails, this code will not roll back the creation of isolationChain1. Please add a deferred cleanup function as above w/ the DockerChains for Filter and NAT. Also, although the original code didn't have a cleanup for isolationChain (now isolationChain1), please add one to gracefully handle failure to add the return rule2.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
Copy link

@fcrisciani fcrisciani left a comment

Choose a reason for hiding this comment

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

LGTM

@ctelfer
Copy link
Contributor

ctelfer commented Mar 26, 2018

Fixes to address my comments look good. Doing one more pass on a review. Thanks!

}
// Install the rules to isolate this network against each of the other networks
if err := setINC(thisConfig.BridgeName, enable); err != nil {
return err
}

return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Hrmm.. I didn't catch this the first time around, but when doing a quick build test locally, my machine flagged something that CI apparently didn't with golint. Maybe I have a different golint version.

drivers/bridge/bridge.go:316:2: redundant if ...; err != nil check, just return error instead.
Makefile:109: recipe for target 'lint' failed

It is right: it would be cleaner to change the last few lines to:

return setINC(thisConfig.BridgeName, enable)

It builds fine once that change is made. Sorry, for not catching this when requesting the error handling change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed @ctelfer , If there is an error anyway we are not printing any error messages inside the if case.

networks map[string]*bridgeNetwork
store datastore.DataStore
nlh *netlink.Handle
configNetwork sync.Mutex
sync.Mutex
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

What changed in the entire structure ? new change and old attributes looks same to me except "isolationChain1 , isolationChain2"

Copy link
Member

Choose a reason for hiding this comment

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

It's due to go's formatting; it will align all variables, and 1 and 2 make the left column one position wider. If you add ?w=1 to the GitHub URL you'll see the diff without whitespace changes; https://github.com/docker/libnetwork/pull/2117/files?w=1

@selansen
Copy link
Collaborator

LGTM

@selansen
Copy link
Collaborator

selansen commented Mar 26, 2018 via email

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
@AkihiroSuda
Copy link
Member Author

fixed lint issue, PTAL

@selansen
Copy link
Collaborator

selansen commented Apr 2, 2018

LGTM

Copy link
Contributor

@ctelfer ctelfer left a comment

Choose a reason for hiding this comment

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

LGTM Thanks!

Copy link

@fcrisciani fcrisciani left a comment

Choose a reason for hiding this comment

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

LGTM

@fcrisciani
Copy link

Thanks @AkihiroSuda

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.

7 participants