Skip to content

knative svc got stuck when multiple ksvc are generated in parallel and min-scale=0  #8539

Closed

Description

@cdlliuy

In what area(s)?

/area ksvc creation
/area autoscale

What version of Knative?

0.14, 0.15 and even see similar on current master HEAD

Expected Behavior

Expect the ksvc can be created successfully.

Actual Behavior

Failed to create ksvc with revisionmissing

Steps to Reproduce the Problem

Trying to generate 100 ksvc with cmd:

for i in {100..200}; do kn service create sbr-app-$i  --image docker.io/cdlliuy/helloworld --min-scale 0 --no-wait & ;  done

After that, several of ksvc didn't get ready at all.

[root@autoscaler1 logs ]$ kubectl get ksvc | grep -v True
NAME          URL                                                                                                              LATESTCREATED         LATESTREADY           READY     REASON
sbr-app-175   http://sbr-app-175.yingtest.gen2-somaya-cd5bb76c946a0f930dd9607ba0ddd3a1-0001.eu-de.containers.appdomain.cloud   sbr-app-175-swbxr-1                         Unknown   RevisionMissing
sbr-app-179   http://sbr-app-179.yingtest.gen2-somaya-cd5bb76c946a0f930dd9607ba0ddd3a1-0001.eu-de.containers.appdomain.cloud   sbr-app-179-mfnzq-1                         Unknown   RevisionMissing
sbr-app-187   http://sbr-app-187.yingtest.gen2-somaya-cd5bb76c946a0f930dd9607ba0ddd3a1-0001.eu-de.containers.appdomain.cloud   sbr-app-187-pzmqz-1                         Unknown   RevisionMissing
[root@autoscaler1 logs ]$ kubectl get revision | grep -v True
NAME                  CONFIG NAME   K8S SERVICE NAME      GENERATION   READY     REASON
sbr-app-175-swbxr-1   sbr-app-175   sbr-app-175-swbxr-1   1            Unknown   Deploying
sbr-app-179-mfnzq-1   sbr-app-179   sbr-app-179-mfnzq-1   1            Unknown   Deploying
sbr-app-187-pzmqz-1   sbr-app-187   sbr-app-187-pzmqz-1   1            Unknown   Deploying
[root@autoscaler1 logs ]$ kubectl get Configuration | grep -v True
NAME          LATESTCREATED         LATESTREADY           READY     REASON
sbr-app-175   sbr-app-175-swbxr-1                         Unknown
sbr-app-179   sbr-app-179-mfnzq-1                         Unknown
sbr-app-187   sbr-app-187-pzmqz-1                         Unknown
[root@autoscaler1 logs ]$ kubectl get kpa | grep 175
sbr-app-175-swbxr-1   0              0             False   NoTraffic
[root@autoscaler1 logs ]$ kubectl get sks | grep 175
sbr-app-175-swbxr-1   Proxy   2            sbr-app-175-swbxr-1   sbr-app-175-swbxr-1-private   Unknown   NoHealthyBackends
[root@autoscaler1 logs ]$ kubectl get deployment | grep 175
sbr-app-175-swbxr-1-deployment   0/0     0            0           28m
[root@autoscaler1 logs ]$ kubectl get endpoints | grep 175
sbr-app-175-swbxr-1           172.17.33.212:8012   28m
sbr-app-175-swbxr-1-private   <none>               28m
[root@autoscaler1 logs ]$ kubectl get svc | grep 175
sbr-app-175-swbxr-1           ClusterIP      172.21.187.65    <none>                                                 80/TCP                              28m
sbr-app-175-swbxr-1-private   ClusterIP      172.21.29.82     <none>                                                 80/TCP,9090/TCP,9091/TCP,8022/TCP   28m
sbr-app-199-pksjv-1-private   ClusterIP      172.21.216.175   <none>                                                 80/TCP,9090/TCP,9091/TCP,8022/TCP   29m

The revision CR got stuck with :

  conditions:
  - lastTransitionTime: "2020-07-01T03:16:54Z"
    message: The target is not receiving traffic.
    reason: NoTraffic
    severity: Info
    status: "False"
    type: Active
  - lastTransitionTime: "2020-07-01T03:15:10Z"
    reason: Deploying
    status: Unknown
    type: ContainerHealthy
  - lastTransitionTime: "2020-07-01T03:15:10Z"
    reason: Deploying
    status: Unknown
    type: Ready
  - lastTransitionTime: "2020-07-01T03:15:10Z"
    reason: Deploying
    status: Unknown
    type: ResourcesAvailable
  containerStatuses:

Also, although I reproduced this problem with multiple ksvc creation, we observed the similar failure when only creating one single ksvc in our daily continuous test.

It is a race condition issue, but just be easier to be reproduced under load.

Activity

  1. added
    kind/bug
    on Jul 2, 2020
  2. cdlliuy commented on Jul 2, 2020

    @cdlliuy
    Author

    Given there are only 3 of 100 knative service creation failed, I compared the succeed and failed logs file (by downloading controller and autoscaler log, grep + concat + sort by timestamp) below:
    173_succeed.txt
    174-succeed.txt
    175-failed.txt

    I did the following analysis:

    1. kpa status is always changed, from unknown -> active -> inactive
    2. in ideally, once kpa status is changed to active, the revision-controller need to mark revision ready;
      case corev1.ConditionFalse:
      rs.MarkActiveFalse(cond.Reason, cond.Message)
      case corev1.ConditionTrue:
      rs.MarkActiveTrue()
      // Precondition for PA being active is SKS being active and
      // that entices that |service.endpoints| > 0.
      rs.MarkResourcesAvailableTrue()
      rs.MarkContainerHealthyTrue()
      }

    But when the revision-controller didn't have a chance to do reconcile when kpa is active, later on, kpa status will be changed to inactive. As a result, the revision controller won't have any chance to make revision active anymore because of the following code:
    https://github.com/knative/serving/blob/master/pkg/reconciler/revision/reconcile_resources.go#L72-L74

    func (rs *RevisionStatus) IsActivationRequired() bool {
    if c := revCondSet.Manage(rs).GetCondition(RevisionConditionActive); c != nil {
    return c.Status != corev1.ConditionTrue
    }
    return false
    }

    btw: the func name in above is confusing. IsActivationRequired() func returns True when revision.status is NOT true, when only when !IsActivationRequired(), the deployment status is propagated ..

    Then, looking at the logs, when revision reconcile is good, I got:

    {"level":"info","ts":"2020-07-01T03:14:40.466Z","logger":"autoscaler.kpa-class-podautoscaler-controller","caller":"kpa/kpa.go:176","msg":"Observed pod counts=kpa.podCounts{want:1, ready:1, notReady:0, pending:0, terminating:0}
    ==> KPA should be marked active here.
    ","commit":"12fd001","knative.dev/controller":"kpa-class-podautoscaler-controller","knative.dev/traceid":"0794896e-850c-41e1-801e-818d143f327a","knative.dev/key":"yingtest/sbr-app-173-pdxlm-1"}
    .....
    
    {"level":"info","ts":"2020-07-01T03:15:38.182Z","logger":"controller.revision-controller","caller":"revision/reconcile_resources.go:138","msg":"Reconciling PA: sbr-app-173-pdxlm-1","commit":"12fd001","knative.dev/controller":"revision-controller","knative.dev/traceid":"fa84204c-1961-4478-847b-238f76a0effc","knative.dev/key":"yingtest/sbr-app-173-pdxlm-1"}
    

    In above successful log, reconcile controller had the chance to mark active by reconciling PA. but please notice the time difference here ! Almost 1 minute already.

    ================

    In the failure case ..

    {"level":"info","ts":"2020-07-01T03:15:58.011Z","logger":"autoscaler.kpa-class-podautoscaler-controller","caller":"kpa/kpa.go:176","msg":"Observed pod counts=kpa.podCounts{want:1, ready:1, notReady:0, pending:0, terminating:0}
    ","commit":"12fd001","knative.dev/controller":"kpa-class-podautoscaler-controller","knative.dev/traceid":"18c3ebc4-e9c1-46da-a396-380bccef7e23","knative.dev/key":"yingtest/sbr-app-175-swbxr-1"}
    
    ....
    
    {"level":"info","ts":"2020-07-01T03:16:33.224Z","logger":"autoscaler.kpa-class-podautoscaler-controller","caller":"kpa/kpa.go:166","msg":"PA scale got=1, want=0, desiredPods=0 ebc=-100","commit":"12fd001","knative.dev/controller":"kpa-class-podautoscaler-controller","knative.dev/traceid":"f464e951-1716-4984-b8b9-28492e54b3b4","knative.dev/key":"yingtest/sbr-app-175-swbxr-1"}
    {"level":"info","ts":"2020-07-01T03:16:33.224Z","logger":"autoscaler.kpa-class-podautoscaler-controller","caller":"kpa/scaler.go:207","msg":"Can deactivate PA, was active for 1m3.224129443s","commit":"12fd001","knative.dev/controller":"kpa-class-podautoscaler-controller","knative.dev/traceid":"f464e951-1716-4984-b8b9-28492e54b3b4","knative.dev/key":"yingtest/sbr-app-175-swbxr-1"}
    ==> mark PA inactive here
    ....
    
    
    {"level":"info","ts":"2020-07-01T03:16:53.234Z","logger":"controller.revision-controller","caller":"revision/reconcile_resources.go:138","msg":"Reconciling PA: sbr-app-175-swbxr-1","commit":"12fd001","knative.dev/controller":"revision-controller","knative.dev/traceid":"2d2e36a7-7118-4d4a-8eb5-b25c08f2d4e9","knative.dev/key":"yingtest/sbr-app-175-swbxr-1"}
    ....
    

    In this case, PA was changed from active to inactive first before revision controller had a chance to reconsile PA..

    As the result, the revision stayed in deploying state forever ...

    I can't explain why the revision-controller got KPA changes so late, but it did lose the chance to recover from the reconcile latency.

    we may need more observation on the controller cpu /memory during the test..
    Also, I think using a longer stable window for autoscale will be helpful to mitigate the issue.

    Anyway, I also hope a fix to recover these type of failure from source code level .

  3. cdlliuy commented on Jul 2, 2020

    @cdlliuy
    Author
  4. vagababov commented on Jul 2, 2020

    @vagababov
    Contributor

    you actually got pretty good results. 200 simultaneous services is a lot. Our benchmark currently tops at 25.
    /cc @mattmoor

  5. markusthoemmes commented on Jul 2, 2020

    @markusthoemmes
    Contributor

    Great analysis @cdlliuy and I think you're right: Our PA status is dangerously running into races sometimes that causes the creating revision to be stuck forever. I have on my todo list to rework that a bit and I think we can piggyback on the new "HasBeenActive" state to do that. Gonna whip up a PoC.

  6. markusthoemmes commented on Jul 2, 2020

    @markusthoemmes
    Contributor

    /assign

  7. markusthoemmes commented on Jul 2, 2020

    @markusthoemmes
    Contributor

    Actually opted to write up a potential way to go about this first in #8540. I'd love to run this via a few API peeps to make sure we're not butchering things too much.

  8. zhanggbj commented on Jul 2, 2020

    @zhanggbj

    @vagababov @markusthoemmes btw, is the benchmark you mentioned above also available in serving repo or somewhere? I'm thinking we can also leverage it. thanks!

  9. vagababov commented on Jul 3, 2020

    @vagababov
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions