-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Make IP allocator lazy #272
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
Conversation
network.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be compacted to:
if ip, ok := <-alloc.queue; ok {|
Does it make sense to prioritize reusing addresses over allocating new ones? |
Absolutely, yes. |
|
Actually, no. It is better to allocate new addressed before using new ones. This friendly tip brought to you courtesy of the dotCloud ops team /cc On Sat, Mar 30, 2013 at 4:07 PM, Dominik Honnef [email protected]:
|
|
@shykes Cool, I wasn't sure if that was the case. 📝 |
|
If you allocate new addresses, however, you will slowly fill up the list of released IPs. In the case of an /8 network (see original issue), you will face continuously growing memory consumption for every VM you ran. I do acknowledge the problem of reusing IPs, but not reusing them at all but yet storing them (which this PR does), is not acceptable either. Options I can think of (not ops-approved, however) are starting to use old IPs once the list reaches a certain size, using them at random, or implementing a compact way of storing reusable IPs. |
|
Here's what I have in mind:
This way you only store as many IPs as you have allocated, regardless of And we have to implement this map anyway for the "real port" feature. On Sat, Mar 30, 2013 at 4:46 PM, Dominik Honnef [email protected]:
|
|
That sounds reasonable. Since you're referring to a "real port feature" that I'm not aware of I'll hold off implementing this since I don't know what kind of information you want in the map, or where the map is supposed to be managed. |
|
See issue #273 for details. I'm thinking a simple map[int]struct{} would be On Sat, Mar 30, 2013 at 4:59 PM, Dominik Honnef [email protected]:
|
|
The same goroutine which allocates IPs should probably also own access to On Sat, Mar 30, 2013 at 5:04 PM, Solomon Hykes
|
|
This should work as you intended. |
network.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this field should be exported. It will likely need a mutex if it's meant to be accessed by other goroutines.
|
There should be some tests that cover the allocation strategy. |
|
Done. I'm still not entirely sure about #273, but I'm sure someone else can make changes to the IP allocator as needed, based on this. |
|
Thanks @dominikh. Reviewing. |
|
Fwiw, you might want to consider renaming the populate method. I don't think it's quite fitting anymore, considering what it's doing now. |
|
@titanous Will do once he approves of the changes. I suppose I'll just force push the feature branch and GitHub will do the right thing? |
|
@dominikh Yep, the pull request will update when you force-push. |
|
I agree, populate is no longer adequate. I guess Allocate() would work On Sun, Mar 31, 2013 at 12:08 PM, Dominik Honnef
|
|
@dominikh sorry I need to go afk for a few more hours, but so far this looks like really good work. Thanks again. |
|
I was thinking of something like |
|
Or rather unexported versions of those. |
|
Agreed On Sunday, March 31, 2013, Dominik Honnef wrote:
|
|
Looks good! Let me know when you're ready for me to merge. |
Instead of allocating all possible IPs in advance, generate them as needed. A loop will cycle through all possible IPs in sequential order, allocating them as needed and marking them as in use. Once the loop exhausts all IPs, it will wrap back to the beginning. IPs that are already in use will be skipped. When an IP is released, it will be cleared and be available for allocation again. Two decisions went into this design: 1) Minimize memory footprint by only allocating IPs that are actually in use 2) Minimize reuse of released IP addresses to avoid sending traffic to the wrong containers As a side effect, the functions for IP/Mask<->int conversion have been rewritten to never be able to fail in order to reduce the amount of error returns. Fixes gh-231
Add support for --network=netns:/proc/pid/ns/net
…twork [19.03 backport] Re-align proxy commit with libnetwork vendor
…aster-9c83848fc95a200c0c69a34cdeeb1f18a090c13a [master] sync to upstream master 9c83848
Instead of allocating all possible IPs in advance, generate them as
needed. Released IPs will not be fed back to the channel but stored in
a linked list. Said linked list will be used once the initial
generator exhausted all possible IPs.
In the worst case (VMs using up the entire /8 space, then releasing
the entire /8 space), memory usage will be slightly higher than
before (overhead of the list). In the usual case (an equal amount of
VMs acquiring and releasing IPs), memory usage will be relatively
constant. In both cases, IPs that have never been acquired will not
occupy memory.
Due to required API changes (the IP allocator runs in a goroutine now
and thus cannot easily return errors), the functions that are
responsible for IP/Mask<->int conversions have been rewritten to be
error-free.
Fixes gh-231