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

Allocate docker limits based on server size. #6879

Merged
merged 5 commits into from Apr 14, 2020
Merged

Conversation

ericholscher
Copy link
Member

@ericholscher ericholscher commented Apr 8, 2020

This assumes 1-builder per server.
It is still able to be overwritten by settings,
so to have this take effect we need to set:

DOCKER_LIMITS = None

This assumes 1-builder per server.
It is still able to be overwritten by settings,
so to have this take effect we need to set:

```
DOCKER_LIMITS = None
```
@ericholscher ericholscher requested a review from Apr 8, 2020
# Set docker limits dynamically based on system memory
# This assumes 1-builder per server
try:
total_memory = int(subprocess.check_output("free -m | awk '/^Mem:/{print $2}'", shell=True))
Copy link
Member Author

@ericholscher ericholscher Apr 8, 2020

Choose a reason for hiding this comment

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

We could use psutil here: https://pypi.org/project/psutil/ -- but it would add a dependency. Not sure the tradeoff.

Copy link
Contributor

@agjohnson agjohnson Apr 13, 2020

Choose a reason for hiding this comment

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

I'd worry a little about this call failing for some reason, then falling through to the except because it's a generic Exception, and then we could be in a place where we are setting the default amount on servers without noticing.

psutil might give us more confidence in this check, or the except should be much tighter. The failure case is likely MacOS doing something different, or MacOS free/awk doing something different than Linux free/gnu awk, so we could also put this default set operation in a if DEBUG inside a @property setting. We likely never want to settle on the defaults in prod

Copy link
Contributor

@davidfischer davidfischer left a comment

From a code correctness standpoint, I verified that this works. It will fall back to defaults on Mac/Windows as they typically don't have these commands.

So this leaves 1GB of memory to the rest of the system and the rest of the builder code and allocates the rest to the docker builders?

Copy link
Member

@humitos humitos left a comment

Wouldn't be better to have these dynamic limits in our -ops repo?

@humitos
Copy link
Member

@humitos humitos commented Apr 9, 2020

DOCKER_LIMITS = None

Will need to be set to {} because we are doing and .update finally at this line,

https://github.com/readthedocs/readthedocs.org/pull/6879/files#diff-3fbfb50cb375355069e83003f500d2c8R63

@ericholscher
Copy link
Member Author

@ericholscher ericholscher commented Apr 9, 2020

Wouldn't be better to have these dynamic limits in our -ops repo?

Why? It seems useful for anyone running RTD.

@humitos
Copy link
Member

@humitos humitos commented Apr 9, 2020

Why? It seems useful for anyone running RTD.

Just asking because we are changing the default from 200m to be ~75% of the total memory in the computer. Only that.

Copy link
Contributor

@agjohnson agjohnson left a comment

This logic might fit better inside a settings property method inside global level in constants

# Set docker limits dynamically based on system memory
# This assumes 1-builder per server
try:
total_memory = int(subprocess.check_output("free -m | awk '/^Mem:/{print $2}'", shell=True))
Copy link
Contributor

@agjohnson agjohnson Apr 13, 2020

Choose a reason for hiding this comment

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

I'd worry a little about this call failing for some reason, then falling through to the except because it's a generic Exception, and then we could be in a place where we are setting the default amount on servers without noticing.

psutil might give us more confidence in this check, or the except should be much tighter. The failure case is likely MacOS doing something different, or MacOS free/awk doing something different than Linux free/gnu awk, so we could also put this default set operation in a if DEBUG inside a @property setting. We likely never want to settle on the defaults in prod

@ericholscher
Copy link
Member Author

@ericholscher ericholscher commented Apr 13, 2020

This logic might fit better inside a settings property method inside global level in constants

Yea, I just wanted to allow users to override it still with a setting if needed. We could have two settings for this, but that just seems confusing?

@ericholscher
Copy link
Member Author

@ericholscher ericholscher commented Apr 14, 2020

I will merge this now, and see how it goes in prod. We can always adjust, but I'd like to test building one deploy builder image today.

@ericholscher ericholscher merged commit 5d8a969 into master Apr 14, 2020
2 checks passed
@ericholscher ericholscher deleted the dynamic-build-queue branch Apr 14, 2020
humitos added a commit that referenced this issue Apr 28, 2020
We are settings this limits dynamically in #6879
@humitos humitos mentioned this pull request Apr 28, 2020
agjohnson pushed a commit that referenced this issue Apr 28, 2020
We are settings this limits dynamically in #6879
agjohnson pushed a commit that referenced this issue May 5, 2020
We are settings this limits dynamically in #6879
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.

None yet

4 participants