elegant-beach-10818
07/24/2023, 10:17 PM16:07:56. One second later at 16:07:57 the task is marked as finished. Then 4 minutes later at 16:11:59 we get the standard output Task finished with exit code 0.
In flows where the parallelism is limited, this is causing the entire flow to hang until these stuck tasks get cleared out. Attached is the effect on the task graph
Any thoughts on potential causes? This is running on metaflow version 2.9.9ancient-application-36103
07/24/2023, 10:23 PM16:07:57 or 16:11:59 ?elegant-beach-10818
07/24/2023, 10:24 PMancient-application-36103
07/24/2023, 10:27 PMancient-application-36103
07/24/2023, 10:27 PMTask finished with exit code 0. at 16:11:59 was for the same task_id which printed to stdout at 16:07:56 ?ancient-application-36103
07/24/2023, 10:28 PMelegant-beach-10818
07/24/2023, 10:34 PMmammoth-rainbow-82717
07/25/2023, 8:15 AMelegant-beach-10818
07/25/2023, 4:37 PMelegant-beach-10818
07/25/2023, 4:47 PMI heavily instrumented my fork of metaflow and tracked down the cause of the delay. The code is getting stuck inhere: https://github.com/Netflix/metaflow/blob/ec8fd6c4a161b13a0f3765efb1e7fea92cdc2baa/metaflow/plugins/kubernetes/kubernetes.py#L357C9-L357C9tail_logs
Digging deeper, the reason is that(which is callinghas_log_updates) continues to be true after the task has finished.self._job.is_running
Digging deeper, bothandis_donecontinue to be false (once either one is true, the job will finish)_are_pod_containers_done
Digging deeper, the fields checked bynever seem to indicate that the job is done. So the cause is withis_done_are_pod_containers_done
Checking, the cause is that the container status continues to be “running” long after it’s printed the last statement of the function: https://github.com/Netflix/metaflow/blob/ec8fd6c4a161b13a0f3765efb1e7fea92cdc2baa/metaflow/plugins/kubernetes/kubernetes_job.py#L598_are_pod_containers_done
The container status seems to be set outside of metaflow so not sure what can be done to reduce the time from the job completing to when that status gets set to terminated. Usually it gets set within 1-2 seconds, but in my testing I had multiple instances where it took much longerHere's his fork, which is based on the latest release with a few added debugging print statements: https://github.com/chadaeschliman/metaflow/tree/instrument_delays I've also recreated the issue a few minutes ago. For this latest particular job (gist here) the job is reported in the UI as completed at
07-25-2023 16:33:26. In the standard out the "Task finished with exit code 0" printout at 16:39:17. In Kubernetes that same pod says it completed at Finished: Tue, 25 Jul 2023 11:33:28 -0500. For whatever reason there's a ~6 min delay from when the pod is finished in kubernetes and when that task is reported as complete to Metaflow.ancient-application-36103
07/25/2023, 7:00 PMuser
07/25/2023, 9:17 PMjob to be completed. But, it was noticed that in K8s, the job gets marked as completed after the pod is marked completed and pods get marked as completed when the container is marked completed. Therefore, we had made these changes to look at container status instead of job status.
Metaflow relies on K8s to mark the container as completed correctly and swiftly when the process inside the container completes. It's unclear in what cases and why does K8s sometimes take time to mark the container as compeleted.
AFAICT, there are no K8s level config options either to influence this. I believe kubelet polls periodically whether the container it started completed or not. And this polling interval influences when the container is marked completed.
With the changes above, things got better. But there might be something even more optimal. Let me know if there are more ideas/suggestions about what could be done here to make this faster.elegant-beach-10818
07/26/2023, 3:40 PM11:33:28 -0500 but it took 6 minutes for Metaflow to print the final "Task finished with exit code 0" at 16:39:17 and allow other tasks in the flow to run.
I did realize that our job count was around 3300 completed jobs. Based on some research, it seems some clusters can have issues when surpassing 3000 jobs
It's also odd that completed jobs stick around since the codebase sets a TTL hereelegant-beach-10818
07/26/2023, 3:41 PMuser
07/26/2023, 4:23 PMapiserver_request_duration_seconds . With this, it would be possible to check if the problem was on the K8s side or on the client side.elegant-beach-10818
07/26/2023, 4:52 PM• Is it correct that the flow was started locally on a user machine? Or was it run as Argo workflow?Both. We began noticing it with scheduled jobs on argo, and had the same issue when ran from our version of "local" which is a users jupyterhub server
• Can you confirm that there is no time difference between the user machine and k8s nodes?yes, shelling into one of the running containers on k8s and running
date matches up with running date on local
• Also, can you confirm that the user machine from where the flow was started had good connectivity with K8s? We've heard of some cases when VPNs can be a little flaky resulting in increased latencies.I'm confident the connection is good because both the Ec2 (where our jupyterhub runs) and k8s are both within AWS infrastructure.
• Can you check if those job objects are all from within the last 7 days? That's the TTL set in metaflow.They are not. Some of them were over a month old. In k9s when I look at the yaml for a job, it shows
f:ttlSecondsAfterFinished: {}
Do you have some metrics enabled on the K8s api server to see response times?Not currently that's something I can work on adding I'll do some more testing to see if I can recreate the issue with a testing cluster by manually creating tons of jobs and see if that impacts metaflow in the same way. Also I'll investigate why TTL isn't working. It's somewhat odd because others at the company are also using python to deploy jobs and their ttl values are working fine
user
07/26/2023, 4:54 PMelegant-beach-10818
07/26/2023, 4:54 PM