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 resources automatically to containers in a container app #856

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

isaacabraham
Copy link
Member

The changes in this PR are as follows:

  • Adds support for allocating resources to a container app and equally sharing across all containers.

I have read the contributing guidelines and have completed the following:

  • Tested my code end-to-end against a live Azure subscription.
  • Updated the documentation in the docs folder for the affected changes.
  • Written unit tests against the modified code that I have made.
  • Updated the release notes with a new entry for this PR.
  • Checked the coding standards outlined in the contributions guide and ensured my code adheres to them.

Below is a minimal example configuration that includes the new features, which can be used to deploy to Azure:

containerEnvironment {
    add_containers [
        containerApp {
            allocate_resources ResourceLevels.``CPUs = 1.75, RAM = 3.5`` // resources shared equally between containers.
            add_containers [
                container {
                    name "aspnetsample"
                    public_docker_image "mcr.microsoft.com/dotnet/samples" "aspnetapp"
                }
                container {
                    name "queuereaderapp"
                    public_docker_image "mcr.microsoft.com/azuredocs/containerapps-queuereader" null
                }
            ]
        }
    ]
}

Copy link
Collaborator

@ninjarobot ninjarobot left a comment

Choose a reason for hiding this comment

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

I think this is a move in the right direction, but we will probably need to come up with a way to define more strategies for balancing the allocation.

@@ -2129,6 +2129,27 @@ module ContainerApp =
| PublicImage (container, version) ->
let version = version |> Option.defaultValue "latest"
$"{container}:{version}"
type ContainerAppResourceLevel = ContainerAppResourceLevel of cores:float<VCores> * memory:float<Gb>
module ResourceLevels =
let ``CPUs = 0.25, RAM = 0.5`` = ContainerAppResourceLevel (0.25<VCores>, 0.5<Gb>)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is difficult syntax to use. An editor/IDE helps, but if that's not available or someone is unfamiliar with F#, the double backticks add complexity.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. I just don't know what to call these values otherwise! Any ideas?

let containers = 5.


let optimise containers (cores:float<VCores>, memory:float<Gb>) =
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think in most cases, this can't really be evenly distributed. We probably need some different strategies where containers are weighted to prioritize them or where some of the containers have a fixed size and any extra resources are allocated to certain containers that would need more elasticity.

Copy link
Collaborator

Choose a reason for hiding this comment

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

To clarify a bit - you might have some sidecars to handle things like logging that have low, fixed resource usage. And then an HTTP frontend might need more CPU, but low memory needs. And then maybe one or two containers that do most of the application logic and need all the rest of the capacity. Does that make sense? I think it's difficult to come up with a "one size fits all" solution and should design it around multiple user-defined strategies.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's true. One idea I had was either to set a percentage, or a simple T-Shirt size e.g. S/M/L, and distribute it that way. Once we get out of that world and into the world of more complex scenario, this is something that I suspect will then require manual creation - there are so many permutations.

Copy link
Member Author

@isaacabraham isaacabraham Dec 21, 2021

Choose a reason for hiding this comment

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

I'd also like to loop in @matthewcrews to see if he has any thoughts on this kind of problem (although might be overkill!). Ideally I really don't want to bring in any external library but it sounds like a kind of constraint solving problem:

  • We have x amount of CPU and y amount of RAM
  • We have 5 containers, C1-C5
  • C1 never needs more than a specific amount of CPU and RAM
  • C2 is CPU hungry
  • C3 needs more RAM
  • C4 and C5 should take up the remaining resources, although C5 is more important
  • All containers should have a minimum of resources that they must always have

Choose a reason for hiding this comment

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

I'd need to unpack this more but this is sounding like a straightforward allocation/assignment problem. I don't think you need to go full optimization model on this.

There are some known heuristics that should be able to do this for you and only take a few lines of F#. I'd be happy to jump on a call if you wanted to discuss this in more detail.

@ninjarobot
Copy link
Collaborator

@isaacabraham is it worth merging and shipping this one and iterating on it to come up with more allocation strategies?

@martinbryant
Copy link
Contributor

@isaacabraham attempted to merge master into this pull request. Need some input on the addition of EphemeralStorage the has been added to Builders.ContainerApp.fs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants