<p>I sent 2000 short-lived jobs to my kube cluster very quickly, and I observed a couple of minutes delay between a job was created and a pod for the job started pending. Does anybody have any clue about what may be the bottleneck?</p>

<p>Could etcd be the bottleneck?</p>

tiancai
<p>From a 10.000 foot view, the process is:</p>

<ul>
<li><p>Every time you schedule a pod/job, it gets added to a queue.</p></li>
<li><p>The scheduler reads that queue and assign the POD to a node.</p></li>
<li><p>When a node receives an assignment of a pod, it handles the creation by calling the runtime and requesting the creation.</p></li>
</ul>

<p>Given the above, the delay might be either:</p>

<ul>
<li>the scheduler waiting for a node to be available(status report) to schedule the pod</li>
<li>the runtime scheduling the pods in the nodes</li>
</ul>

<p>ETCD bottleneck might also be an issue, but is less likely, if was ETCD you probably would notice that while creating the jobs.</p>

<p>Also, worth mentioning that the nodes have a limit on how many pods each node can run at same time time, on <strong><a href="https://kubernetes.io/docs/setup/cluster-large/" rel="nofollow noreferrer">V1.14 <em>no more than 100 pods per node can run at same time</em></strong></a>, no matter how large is the node , in this case, you would need at least 21 nodes to run all at same time, 20 for the requested pods and 1 extra node to account for system pods. If you are running k8s in a cloud provider, the limit might be different for each provider.</p>

<p>Without investigation is hard to say where is the problem.</p>

<p>In summary:</p>

<p>There is a work queue to guarantee the reliability of the cluster (API/scheduler/ETCD) and prevent burst calls to affect the availability of the services, after the pods are scheduled, the node runtime will download the images and make sure it runs the PODs as desired on their own time.</p>

<p>If the issue is the limit of pods running at same time in a node, it is likely slowing down because the scheduler is waiting for a node to finish a pod before running another, adding more nodes will improve de results </p>

<p><a href="https://coreos.com/blog/improving-kubernetes-scheduler-performance.html" rel="nofollow noreferrer">This link</a> details some examples of k8s scheduler performance issues.</p>

<p><a href="https://jvns.ca/blog/2017/07/27/how-does-the-kubernetes-scheduler-work/" rel="nofollow noreferrer">This link</a> describes in a bit of details the entire flow.</p>
