Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

Randomise selection order for affine blocks. #102

Merged
merged 1 commit into from
Apr 29, 2016

Conversation

fasaxc
Copy link
Member

@fasaxc fasaxc commented Apr 4, 2016

I think this is what's needed to avoid contention when many hosts assign IPAM blocks concurrently. I'm just about to try it in a scale test, though...

@robbrockbank
Copy link
Contributor

Are you sure you want this to be random? If you have multiple clients on the same host attempting to allocate IP addresses for the first time you'll end up with multiple allocation blocks being assigned on the host.

Wouldn't it be better to use a hash of the host to provide a fix entry point into the CIDRs for a specific host?

@fasaxc
Copy link
Member Author

fasaxc commented Apr 5, 2016

Hadn't thought of that, good spot. I'll make that change and put it through its paces in my scale testing.

@fasaxc
Copy link
Member Author

fasaxc commented Apr 5, 2016

Seems to do the trick after I finally managed to get a working container image. I did spot that there's some pretty similar function in IpamClient.random_blocks() but my version avoids building up a huge list of blocks and shuffling them. Occurred to me that, for IPv6, enumerating the blocks might be a little time-consuming ;-) WDYT?

@fasaxc fasaxc force-pushed the smc-randomise-block-sel branch 2 times, most recently from a4c2694 to 775edb0 Compare April 11, 2016 10:27
@robbrockbank
Copy link
Contributor

Yeah I've always worried that the shuffling code will be the consuming. Wanna fix that up too? :-)

@fasaxc
Copy link
Member Author

fasaxc commented Apr 12, 2016

@robbrockbank OK, I've made that change. Means I can now use self._random_blocks in _new_affine_blocks too, which makes it DRYer.

"""Tries to allocate IPs from the explicitly-listed blocks.

:param list blocks: Blocks to allocate from (for example, the affine
blocks for a host).
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: formatting off on this line

@robbrockbank
Copy link
Contributor

Looks good to me. Couple of minor comments. Took me a while to get my head round the random blocks thing... not sure if because I'm slow, or whether it just needs some beefing up of the comments.

@fasaxc
Copy link
Member Author

fasaxc commented Apr 15, 2016

Added more comments, and the license for netaddr. Bit of a shame to have to pick up more license than code but I think that's necessary.

@robbrockbank
Copy link
Contributor

lol - wish you'd put that comment in there sooner - I had to get my maths head on... it's been a long time ;-)

Looks good. Need to resolve conflicts though, then we're good to go.

Avoids contention when many hosts assign blocks concurrently.

- Rework IPAMClient.random_blocks() to avoid collecting the whole list.
  Instead use _random_subnets_from_cidrs() to generate blocks form the
  list of CIDRs.
@fasaxc fasaxc force-pushed the smc-randomise-block-sel branch 2 times, most recently from 13685d0 to f0f9f33 Compare April 25, 2016 14:35
@robbrockbank robbrockbank merged commit 73dceb8 into projectcalico:master Apr 29, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants