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

[Proposal] POEM: Providing action limits for each namespace #5236

Merged
merged 3 commits into from
May 25, 2022

Conversation

upgle
Copy link
Member

@upgle upgle commented May 16, 2022

Description

This is the POEM documentation for new feature providing action limits for each namespace.
I refer to this guide document for POEM: https://github.com/apache/openwhisk/blob/master/proposals/README.md

Related issue and scope

  • I opened an issue to propose and discuss this change (#????)

My changes affect the following components

  • Documentation

Types of changes

  • Enhancement or new feature (adds new functionality).

Checklist:

  • I signed an Apache CLA.
  • I reviewed the style guides and followed the recommendations (Travis CI will check :).
  • I added tests to cover my changes.
  • My changes require further changes to the documentation.
  • I updated the documentation where necessary.

Title

Providing action limits for each namespace

Status

  • Current state: In-progress
  • Author(s): @upgle

Summary and Motivation

This POEM proposes a new feature that allows administrators to set action limits (memory, timeout, log, and concurrency) for each namespace.

Sometimes some users want to make an action with more memory and longer duration. But, Openwhisk only has a system limit for action shared by all namespaces.
There is no way to adjust the action limit for a few users, and changing the action limit setting will affect all users.

In some private environments, you can operate Openwhisk more flexibly by providing different action limits.
(For example, providing high memory only to some users.)

          256M                               512M

            │     namespace default limit      │
            ▼                                  ▼
 ┌──────────┬──────────────────────────────────┬────────────┬────────────────────────┐
 │          │┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼│----------► │                        │
 └──────────┴──────────────────────────────────┴────────────┴────────────────────────┘
 ▲                                                          ▲                        ▲
 │ system limit                                             │ namespace limit        │ system limit

128M                                                      1024M                    2048M

Proposed changes

3 types of action limits

There was only a system limit shared by all namespaces, but two more concepts for namespace limits are added.

  • (1) system limit: It can never be exceeded under any circumstances.
  • (2) namespace default limit: It can be used if a limit has not been set for a namespace.
  • (3) namespace limit: It can be set by a system administrator for a namespace and cannot exceed the range of the system limit.

Limit configs for namespace

  • The maxParameterSize, maxPayloadSize and truncationSize values are treated as ByteSize string. (e.g. 1 MB, 512 KB...)

The following settings are new:

config key Type description
minActionMemory integer (unit: MB) minimum action memory size for namespace
maxActionMemory integer (unit: MB) maximum action memory size for namespace
minActionLogs integer (unit: MB) minimum activation log size for namespace
maxActionLogs integer (unit: MB) maximum activation log size for namespace
minActionTimeout integer (unit: milliseconds) minimum action time limit for namespace
maxActionTimeout integer (unit: milliseconds) maximum action time limit for namespace
minActionConcurrency integer minimum action concurrency limit for namespace
maxActionConcurrency integer maximum action concurrency limit for namespace
maxParameterSize string (format: ByteSize) maximum parameter size for namespace
maxPayloadSize string (format: ByteSize) maximum payload size for namespace
truncationSize string (format: ByteSize) activation truncation size for namespace

Limit document for CouchDB

You can set namespace limits with {namespace}/limits document just like any other existing settings (invocationsPerMinute, concurrentInvocations..).

{
  "concurrentInvocations": 100,
  "invocationsPerMinute": 100,
  "firesPerMinute": 100,
  "maxActionMemory": 1024,
  "minActionMemory": 128,
  "maxActionConcurrency": 400,
  "minActionConcurrency": 1,
  "maxActionLogs": 128,
  "minActionLogs": 0,
  "maxParameterSize": "1048576 B"
}

Using wskadmin command (tool)

  • In general, it is recommended to use a wskadmin rather than modify the DB directly.
  • There is plan to provide the feauture to change namespace limits in wskadmin.

Namespace Limit API

User can get the applied action limits of the namespace by the namespace limit API.
If the namespace's action limit is not set, the default namespace limit value will be returned.

GET /api/v1/namespaces/_/limits

{
  "concurrentInvocations": 30,
  "firesPerMinute": 60,
  "invocationsPerMinute": 60,
  "maxActionConcurrency": 500,
  "maxActionLogs": 0,
  "maxActionMemory": 512,
  "maxActionTimeout": 300000,
  "maxParameterSize": "1048576 B",
  "minActionConcurrency": 1,
  "minActionLogs": 0,
  "minActionMemory": 128,
  "minActionTimeout": 100
}

System API (URI path: /)

A namespace default limit information is additionally provided separately from the previously provided system limit information.

  • default_max_action_duration
  • default_max_action_logs
  • default_max_action_memory
  • default_min_action_duration
  • default_min_action_logs
  • default_min_action_memory

Preview

GET /

{
  "api_paths": [
    "/api/v1"
  ],
  "description": "OpenWhisk",
  "limits" : {
    "actions_per_minute": 60,
    "concurrent_actions": 30,
    "default_max_action_duration": 300000,
    "default_max_action_logs": 0,
    "default_max_action_memory": 536870912,
    "default_min_action_duration": 100,
    "default_min_action_logs": 0,
    "default_min_action_memory": 134217728,
    "max_action_duration": 300000,
    "max_action_logs": 0,
    "max_action_memory": 536870912,
    "min_action_duration": 100,
    "min_action_logs": 0,
    "min_action_memory": 134217728,
    "sequence_length": 50,
    "triggers_per_minute": 60
  }
}

Backward compatibility

For backward compatibility, if there is no namespace default limit setting, it is replaced with a system limit.

As the namespace default limit is the same as the system limit, so the administrator cannot set the namespace limit, and the user can create actions with resources (memory, logs, timeout...) up to the system limit as before.

Namespace limit validation

Previously, system limits were validated when unmarshalls the ActionLimits object from the user request.

However, at the time of unmarshalls the user requests, the namespace's action limit cannot be known and the limit value cannot be included in an error message, so the validation must be performed after unmarshalling.
Therefore, the code to perform this validation has been added to the controller, scheduler, and invoker.

1. Validate action limits when the action is created in the controller

When an action is created in the controller, make sure that the action limits do not exceed the system limits and namespace limits.

If the namespace limits or system limits are exceeded, the namespace limit value must be returned as an error message in the response body.

                                                 ┌───────────────┐
                                                 │               │
                                                 │   AuthStore   │
                                                 │               │
                                                 └───────┬───────┘
                                                         │
                                                 ┌───────┴───────┐
                                                 │               │
                                                 │   Identity    │ UserLimits
                                                 │               │ (maxActionMemory = 512M)
  Create action     ┌───────────────────┐        └───────────────┘
 (memory = 1024M)   │                   │                ▲
──────────────────► │                   │                │
                    │    Controller     ├────────────────┘
◄────────X───────── │                   │   Validate namespace limit
   Reject request   │                   │
   (1024M > 512M)   └───────────────────┘

2. Validate action limits when the action is executed in the invoker

When the action is executed, the invoker must checks whether the action limit exceeds the system limit and namespace limits.
If the limit of the action to be executed exceeds the limit, an application error with Messages.actionLimitExceeded message is returned and invocation is aborted.

case _: ActionLimitsException =>
  ActivationResponse.applicationError(Messages.actionLimitExceeded)
                                                             ┌───────────────┐
                                                             │               │
                                                             │   Identity    │  UserLimits
                                                             │               │  (maxActionMemory = 512M)
                                                             └───────────────┘
                                                                  ▲
                                                                  │  Validate namespace limit
                                                                  │
  Invoke action     ┌───────────────────┐     Activation     ┌────┴──────────────┐
 (memory = 1024M)   │                   │       Message      │                   │
──────────────────► │                   │ ─────────────────► │                   │
                    │    Controller     │                    │      Invoker      │
◄────────X───────── │                   │ ◄────────X──────── │                   │
   Reject request   │                   │        Reject      │                   │
                    └───────────────────┘      Invocation    └───────────────────┘
                                             (1024M > 512M)

3. Validate action limits when the action is executed in the invoker with the scheduler

The invoker that works with the scheduler should check namespace limits when creating containers and handling activations.

  • When creating a container, if the requested resource of the action exceeds the namespace limit, creation is rejected and the queue is removed.
  • when processing an activation message, if the action exceeds the namespace limit, the activation is rejected.
                                                         ┌───────────────┐
                                                         │               │
                                                         │   Identity    │ UserLimits
                                                         │               │ (maxActionMemory = 512M)
                                                         └───────────────┘
                                                                 ▲
                                        Invoker                  │
                                       ┌─────────────────────────┼─┐
┌─────────────┐   ContainerCreation    │                         │ │
│             │        Message         │  ┌────────────────────┐ │ │
│             │ ───────────────────────┼─►│  ContainerMessage  │ │ │
│             │                        │  │     Consumer       ├─┤ │ Validate namespace limit
│             │ ◄───────────X──────────┼─ └────────────────────┘ │ │
│  Scheduler  │     Reject creating    │                         │ │
│             │        container       │  ┌────────────────────┐ │ │
│             │                        │  │  FunctionPulling   │ │ │
│             │ ◄──────────────────────┼──┤  ContainerProxy    ├─┘ │
│             │      Fetch activation  │  └──────────────┬─────┘   │
└─────────────┘                        │                 │         │
                                       └─────────────────┼─────────┘
                    Kafka                                │
                   ┌───────────────┐                     │
                   ├───────────────┤                     │
                   │ Completed0    │ ◄─────────X─────────┘
                   ├───────────────┤   Activation Response
                   └───────────────┘    (Reject 1024>512M)

Handling invalid namespace limits

Because there is no admin API to handle namespace limits, the CouchDB document may have namespace limit values that exceed the system limits.
But, If there is a namespace limit that exceeds the system limit, the namespace limit is lowered to the system limit.

@upgle upgle changed the title POEM: Providing action limits for each namespace [Proposal] POEM: Providing action limits for each namespace May 16, 2022
Copy link
Member

@style95 style95 left a comment

Choose a reason for hiding this comment

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

Nice!

@upgle upgle added the proposal Denote an issue is a proposal label May 16, 2022
@jiangpengcheng
Copy link
Contributor

I'm still not clear about the differences between system limit and namespace default limit:

  1. when namespace limit and namespace default limit are not set, the system limit is used
  2. when namespace limit is not set, namespace default limit is set, namespace default limit is used
  3. when namespace limit is set, it's used

looks like the namespace default limit is applied to all namespaces which has no namespace limit
and the system limit is also applied to all namespaces which has no namespace limit too if there is no namespace default limit
so why introduce an extra default limit for all namespaces?

@upgle
Copy link
Member Author

upgle commented May 17, 2022

@jiangpengcheng

  • namespace default limit and system limit is configuration for system.
    • So there is never a case where there is no namespace default limit.
  • Values exceeding the system limit cannot be used even by administrators. (It is a kind of safety device.)

  1. when namespace limit and namespace default limit are not set, the system limit is used
    • This is an incorrect assumption. The default limit is always present.
  2. when namespace limit is not set, namespace default limit is set, namespace default limit is used
    • Yes, right
  3. when namespace limit is set, it's used
    • Yes, right

@style95
Copy link
Member

style95 commented May 19, 2022

It seems many pull requests are failing because of the following reason and this PR is also one of them.

> Task :tests:testSwaggerCodegen FAILED
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':swagger-java-client'.
> Could not resolve all artifacts for configuration ':swagger-java-client:classpath'.
   > Could not resolve com.android.tools.build:gradle:2.3.+.
     Required by:
         project :swagger-java-client
      > Failed to list versions for com.android.tools.build:gradle.
         > Unable to load Maven meta-data from https://jcenter.bintray.com/com/android/tools/build/gradle/maven-metadata.xml.
            > Could not HEAD 'https://jcenter.bintray.com/com/android/tools/build/gradle/maven-metadata.xml'.
               > org.apache.http.client.ClientProtocolException (no error message)

Need to see if there is any issue in the dependency resolution.

```

#### Using wskadmin command (tool)
- In general, it is recommended to use a wskadmin rather than modify the DB directly.
Copy link
Contributor

Choose a reason for hiding this comment

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

I personally think it would be nice to have admin routes in the controller to update this data and you give just one namespace that the operators have access to authorization to hit the admin route path. wskadmin isn't really any different from editing the db directly security / authorization wise as it's just a cli tool that makes the db api calls.

That doesn't really preclude this proposal since this is just adding operator limits that can be configured that way, which is already done.

Copy link
Contributor

Choose a reason for hiding this comment

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

Now if it's the owners of an individual namespace that can tune these min / max values, then that's definitely a problem to hand them the keys to wskadmin. I don't think that's what's being proposed here though

Copy link
Member Author

@upgle upgle May 20, 2022

Choose a reason for hiding this comment

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

I referred to the previous implementation for namespace limits, and I agree it is necessary to introduce a namespace with administrator privileges and an administrator API. I think it can be achieved through another proposal.

Copy link
Member

Choose a reason for hiding this comment

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

Starting with wskadmin or modifications to couch is a fair transition. I also see the value of making this part of an OW Admin API. Regardless, I believe the GET /api/v1/namespaces[_/limits] should return not just the namespace name but the limits for that namespace as shown below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Using the wskadmin tool is the same as modifying the db directly, so I will delete the ambiguous phrase.

maxActionLogs | integer (unit: MB) | maximum activation log size for namespace
minActionTimeout | integer (unit: milliseconds) | minimum action time limit for namespace
maxActionTimeout | integer (unit: milliseconds) | maximum action time limit for namespace
minActionConcurrency | integer | minimum action concurrency limit for namespace
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be renamed. This is representing container activation concurrency. If we are ever to add action concurrency like namespace concurrency but more fine grained, this will then be very confusing

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for your comments. I've been thinking a lot too but I can't come up with a good config name.
And a lot of code already calls it the action concurrency limit. I think using a new name can also be more confusing.

"CONFIG_whisk_concurrencyLimit_min": "{{ limit_action_concurrency_min | default() }}"

  • concurrentInvocations: Max allowed concurrent in-flight invocations for a namespace level.
  • minActionConcurrency: Minimum allowed concurrent invocations for an action level.

@codecov-commenter
Copy link

codecov-commenter commented May 21, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.80%. Comparing base (3e3414c) to head (5c2d8b0).
Report is 157 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #5236       +/-   ##
===========================================
+ Coverage   44.53%   74.80%   +30.26%     
===========================================
  Files         238      238               
  Lines       13957    13965        +8     
  Branches      570      582       +12     
===========================================
+ Hits         6216    10446     +4230     
+ Misses       7741     3519     -4222     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@style95
Copy link
Member

style95 commented May 23, 2022

@bdoyle0182 @rabbah
If you have no further comments, let me merge this PR.

proposals/POEM-3-action-limit-for-namespace.md Outdated Show resolved Hide resolved
proposals/POEM-3-action-limit-for-namespace.md Outdated Show resolved Hide resolved
proposals/POEM-3-action-limit-for-namespace.md Outdated Show resolved Hide resolved
```

#### Using wskadmin command (tool)
- In general, it is recommended to use a wskadmin rather than modify the DB directly.
Copy link
Member

Choose a reason for hiding this comment

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

Starting with wskadmin or modifications to couch is a fair transition. I also see the value of making this part of an OW Admin API. Regardless, I believe the GET /api/v1/namespaces[_/limits] should return not just the namespace name but the limits for that namespace as shown below.

proposals/POEM-3-action-limit-for-namespace.md Outdated Show resolved Hide resolved
proposals/POEM-3-action-limit-for-namespace.md Outdated Show resolved Hide resolved
- In general, it is recommended to use a wskadmin rather than modify the DB directly.
- There is plan to provide the feauture to change namespace limits in wskadmin.

### Namespace Limit API
Copy link
Member

Choose a reason for hiding this comment

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

I think you intend to extend the limits document/attachment to include the namespace limits, is that right? I didn't see it called out explicitly.

Copy link
Member Author

Choose a reason for hiding this comment

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

upgle and others added 2 commits May 24, 2022 13:54
@style95
Copy link
Member

style95 commented May 25, 2022

I will merge this as it has been open for a while.
Since this is just a proposal PR, if anyone has any comments, please leave them to the implementation PR.
#5229

@style95 style95 merged commit edc484b into apache:master May 25, 2022
JesseStutler pushed a commit to JesseStutler/openwhisk that referenced this pull request Jul 13, 2022
)

* Add POEM (Providing action limits for each namespace)

* Apply suggestions from code review

Co-authored-by: rodric rabbah <rodric@gmail.com>

* Update POEM-3-action-limit-for-namespace.md

Co-authored-by: rodric rabbah <rodric@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Denote an issue is a proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants